On Fri, Aug 8, 2014 at 9:19 PM, Remko Popma <[email protected]> wrote:
> It would have been nice to have a fully automatic solution, and it's too > bad that the JMX idea doesn't work, but bringing in new dependencies for > this seems a bit overkill to me... > Well, the JMX works to pickup JVM arguments but not main arguments. I do not know if that is useful though. So I won't include it for a first cut. > > I actually think Gary's solution to ask the user to add one line of code > will be hard to beat for simplicity and ease of use. > Yes, simple is nice and it is very little code. Should this go in now for 2.0.2 or wait for 2.1? Gary > It solves Arwen's original problem and is generic enough that many users > can benefit from it. > > Sent from my iPhone > > > On 2014/08/09, at 6:40, Matt Sicker <[email protected]> wrote: > > > > I was thinking it would be easier to create a main() method wrapper or > use > > byte code weaving to automatically wrap it. However, I realized that this > > wouldn't be useful for applications running in server containers like > > Tomcat without modifying that source. > > > > > >> On 8 August 2014 07:56, Remko Popma <[email protected]> wrote: > >> > >> Ouch! > >> > >> > >> On Fri, Aug 8, 2014 at 9:24 PM, Gary Gregory <[email protected]> > >> wrote: > >> > >>> It's worse than that, the JMX look up does not provide access to the > main > >>> args. The other lookup I created and attached to the jira needs to be > >>> initialized by the user. > >>> > >>> Gary > >>> > >>> > >>>> On Fri, Aug 8, 2014 at 7:41 AM, Remko Popma <[email protected]> > >>> wrote: > >>> > >>>> Note that log4j will only invoke this logic if the application has a > >>>> lookup of the form ${main:<argnum>} in its configuration. > >>>> > >>>> In environments without JMX the app may even need to explicitly > >>> initialize > >>>> the main arguments map. > >>>> > >>>> This doesn't happen without being requested by the app, so I don't > >> share > >>>> the concern. > >>>> > >>>> Sent from my iPhone > >>>> > >>>>>> On 2014/08/08, at 16:54, Mikael Ståldal < > >>>>> [email protected]> wrote: > >>>>> > >>>>> To me, it seems conceptually wrong for a library (like Log4j) to read > >>>>> command line arguments behind the scenes without involvement from the > >>>>> application. Command line arguments are for the application to parse. > >>>>> > >>>>> System properties is the proper way to configure a library without > >>>>> involvement from the application > >>>>> > >>>>> > >>>>>> On Thu, Aug 7, 2014 at 7:02 PM, Gary Gregory < > >> [email protected]> > >>>> wrote: > >>>>>> > >>>>>> Please see this experiment: > >>>>>> https://issues.apache.org/jira/browse/LOG4J2-771 > >>>>>> > >>>>>> Gary > >>>>>> > >>>>>> > >>>>>> On Thu, Aug 7, 2014 at 7:57 AM, Gary Gregory < > >> [email protected]> > >>>>>> wrote: > >>>>>> > >>>>>>> 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 < > >> [email protected] > >>>> > >>>>>>> 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 <[email protected]> > >>>> wrote: > >>>>>>>>> > >>>>>>>>> Hey, it's better than having to use sun.util.Reflection! > >>>>>>>>> > >>>>>>>>> > >>>>>>>>>> On 6 August 2014 20:19, Gary Gregory <[email protected]> > >>>> wrote: > >>>>>>>>>> > >>>>>>>>>> And worse: vendor specific! > >>>>>>>>>> > >>>>>>>>>> Gary > >>>>>>>>>> > >>>>>>>>>> > >>>>>>>>>>> On Wed, Aug 6, 2014 at 9:05 PM, Remko Popma < > >>> [email protected] > >>>>> > >>>>>>>>>> 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 <[email protected]> > >>>>>>>>> wrote: > >>>>>>>>>>>> > >>>>>>>>>>>> With some debug API hackery: > >> > http://docs.oracle.com/javase/7/docs/jdk/api/jpda/jdi/com/sun/jdi/StackFrame.html > >>>>>>>>>>>> > >>>>>>>>>>>> Gary > >>>>>>>>>>>> > >>>>>>>>>>>> > >>>>>>>>>>>>> On Wed, Aug 6, 2014 at 8:36 PM, Remko Popma < > >>>>>>>>> [email protected]> > >>>>>>>>>>> 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 < > >> [email protected]> > >>>>>>>>> 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 > >>>>>>>>>>>>>> > >>>>>>>>>>>>>> <div>-------- Original message --------</div><div>From: > >> Ralph > >>>>>>>>> Goers < > >>>>>>>>>>>>> [email protected]> </div><div>Date:08/06/2014 > >> 19:18 > >>>>>>>>>>>>> (GMT-05:00) </div><div>To: Log4J Users List < > >>>>>>>>>>>>> [email protected]> </div><div>Subject: Re: Set > >> the > >>>>>>>>> file > >>>>>>>>>>> name > >>>>>>>>>>>>> based on command line args </div><div> > >>>>>>>>>>>>>> </div>Wouldn’t it be easier to have a Lookup that your main > >>>>>>>>> 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 < > >>>>>>>>> [email protected]> > >>>>>>>>>>>>> wrote: > >>>>>>>>>>>>>>> > >>>>>>>>>>>>>>> I wonder if we could write a "MainArgumentsLookup" that > >> finds > >>>>>>>>> the > >>>>>>>>>> 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 < > >>>>>>>>>>> [email protected] > >>>>>>>>>>>>>> > >>>>>>>>>>>>>>> wrote: > >>>>>>>>>>>>>>> > >>>>>>>>>>>>>>>> Well…. > >>>>>>>>>>>>>>>> > >>>>>>>>>>>>>>>> You would really be passing the name of the file to the > >>>>>>>>> Appender, > >>>>>>>>>>> not a > >>>>>>>>>>>>>>>> Logger. Loggers only reference Appenders so you can’t > >>> 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 > >>>>>>>>> name > >>>>>>>>>> with > >>>>>>>>>>>>> the > >>>>>>>>>>>>>>>> Lookup. Then reference it from the configuration as > >>>>>>>>> ${myLookup: > >>>>>>>>>>> key} > >>>>>>>>>>>>>>>> where myLookup is the name of your custom Lookup and key > >> is > >>>>>> the > >>>>>>>>>> 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 > >>>>>>>>> it 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 <[email protected]> > >>>>>>>>> wrote: > >>>>>>>>>>>>>>>>> > >>>>>>>>>>>>>>>>> My application takes a parameter where the user can > >> specify > >>>>>>>>> the > >>>>>>>>>> log > >>>>>>>>>>>>>>>> file. I'd like to pass this parameter to the Logger which > >>>>>>>>> uses 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 > >>>>>>>>> the > >>>>>>>>>>>>>>>>> Uniform Electronic Transaction Act or any other law of > >>>>>> similar > >>>>>>>>>>>>>>>>> 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: > >>>>>>>>> [email protected] > >>>>>>>>>>>>>>>> For additional commands, e-mail: > >>>>>>>>>> [email protected] > >>>>>>>>>>>>>>> > >>>>>>>>>>>>>>> > >>>>>>>>>>>>>>> -- > >>>>>>>>>>>>>>> E-Mail: [email protected] | [email protected] > >>>>>>>>>>>>>>> Java Persistence with Hibernate, Second Edition > >>>>>>>>>>>>>>> <http://www.manning.com/bauer3/> > >>>>>>>>>>>>>>> JUnit in Action, Second Edition < > >>>>>>>>> http://www.manning.com/tahchiev/> > >>>>>>>>>>>>>>> Spring Batch in Action <http://www.manning.com/templier/> > >>>>>>>>>>>>>>> Blog: http://garygregory.wordpress.com > >>>>>>>>>>>>>>> Home: http://garygregory.com/ > >>>>>>>>>>>>>>> Tweet! http://twitter.com/GaryGregory > >>> --------------------------------------------------------------------- > >>>>>>>>>>>>>> To unsubscribe, e-mail: > >>>>>>>>> [email protected] > >>>>>>>>>>>>>> For additional commands, e-mail: > >>>>>>>>> [email protected] > >>> --------------------------------------------------------------------- > >>>>>>>>>>>>> To unsubscribe, e-mail: > >>>>>> [email protected] > >>>>>>>>>>>>> For additional commands, e-mail: > >>>>>>>>> [email protected] > >>>>>>>>>>>> > >>>>>>>>>>>> > >>>>>>>>>>>> -- > >>>>>>>>>>>> E-Mail: [email protected] | [email protected] > >>>>>>>>>>>> Java Persistence with Hibernate, Second Edition > >>>>>>>>>>>> <http://www.manning.com/bauer3/> > >>>>>>>>>>>> JUnit in Action, Second Edition < > >>>>>> http://www.manning.com/tahchiev/> > >>>>>>>>>>>> Spring Batch in Action <http://www.manning.com/templier/> > >>>>>>>>>>>> Blog: http://garygregory.wordpress.com > >>>>>>>>>>>> Home: http://garygregory.com/ > >>>>>>>>>>>> Tweet! http://twitter.com/GaryGregory > >> --------------------------------------------------------------------- > >>>>>>>>>>> To unsubscribe, e-mail: > >>> [email protected] > >>>>>>>>>>> For additional commands, e-mail: > >>>>>> [email protected] > >>>>>>>>>> > >>>>>>>>>> > >>>>>>>>>> -- > >>>>>>>>>> E-Mail: [email protected] | [email protected] > >>>>>>>>>> Java Persistence with Hibernate, Second Edition > >>>>>>>>>> <http://www.manning.com/bauer3/> > >>>>>>>>>> JUnit in Action, Second Edition < > >> http://www.manning.com/tahchiev/ > >>>> > >>>>>>>>>> Spring Batch in Action <http://www.manning.com/templier/> > >>>>>>>>>> Blog: http://garygregory.wordpress.com > >>>>>>>>>> Home: http://garygregory.com/ > >>>>>>>>>> Tweet! http://twitter.com/GaryGregory > >>>>>>>>> > >>>>>>>>> > >>>>>>>>> > >>>>>>>>> -- > >>>>>>>>> Matt Sicker <[email protected]> > >>>>>>>> > >>>>>>>> > >>>>>>>> > >>>>>>>> -- > >>>>>>>> E-Mail: [email protected] | [email protected] > >>>>>>>> Java Persistence with Hibernate, Second Edition > >>>>>>>> <http://www.manning.com/bauer3/> > >>>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/ > >>> > >>>>>>>> Spring Batch in Action <http://www.manning.com/templier/> > >>>>>>>> > >>>>>>>> Blog: http://garygregory.wordpress.com > >>>>>>>> Home: http://garygregory.com/ > >>>>>>>> Tweet! http://twitter.com/GaryGregory > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> -- > >>>>>>> E-Mail: [email protected] | [email protected] > >>>>>>> Java Persistence with Hibernate, Second Edition > >>>>>>> <http://www.manning.com/bauer3/> > >>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/> > >>>>>>> Spring Batch in Action <http://www.manning.com/templier/> > >>>>>>> Blog: http://garygregory.wordpress.com > >>>>>>> Home: http://garygregory.com/ > >>>>>>> Tweet! http://twitter.com/GaryGregory > >>>>>> > >>>>>> > >>>>>> > >>>>>> -- > >>>>>> E-Mail: [email protected] | [email protected] > >>>>>> Java Persistence with Hibernate, Second Edition > >>>>>> <http://www.manning.com/bauer3/> > >>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/> > >>>>>> Spring Batch in Action <http://www.manning.com/templier/> > >>>>>> Blog: http://garygregory.wordpress.com > >>>>>> Home: http://garygregory.com/ > >>>>>> Tweet! http://twitter.com/GaryGregory > >>>>> > >>>>> > >>>>> > >>>>> -- > >>>>> Mikael Ståldal > >>>>> Chief Software Architect > >>>>> *Appear* > >>>>> Phone: +46 8 545 91 572 > >>>>> Email: [email protected] > >>>> > >>>> --------------------------------------------------------------------- > >>>> To unsubscribe, e-mail: [email protected] > >>>> For additional commands, e-mail: [email protected] > >>> > >>> > >>> -- > >>> E-Mail: [email protected] | [email protected] > >>> Java Persistence with Hibernate, Second Edition > >>> <http://www.manning.com/bauer3/> > >>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/> > >>> Spring Batch in Action <http://www.manning.com/templier/> > >>> Blog: http://garygregory.wordpress.com > >>> Home: http://garygregory.com/ > >>> Tweet! http://twitter.com/GaryGregory > > > > > > > > -- > > Matt Sicker <[email protected]> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > -- E-Mail: [email protected] | [email protected] Java Persistence with Hibernate, Second Edition <http://www.manning.com/bauer3/> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/> Spring Batch in Action <http://www.manning.com/templier/> Blog: http://garygregory.wordpress.com Home: http://garygregory.com/ Tweet! http://twitter.com/GaryGregory
