Return-Path: X-Original-To: apmail-logging-log4j-user-archive@www.apache.org Delivered-To: apmail-logging-log4j-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4DAAD11E35 for ; Thu, 7 Aug 2014 11:57:34 +0000 (UTC) Received: (qmail 16838 invoked by uid 500); 7 Aug 2014 11:57:33 -0000 Delivered-To: apmail-logging-log4j-user-archive@logging.apache.org Received: (qmail 16796 invoked by uid 500); 7 Aug 2014 11:57:33 -0000 Mailing-List: contact log4j-user-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Users List" Reply-To: "Log4J Users List" Delivered-To: mailing list log4j-user@logging.apache.org Received: (qmail 16785 invoked by uid 99); 7 Aug 2014 11:57:33 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Aug 2014 11:57:33 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of garydgregory@gmail.com designates 209.85.192.176 as permitted sender) Received: from [209.85.192.176] (HELO mail-pd0-f176.google.com) (209.85.192.176) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Aug 2014 11:57:29 +0000 Received: by mail-pd0-f176.google.com with SMTP id y10so5073326pdj.7 for ; Thu, 07 Aug 2014 04:57:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=0f+S5MOPh8GfNLE9X9q+IUkD7WZdRlzyzKsw9LxZ2gI=; b=fpRARdAaVgBUaS4F38mMGnWkkBU88wPrIYMbqU3eo0P3K5LhNamnV5ccIS16rgPIRA gRCr23ZQuiNImNhD6TDYS5tHxP6PAs60K7+66yF0zU0sry0yI0oF/UNvVdY3vPdaW1dh U1zxboJOLpsGQ8h2Nugrltee94EqPA4z6P2FOBXXfyuuLpRKIVXEIAa7QWNm3p0FrGw+ ENHDa3mPr+GaKybZUyXWUgOIoLAEYrfI8NOgoA1He6N3eJ+l7A2r3D39KE4p91Yyhitg k9uYEvaMDyqWP0X4VhWd8s2cIlQ1b6MXaW2u6zUEEP9C8LXZH5zw4K8A6gida7T16NkB PtGg== MIME-Version: 1.0 X-Received: by 10.68.252.229 with SMTP id zv5mr17569814pbc.16.1407412628324; Thu, 07 Aug 2014 04:57:08 -0700 (PDT) Received: by 10.70.32.1 with HTTP; Thu, 7 Aug 2014 04:57:08 -0700 (PDT) In-Reply-To: References: <346nvxplw657fgx6ijovdq75.1407371214378@email.android.com> <022E2C67-D066-4190-978D-E291548D8F12@gmail.com> Date: Thu, 7 Aug 2014 07:57:08 -0400 Message-ID: Subject: Re: Set the file name based on command line args From: Gary Gregory To: Log4J Users List Content-Type: multipart/alternative; boundary=047d7b16059fc386d3050008c9d4 X-Virus-Checked: Checked by ClamAV on apache.org --047d7b16059fc386d3050008c9d4 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On an Oracle JVM, you use a system property lookup to get the "sun.java.command" system property which gives you the whole command line but we do not have a syntax to parse it... Gary On Thu, Aug 7, 2014 at 2:27 AM, Gary Gregory wrote= : > It'll be more complicated than just grabbing the main args of course. > > If I say something like ${main:0} that seems easy to deal with, but when = I > say ${main:--file} or ${main:-f} or ${main:-file}, that should pickup the > _next_ arg in the array. What if it is missing or the next arg is another > dash option? Too bad I guess. What are the rules? > > I could see two lookup classes: > - One is a named Map Lookup built from a String[], which would be a > singleton called by the main method: > MainArgumentsLookup.SINGELTON.set(args); Is the args array a reference or= a > deep copy? > - Another is the more complex and vendor dependent (and unproven) stack > walker. > > Gary > > > On Wed, Aug 6, 2014 at 11:45 PM, Matt Sicker wrote: > >> Hey, it's better than having to use sun.util.Reflection! >> >> >> On 6 August 2014 20:19, Gary Gregory wrote: >> >> > And worse: vendor specific! >> > >> > Gary >> > >> > >> > On Wed, Aug 6, 2014 at 9:05 PM, Remko Popma >> wrote: >> > >> > > Oooh... A little naughty, but a lot of fun! :-) >> > > Thanks for the pointer! >> > > >> > > Sent from my iPhone >> > > >> > > > On 2014/08/07, at 9:44, Gary Gregory >> wrote: >> > > > >> > > > With some debug API hackery: >> > > > >> > > >> > >> http://docs.oracle.com/javase/7/docs/jdk/api/jpda/jdi/com/sun/jdi/StackF= rame.html >> > > > >> > > > Gary >> > > > >> > > > >> > > >> On Wed, Aug 6, 2014 at 8:36 PM, Remko Popma > > >> > > wrote: >> > > >> >> > > >> I don't follow... If you walk the stack trace you can find the >> name of >> > > the >> > > >> original class whose main() method was called, but how would that >> give >> > > you >> > > >> access to the main method's parameter values? >> > > >> >> > > >> Sent from my iPhone >> > > >> >> > > >>> On 2014/08/07, at 9:26, Gary Gregory >> wrote: >> > > >>> >> > > >>> Yes you are right but the stack walker could be used even if you >> do >> > not >> > > >> control to source for main. Maybe a script calls a main and then = my >> > app >> > > >> plugin gets called and I want to also follow the verbose command >> line >> > > >> setting. >> > > >>> >> > > >>> >> > > >>> Gary >> > > >>> >> > > >>>
-------- Original message --------
From: Ralph >> Goers < >> > > >> ralph.goers@dslextreme.com>
Date:08/06/2014 19:18 >> > > >> (GMT-05:00)
To: Log4J Users List < >> > > >> log4j-user@logging.apache.org>
Subject: Re: Set the >> file >> > > name >> > > >> based on command line args
>> > > >>>
Wouldn=E2=80=99t it be easier to have a Lookup that your m= ain called >> > and >> > > >> just passed the arguments? But yeah, it should be possible to do >> what >> > > you >> > > >> are suggesting. >> > > >>> >> > > >>> Ralph >> > > >>> >> > > >>>> On Aug 6, 2014, at 4:09 PM, Gary Gregory > > >> > > >> wrote: >> > > >>>> >> > > >>>> I wonder if we could write a "MainArgumentsLookup" that finds t= he >> > main >> > > >>>> thread and walks up the stack to the public static main(String[= ]) >> > main >> > > >>>> methods and gets the arguments from the stack... >> > > >>>> >> > > >>>> Gary >> > > >>>> >> > > >>>> >> > > >>>> On Wed, Aug 6, 2014 at 6:54 PM, Ralph Goers < >> > > ralph.goers@dslextreme.com >> > > >>> >> > > >>>> wrote: >> > > >>>> >> > > >>>>> Well=E2=80=A6. >> > > >>>>> >> > > >>>>> You would really be passing the name of the file to the >> Appender, >> > > not a >> > > >>>>> Logger. Loggers only reference Appenders so you can=E2=80=99t= really >> > > configure >> > > >>>>> them with Appender configuration data. That said, Log4j 2 >> provides >> > a >> > > >> few >> > > >>>>> ways you could do this: >> > > >>>>> 1. Set a system property and reference it via >> ${sys:propertyName} >> > in >> > > >> the >> > > >>>>> configuration. The manual has examples of this. >> > > >>>>> 2. Create a custom Lookup Plugin and then register the file na= me >> > with >> > > >> the >> > > >>>>> Lookup. Then reference it from the configuration as >> ${myLookup: >> > > key} >> > > >>>>> where myLookup is the name of your custom Lookup and key is th= e >> > name >> > > >> that >> > > >>>>> represents the file name value. >> > > >>>>> 3. Create a custom Configuration the extends XMLConfiguration = or >> > > >>>>> JSONConfiguration. Pass the file name to that class and have i= t >> add >> > > >> that as >> > > >>>>> a property to the properties Map in the configuration. The XML >> > could >> > > >> then >> > > >>>>> just reference it as ${propertyName}. >> > > >>>>> >> > > >>>>> Ralph >> > > >>>>> >> > > >>>>>> On Aug 6, 2014, at 2:03 PM, Arwen Pond wrote= : >> > > >>>>>> >> > > >>>>>> My application takes a parameter where the user can specify t= he >> > log >> > > >>>>> file. I'd like to pass this parameter to the Logger which use= s >> a >> > > >>>>> FileAppender. I am not sure how to do this in log4j 2. >> > > >>>>>> >> > > >>>>>> Thanks, >> > > >>>>>> Arwen >> > > >>>>>> >> > > >>>>>> >> > > >>>>>> This electronic mail message contains information that (a) is >> or >> > > >>>>>> may be CONFIDENTIAL, PROPRIETARY IN NATURE, OR OTHERWISE >> > > >>>>>> PROTECTED >> > > >>>>>> BY LAW FROM DISCLOSURE, and (b) is intended only for the use = of >> > > >>>>>> the addressee(s) named herein. If you are not an intended >> > > >>>>>> recipient, please contact the sender immediately and take the >> > > >>>>>> steps necessary to delete the message completely from your >> > > >>>>>> computer system. >> > > >>>>>> >> > > >>>>>> Not Intended as a Substitute for a Writing: Notwithstanding t= he >> > > >>>>>> Uniform Electronic Transaction Act or any other law of simila= r >> > > >>>>>> effect, absent an express statement to the contrary, this >> e-mail >> > > >>>>>> message, its contents, and any attachments hereto are not >> > > >>>>>> intended >> > > >>>>>> to represent an offer or acceptance to enter into a contract >> and >> > > >>>>>> are not otherwise intended to bind this sender, >> > > >>>>>> barnesandnoble.com >> > > >>>>>> llc, barnesandnoble.com inc. or any other person or entity. >> > > >>>>> >> > > >>>>> >> > > >>>>> >> > --------------------------------------------------------------------- >> > > >>>>> To unsubscribe, e-mail: >> log4j-user-unsubscribe@logging.apache.org >> > > >>>>> For additional commands, e-mail: >> > log4j-user-help@logging.apache.org >> > > >>>> >> > > >>>> >> > > >>>> -- >> > > >>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org >> > > >>>> Java Persistence with Hibernate, Second Edition >> > > >>>> >> > > >>>> JUnit in Action, Second Edition < >> http://www.manning.com/tahchiev/> >> > > >>>> Spring Batch in Action >> > > >>>> Blog: http://garygregory.wordpress.com >> > > >>>> Home: http://garygregory.com/ >> > > >>>> Tweet! http://twitter.com/GaryGregory >> > > >>> >> > > >>> >> > > >>> >> --------------------------------------------------------------------- >> > > >>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.or= g >> > > >>> For additional commands, e-mail: >> log4j-user-help@logging.apache.org >> > > >> >> > > >> >> --------------------------------------------------------------------- >> > > >> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org >> > > >> For additional commands, e-mail: >> log4j-user-help@logging.apache.org >> > > > >> > > > >> > > > -- >> > > > E-Mail: garydgregory@gmail.com | ggregory@apache.org >> > > > Java Persistence with Hibernate, Second Edition >> > > > >> > > > JUnit in Action, Second Edition >> > > > Spring Batch in Action >> > > > Blog: http://garygregory.wordpress.com >> > > > Home: http://garygregory.com/ >> > > > Tweet! http://twitter.com/GaryGregory >> > > >> > > --------------------------------------------------------------------= - >> > > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org >> > > For additional commands, e-mail: log4j-user-help@logging.apache.org >> > > >> > > >> > >> > >> > -- >> > E-Mail: garydgregory@gmail.com | ggregory@apache.org >> > Java Persistence with Hibernate, Second Edition >> > >> > JUnit in Action, Second Edition >> > Spring Batch in Action >> > Blog: http://garygregory.wordpress.com >> > Home: http://garygregory.com/ >> > Tweet! http://twitter.com/GaryGregory >> > >> >> >> >> -- >> Matt Sicker >> > > > > -- > E-Mail: garydgregory@gmail.com | ggregory@apache.org > Java Persistence with Hibernate, Second Edition > > JUnit in Action, Second Edition > Spring Batch in Action > > Blog: http://garygregory.wordpress.com > Home: http://garygregory.com/ > Tweet! http://twitter.com/GaryGregory > --=20 E-Mail: garydgregory@gmail.com | ggregory@apache.org Java Persistence with Hibernate, Second Edition JUnit in Action, Second Edition Spring Batch in Action Blog: http://garygregory.wordpress.com Home: http://garygregory.com/ Tweet! http://twitter.com/GaryGregory --047d7b16059fc386d3050008c9d4--