Re: problems with web app and JndiContextSelector

2014-08-06 Thread Mike Calmus
After extensive trial and error I think I have things boiled down. In my
list "works" means that I see logging. For some there may be caveats.

All tests were run using Weblogic 10.3.6 (a Servlet 2.5 container) running
on Java 7. There were no difference when using Log4j 2.0 versus 2.0.1.

When I load the log4j libraries as a part of the server's startup classes
(out current preferred configuration with Log4j 1.2.x):

1) Standard web-app configuration with configuration file specified in
web.xml does not work
2) Configured with JndiContextSelector as the Log4jContextSelector system
property it doesn't work when I have things configured correctly. If I
exclude the JNDI lookup environment properties I get an error in the System
log, but logging works.

Removing the Log4j libraries from System startup and instead bundle them
with the application (no other changes)
Scenario 1 above now works.
The JNDI configuration does not work.




On Fri, Aug 1, 2014 at 3:16 PM, Mike Calmus  wrote:

> We're using a Servlet 2.5 container and configuration. I added the
> Log4jContextSelector environment variable to the container startup as well
> as loading all the Log4j 2.0 jars with the container. I added the following
> items to my web.xml:
>
>   
> isLog4jContextSelectorNamed
> true
>   
>   
> log4jContextName
> myapp
>   
>   
> log4jConfiguration
>
> file:///${sys:projectprops}/myapp/default/log4j2.xml
>   
>   
>
> org.apache.logging.log4j.web.Log4jServletContextListener
>   
>   
> log4jServletFilter
>
> org.apache.logging.log4j.web.Log4jServletFilter
>   
>   
> log4jServletFilter
> /*
> REQUEST
> FORWARD
> INCLUDE
> ERROR
>   
> With just this, logging works fine, but I get an error when the JNDI
> lookup fails.
>
>   
> Sets the logging context for the web-app
> log4j/context-name
> java.lang.String
> myapp
>   
> The JNDI lookup error goes away but logging stops working.
>
> I also tried adding the following with no change in results.
>
>   
> URL for configuring log4j context
> log4j/configuration-resource
> java.lang.String
>
> file:///${sys:projectprops}/myapp/default/log4j2.xml
>   
>
>
> On Tue, Jul 29, 2014 at 11:37 AM, Ralph Goers 
> wrote:
>
>> The best would be a sample project that demonstrates the problem. At a
>> minimum I would think the web.xml and log4j 2 configuration.
>>
>> Ralph
>>
>> On Jul 29, 2014, at 5:47 AM, Mike Calmus  wrote:
>>
>> > I am having problems moving our web app over to Log4j 2.0 using JNDI
>> > lookups. I followed the configuration documentation and am not getting
>> any
>> > errors, but nothing is being logged to my configured appenders.
>> Weirdly, if
>> > I remove the JNDI env-entry configuration from web.xml logging seems to
>> > work, albeit with the expected NameNotFoundException in the server
>> output.
>> >
>> > One possibly relevant configuration difference is that we load the log4j
>> > jar files as part of server startup so each app doesn't have to load
>> them.
>> >
>> > Any ideas? What configuration can I provide to help troubleshoot?
>> >
>> > Thanks.
>>
>>
>> -
>> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
>> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>>
>>
>


Re: problems with web app and JndiContextSelector

2014-08-06 Thread Matt Sicker
Are system libraries in Weblogic loaded as OSGi bundles?


On 6 August 2014 11:39, Mike Calmus  wrote:

> After extensive trial and error I think I have things boiled down. In my
> list "works" means that I see logging. For some there may be caveats.
>
> All tests were run using Weblogic 10.3.6 (a Servlet 2.5 container) running
> on Java 7. There were no difference when using Log4j 2.0 versus 2.0.1.
>
> When I load the log4j libraries as a part of the server's startup classes
> (out current preferred configuration with Log4j 1.2.x):
>
> 1) Standard web-app configuration with configuration file specified in
> web.xml does not work
> 2) Configured with JndiContextSelector as the Log4jContextSelector system
> property it doesn't work when I have things configured correctly. If I
> exclude the JNDI lookup environment properties I get an error in the System
> log, but logging works.
>
> Removing the Log4j libraries from System startup and instead bundle them
> with the application (no other changes)
> Scenario 1 above now works.
> The JNDI configuration does not work.
>
>
>
>
> On Fri, Aug 1, 2014 at 3:16 PM, Mike Calmus  wrote:
>
> > We're using a Servlet 2.5 container and configuration. I added the
> > Log4jContextSelector environment variable to the container startup as
> well
> > as loading all the Log4j 2.0 jars with the container. I added the
> following
> > items to my web.xml:
> >
> >   
> > isLog4jContextSelectorNamed
> > true
> >   
> >   
> > log4jContextName
> > myapp
> >   
> >   
> > log4jConfiguration
> >
> >
> file:///${sys:projectprops}/myapp/default/log4j2.xml
> >   
> >   
> >
> >
> org.apache.logging.log4j.web.Log4jServletContextListener
> >   
> >   
> > log4jServletFilter
> >
> >
> org.apache.logging.log4j.web.Log4jServletFilter
> >   
> >   
> > log4jServletFilter
> > /*
> > REQUEST
> > FORWARD
> > INCLUDE
> > ERROR
> >   
> > With just this, logging works fine, but I get an error when the JNDI
> > lookup fails.
> >
> >   
> > Sets the logging context for the web-app
> > log4j/context-name
> > java.lang.String
> > myapp
> >   
> > The JNDI lookup error goes away but logging stops working.
> >
> > I also tried adding the following with no change in results.
> >
> >   
> > URL for configuring log4j context
> > log4j/configuration-resource
> > java.lang.String
> >
> >
> file:///${sys:projectprops}/myapp/default/log4j2.xml
> >   
> >
> >
> > On Tue, Jul 29, 2014 at 11:37 AM, Ralph Goers <
> ralph.go...@dslextreme.com>
> > wrote:
> >
> >> The best would be a sample project that demonstrates the problem. At a
> >> minimum I would think the web.xml and log4j 2 configuration.
> >>
> >> Ralph
> >>
> >> On Jul 29, 2014, at 5:47 AM, Mike Calmus  wrote:
> >>
> >> > I am having problems moving our web app over to Log4j 2.0 using JNDI
> >> > lookups. I followed the configuration documentation and am not getting
> >> any
> >> > errors, but nothing is being logged to my configured appenders.
> >> Weirdly, if
> >> > I remove the JNDI env-entry configuration from web.xml logging seems
> to
> >> > work, albeit with the expected NameNotFoundException in the server
> >> output.
> >> >
> >> > One possibly relevant configuration difference is that we load the
> log4j
> >> > jar files as part of server startup so each app doesn't have to load
> >> them.
> >> >
> >> > Any ideas? What configuration can I provide to help troubleshoot?
> >> >
> >> > Thanks.
> >>
> >>
> >> -
> >> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> >> For additional commands, e-mail: log4j-user-h...@logging.apache.org
> >>
> >>
> >
>



-- 
Matt Sicker 


Set the log level based on command line args

2014-08-06 Thread Arwen Pond
I am investigating migrating from log4j 1 to log4j 2.  A pattern that I have in 
many of my applications is setting the log level based on command line 
arguments.  So if the -v (verbose) option is passed I set the log level to 
Info.  The default is set to warn.
if (line.hasOption("v"))
{
  logger.setLevel(Level.INFO);
}

if (line.hasOption("d"))
{
  logger.setLevel(Level.DEBUG);
}

In the world of log4j 2, what is the recommended way to accomplish this?

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.

RE: Set the log level based on command line args

2014-08-06 Thread Arwen Pond
This is what I have tried:






















Then I call this:
Logger logger = LogManager.getLogger("verbose");
logger.info("Hello World");

But I see duplicated lines in the output.
INFO  [main]: Hello World
11:36:18.191 [main] INFO  verbose - Hello World

What am I doing wrong?

Thanks,
Arwen

-Original Message-
From: Arwen Pond 
Sent: Wednesday, August 06, 2014 10:42 AM
To: log4j-user@logging.apache.org
Subject: Set the log level based on command line args

I am investigating migrating from log4j 1 to log4j 2.  A pattern that I have in 
many of my applications is setting the log level based on command line 
arguments.  So if the -v (verbose) option is passed I set the log level to 
Info.  The default is set to warn.
if (line.hasOption("v"))
{
  logger.setLevel(Level.INFO);
}

if (line.hasOption("d"))
{
  logger.setLevel(Level.DEBUG);
}

In the world of log4j 2, what is the recommended way to accomplish this?

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.

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: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org



Re: Set the log level based on command line args

2014-08-06 Thread Ralph Goers
Please see 
http://logging.apache.org/log4j/2.x/manual/configuration.html#Additivity

Ralph

On Aug 6, 2014, at 10:42 AM, Arwen Pond  wrote:

> I am investigating migrating from log4j 1 to log4j 2.  A pattern that I have 
> in many of my applications is setting the log level based on command line 
> arguments.  So if the -v (verbose) option is passed I set the log level to 
> Info.  The default is set to warn.
>if (line.hasOption("v"))
>{
>  logger.setLevel(Level.INFO);
>}
> 
>if (line.hasOption("d"))
>{
>  logger.setLevel(Level.DEBUG);
>}
> 
> In the world of log4j 2, what is the recommended way to accomplish this?
> 
> 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.



Re: Set the log level based on command line args

2014-08-06 Thread Ralph Goers
I should also add that your configuration didn’t show a root logger.  There is 
always a root logger so I suspect you are also logging to it.  If you make all 
your loggers be configured with additivity=“false” that should stop happening.

Ralph

On Aug 6, 2014, at 1:13 PM, Ralph Goers  wrote:

> Please see 
> http://logging.apache.org/log4j/2.x/manual/configuration.html#Additivity
> 
> Ralph
> 



Re: how to change logging level for a class at runtime [I]

2014-08-06 Thread Ang Xu
Hi,

Is there any plan to merge this patch to the main branch? This
functionality seems extremely useful when modifying config file is not an
option.

Thanks,
Ang

On 6/25/14, 12:19 AM, "Phil Wray"  wrote:

>Classification: For internal use only
>
>Hey Ralph.
>Sure - have created:
>LOG4J2-681 Add ability to change log level for any class/package
>dynamically via jmx
>
>cheers,
>Phil
>
>
>
>
>
>From:
>Ralph Goers 
>To:
>Log4J Users List ,
>Date:
>24/06/2014 15:34
>Subject:
>Re: how to change logging level for a class at runtime
>
>
>
>Phil,
>
>That looks pretty good.  It would be great if you could create a Jira
>issue and add that as a patch
>
>Sent from my iPad
>
>> On Jun 24, 2014, at 7:01 AM, Phil Wray  wrote:
>> 
>> Classification: Public
>> 
>> Hi Ralph,
>> Just to confirm running latest trunk version its possible to change
>levels 
>> at runtime using code as per your docs.
>> Thanks for the help.
>> I see a tag for 2.0-rc2 was taken a couple of days ago - I'm guessing
>this 
>> is being released imminently?
>> 
>> In case it helps others I ended up with the following util to let us
>> change levels via jmx, just using whatever existing appender the logger
>> would have had.
>> 
>>@ManagedOperation
>>public String changeLogLevel(String loggerName, String level){
>>Level newLevel = Level.toLevel(level);
>>LoggerContext ctx = (LoggerContext)
>LogManager.getContext(
>> false);
>>Configuration config = ctx.getConfiguration();
>>LoggerConfig loggerConfig =
>> config.getLoggerConfig(loggerName);
>>String msg;
>> 
>>if (loggerName.equals(loggerConfig.getName())){
>>Level oldLevel = loggerConfig.getLevel();
>>loggerConfig.setLevel(newLevel);
>>msg = String.format("Modified existing logger %s
>> level from %s to %s", loggerName, oldLevel, newLevel);
>>} else {
>>createCopyFrom(loggerConfig, loggerName,
>newLevel, 
>> config);
>>msg = String.format("Added new logger %s with
>> level %s previously used logger %s with level %s", loggerName,
>>newLevel, 
>
>> loggerConfig.getName(), loggerConfig.getLevel());
>>}
>>ctx.updateLoggers();
>>LOG.info(msg);
>>return msg;
>>}
>> 
>>private void createCopyFrom(LoggerConfig original, String name,
>> Level level, Configuration config){
>>AppenderRef[] refs = original.getAppenderRefs().toArray(
>> new AppenderRef[]{});
>>Filter filter = original.getFilter();
>>LoggerConfig copy = LoggerConfig.createLogger(
>>"false",
>>level,
>>name,
>>Boolean.toString
>> (original.isIncludeLocation()),
>>refs, null, config, filter);
>> 
>>for (Appender appender :
>> original.getAppenders().values()){
>>copy.addAppender(appender, null, null);
>>}
>>config.addLogger(name, copy);
>>}
>> 
>> cheers,
>> Phil
>> 
>> 
>> 
>> 
>> From:
>> Phil Wray/ext/dbcom
>> To:
>> "Log4J Users List" ,
>> Date:
>> 24/06/2014 11:16
>> Subject:
>> Re: how to change logging level for a class at runtime
>> 
>> 
>> Classification: Public
>> 
>> Hi Ralph,
>> Sorry hadn't looked at the latest source  - see you've made changes to
>> Configuration to allow adding of LoggerConfig via the interface that
>>are 
>
>> not yet in the release candidate jar.
>> I'll take the latest source and build from that.
>> 
>> 
>> thanks,
>> Phil
>> 
>> 
>> 
>> 
>> 
>> 
>> From:
>> Phil Wray/ext/dbcom
>> To:
>> "Log4J Users List" ,
>> Date:
>> 24/06/2014 09:07
>> Subject:
>> Re: how to change logging level for a class at runtime
>> 
>> 
>> Classification: Public
>> 
>> Hi Ralph,
>> Thanks for getting back, but the examples do not show how to change
>levels 
>> at runtime,
>> 
>> There is no method addLogger(String, LoggerConfig) method on the
>> Configuration interface.
>> The addLogger method exists on BaseConfiguration, however it throws an
>> IllegalStateException as its already started, and says you have to
>create 
>> a new configuration.
>> 
>> Is it actually possible to change the logging level for a class/package
>at 
>> runtime after startup?
>> I think this is a common use case for troubleshooting critical long
>> running processes.
>> 
>> 
>> thanks,
>> Phil
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> From:
>> Ralph Goers 
>> To:
>> Log4J Users List ,
>> Date:
>> 23/06/2014 15:57
>> Subject:
>> Re: how to change logging level for a class at runtime
>> 
>> 
>> 
>> Please see 
>> http://people.apache.org/~rgoers/log4j2/manual/customconfig.html
>> 
>> Ralph
>> 
>>> On Jun 23, 2014, at 3:44 AM, Phil Wray  wrote:
>>> 
>>> Classification: Pub

RE: Set the log level based on command line args

2014-08-06 Thread Arwen Pond
Do you have to specify a root logger in the configuration?

additivity="false" solved my issue.  Thanks.

-Original Message-
From: Ralph Goers [mailto:ralph.go...@dslextreme.com] 
Sent: Wednesday, August 06, 2014 1:17 PM
To: Log4J Users List
Subject: Re: Set the log level based on command line args

I should also add that your configuration didn't show a root logger.  There is 
always a root logger so I suspect you are also logging to it.  If you make all 
your loggers be configured with additivity="false" that should stop happening.

Ralph

On Aug 6, 2014, at 1:13 PM, Ralph Goers  wrote:

> Please see 
> http://logging.apache.org/log4j/2.x/manual/configuration.html#Additivity
> 
> Ralph
> 


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: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org



Set the file name based on command line args

2014-08-06 Thread Arwen Pond
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.

Re: problems with web app and JndiContextSelector

2014-08-06 Thread Mike Calmus
I don't know for sure, but based upon my reading online it appears that may
be a new feature for 12c which we are not yet using.


On Wed, Aug 6, 2014 at 1:33 PM, Matt Sicker  wrote:

> Are system libraries in Weblogic loaded as OSGi bundles?
>
>
> On 6 August 2014 11:39, Mike Calmus  wrote:
>
> > After extensive trial and error I think I have things boiled down. In my
> > list "works" means that I see logging. For some there may be caveats.
> >
> > All tests were run using Weblogic 10.3.6 (a Servlet 2.5 container)
> running
> > on Java 7. There were no difference when using Log4j 2.0 versus 2.0.1.
> >
> > When I load the log4j libraries as a part of the server's startup classes
> > (out current preferred configuration with Log4j 1.2.x):
> >
> > 1) Standard web-app configuration with configuration file specified in
> > web.xml does not work
> > 2) Configured with JndiContextSelector as the Log4jContextSelector system
> > property it doesn't work when I have things configured correctly. If I
> > exclude the JNDI lookup environment properties I get an error in the
> System
> > log, but logging works.
> >
> > Removing the Log4j libraries from System startup and instead bundle them
> > with the application (no other changes)
> > Scenario 1 above now works.
> > The JNDI configuration does not work.
> >
> >
> >
> >
> > On Fri, Aug 1, 2014 at 3:16 PM, Mike Calmus  wrote:
> >
> > > We're using a Servlet 2.5 container and configuration. I added the
> > > Log4jContextSelector environment variable to the container startup as
> > well
> > > as loading all the Log4j 2.0 jars with the container. I added the
> > following
> > > items to my web.xml:
> > >
> > >   
> > > isLog4jContextSelectorNamed
> > > true
> > >   
> > >   
> > > log4jContextName
> > > myapp
> > >   
> > >   
> > > log4jConfiguration
> > >
> > >
> >
> file:///${sys:projectprops}/myapp/default/log4j2.xml
> > >   
> > >   
> > >
> > >
> >
> org.apache.logging.log4j.web.Log4jServletContextListener
> > >   
> > >   
> > > log4jServletFilter
> > >
> > >
> >
> org.apache.logging.log4j.web.Log4jServletFilter
> > >   
> > >   
> > > log4jServletFilter
> > > /*
> > > REQUEST
> > > FORWARD
> > > INCLUDE
> > > ERROR
> > >   
> > > With just this, logging works fine, but I get an error when the JNDI
> > > lookup fails.
> > >
> > >   
> > > Sets the logging context for the web-app
> > > log4j/context-name
> > > java.lang.String
> > > myapp
> > >   
> > > The JNDI lookup error goes away but logging stops working.
> > >
> > > I also tried adding the following with no change in results.
> > >
> > >   
> > > URL for configuring log4j context
> > > log4j/configuration-resource
> > > java.lang.String
> > >
> > >
> >
> file:///${sys:projectprops}/myapp/default/log4j2.xml
> > >   
> > >
> > >
> > > On Tue, Jul 29, 2014 at 11:37 AM, Ralph Goers <
> > ralph.go...@dslextreme.com>
> > > wrote:
> > >
> > >> The best would be a sample project that demonstrates the problem. At a
> > >> minimum I would think the web.xml and log4j 2 configuration.
> > >>
> > >> Ralph
> > >>
> > >> On Jul 29, 2014, at 5:47 AM, Mike Calmus  wrote:
> > >>
> > >> > I am having problems moving our web app over to Log4j 2.0 using JNDI
> > >> > lookups. I followed the configuration documentation and am not
> getting
> > >> any
> > >> > errors, but nothing is being logged to my configured appenders.
> > >> Weirdly, if
> > >> > I remove the JNDI env-entry configuration from web.xml logging seems
> > to
> > >> > work, albeit with the expected NameNotFoundException in the server
> > >> output.
> > >> >
> > >> > One possibly relevant configuration difference is that we load the
> > log4j
> > >> > jar files as part of server startup so each app doesn't have to load
> > >> them.
> > >> >
> > >> > Any ideas? What configuration can I provide to help troubleshoot?
> > >> >
> > >> > Thanks.
> > >>
> > >>
> > >> -
> > >> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> > >> For additional commands, e-mail: log4j-user-h...@logging.apache.org
> > >>
> > >>
> > >
> >
>
>
>
> --
> Matt Sicker 
>


Re: how to change logging level for a class at runtime [I]

2014-08-06 Thread Ralph Goers
I wouldn’t have asked for a patch submission if I didn’t plan to consider it. 
That said, we are all volunteers here and sometimes don’t get to things as 
quickly as we would like.

Ralph

On Aug 6, 2014, at 1:24 PM, Ang Xu  wrote:

> Hi,
> 
> Is there any plan to merge this patch to the main branch? This
> functionality seems extremely useful when modifying config file is not an
> option.
> 
> Thanks,
> Ang
> 
> On 6/25/14, 12:19 AM, "Phil Wray"  wrote:
> 
>> Classification: For internal use only
>> 
>> Hey Ralph.
>> Sure - have created:
>> LOG4J2-681 Add ability to change log level for any class/package
>> dynamically via jmx
>> 
>> cheers,
>> Phil
>> 
>> 
>> 
>> 
>> 
>> From:
>> Ralph Goers 
>> To:
>> Log4J Users List ,
>> Date:
>> 24/06/2014 15:34
>> Subject:
>> Re: how to change logging level for a class at runtime
>> 
>> 
>> 
>> Phil,
>> 
>> That looks pretty good.  It would be great if you could create a Jira
>> issue and add that as a patch
>> 
>> Sent from my iPad
>> 
>>> On Jun 24, 2014, at 7:01 AM, Phil Wray  wrote:
>>> 
>>> Classification: Public
>>> 
>>> Hi Ralph,
>>> Just to confirm running latest trunk version its possible to change
>> levels 
>>> at runtime using code as per your docs.
>>> Thanks for the help.
>>> I see a tag for 2.0-rc2 was taken a couple of days ago - I'm guessing
>> this 
>>> is being released imminently?
>>> 
>>> In case it helps others I ended up with the following util to let us
>>> change levels via jmx, just using whatever existing appender the logger
>>> would have had.
>>> 
>>>   @ManagedOperation
>>>   public String changeLogLevel(String loggerName, String level){
>>>   Level newLevel = Level.toLevel(level);
>>>   LoggerContext ctx = (LoggerContext)
>> LogManager.getContext(
>>> false);
>>>   Configuration config = ctx.getConfiguration();
>>>   LoggerConfig loggerConfig =
>>> config.getLoggerConfig(loggerName);
>>>   String msg;
>>> 
>>>   if (loggerName.equals(loggerConfig.getName())){
>>>   Level oldLevel = loggerConfig.getLevel();
>>>   loggerConfig.setLevel(newLevel);
>>>   msg = String.format("Modified existing logger %s
>>> level from %s to %s", loggerName, oldLevel, newLevel);
>>>   } else {
>>>   createCopyFrom(loggerConfig, loggerName,
>> newLevel, 
>>> config);
>>>   msg = String.format("Added new logger %s with
>>> level %s previously used logger %s with level %s", loggerName,
>>> newLevel, 
>> 
>>> loggerConfig.getName(), loggerConfig.getLevel());
>>>   }
>>>   ctx.updateLoggers();
>>>   LOG.info(msg);
>>>   return msg;
>>>   }
>>> 
>>>   private void createCopyFrom(LoggerConfig original, String name,
>>> Level level, Configuration config){
>>>   AppenderRef[] refs = original.getAppenderRefs().toArray(
>>> new AppenderRef[]{});
>>>   Filter filter = original.getFilter();
>>>   LoggerConfig copy = LoggerConfig.createLogger(
>>>   "false",
>>>   level,
>>>   name,
>>>   Boolean.toString
>>> (original.isIncludeLocation()),
>>>   refs, null, config, filter);
>>> 
>>>   for (Appender appender :
>>> original.getAppenders().values()){
>>>   copy.addAppender(appender, null, null);
>>>   }
>>>   config.addLogger(name, copy);
>>>   }
>>> 
>>> cheers,
>>> Phil
>>> 
>>> 
>>> 
>>> 
>>> From:
>>> Phil Wray/ext/dbcom
>>> To:
>>> "Log4J Users List" ,
>>> Date:
>>> 24/06/2014 11:16
>>> Subject:
>>> Re: how to change logging level for a class at runtime
>>> 
>>> 
>>> Classification: Public
>>> 
>>> Hi Ralph,
>>> Sorry hadn't looked at the latest source  - see you've made changes to
>>> Configuration to allow adding of LoggerConfig via the interface that
>>> are 
>> 
>>> not yet in the release candidate jar.
>>> I'll take the latest source and build from that.
>>> 
>>> 
>>> thanks,
>>> Phil
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> From:
>>> Phil Wray/ext/dbcom
>>> To:
>>> "Log4J Users List" ,
>>> Date:
>>> 24/06/2014 09:07
>>> Subject:
>>> Re: how to change logging level for a class at runtime
>>> 
>>> 
>>> Classification: Public
>>> 
>>> Hi Ralph,
>>> Thanks for getting back, but the examples do not show how to change
>> levels 
>>> at runtime,
>>> 
>>> There is no method addLogger(String, LoggerConfig) method on the
>>> Configuration interface.
>>> The addLogger method exists on BaseConfiguration, however it throws an
>>> IllegalStateException as its already started, and says you have to
>> create 
>>> a new configuration.
>>> 
>>> Is it actually possible to change the logging level for a class/package
>> at 
>>> runtime after startup?
>>> I think this is a common use case for troubleshooting critica

Re: Set the file name based on command line args

2014-08-06 Thread Ralph Goers
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  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: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org



Re: Set the file name based on command line args

2014-08-06 Thread Gary Gregory
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 
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  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: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>
>


-- 
E-Mail: garydgreg...@gmail.com | ggreg...@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


Re: Set the file name based on command line args

2014-08-06 Thread Ralph Goers
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  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 
> 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  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: log4j-user-unsubscr...@logging.apache.org
>> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>> 
>> 
> 
> 
> -- 
> E-Mail: garydgreg...@gmail.com | ggreg...@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-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org



Re: Set the file name based on command line args

2014-08-06 Thread Gary Gregory
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 
 Date:08/06/2014  19:18  (GMT-05:00) 
To: Log4J Users List  
Subject: Re: Set the file name based on command line args 
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  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 
> 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  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: log4j-user-unsubscr...@logging.apache.org
>> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>> 
>> 
> 
> 
> -- 
> E-Mail: garydgreg...@gmail.com | ggreg...@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-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org



Re: Set the file name based on command line args

2014-08-06 Thread Remko Popma
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 
>  Date:08/06/2014  19:18  (GMT-05:00) 
> To: Log4J Users List  
> Subject: Re: Set the file name based on command line args 
> 
> 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  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 
>> 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  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: log4j-user-unsubscr...@logging.apache.org
>>> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>> 
>> 
>> -- 
>> E-Mail: garydgreg...@gmail.com | ggreg...@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-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
> 

-
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org



Re: Set the file name based on command line args

2014-08-06 Thread Gary Gregory
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  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.go...@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’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 
> 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  >
> >> 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  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: log4j-user-unsubscr...@logging.apache.org
> >>> For additional commands, e-mail: log4j-user-h...@logging.apache.org
> >>
> >>
> >> --
> >> E-Mail: garydgreg...@gmail.com | ggreg...@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-unsubscr...@logging.apache.org
> > For additional commands, e-mail: log4j-user-h...@logging.apache.org
> >
>
> -
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>
>


-- 
E-Mail: garydgreg...@gmail.com | ggreg...@apache.org
Java Persistence with Hibernate, Second Edition


Re: Set the file name based on command line args

2014-08-06 Thread Remko Popma
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/StackFrame.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.go...@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’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 
>> 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 >> 
 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  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: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
 
 
 --
 E-Mail: garydgreg...@gmail.com | ggreg...@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-unsubscr...@logging.apache.org
>>> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>> 
>> -
>> To unsubscribe, e-mail: log4j-user-uns

Re: Set the file name based on command line args

2014-08-06 Thread Gary Gregory
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/StackFrame.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.go...@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’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 
> >> 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 <
> ralph.go...@dslextreme.com
> >>>
>  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  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: log4j-user-unsubscr...@logging.apache.org
> > For additional commands, e-mail: log4j-user-h...@logging.apache.org
> 
> 
>  --
>  E-Mail: garydgreg...@gmail.com | ggreg...@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/

Re: how to change logging level for a class at runtime [I]

2014-08-06 Thread Matt Sicker
I may take a look at this soon as I've been getting into JMX lately at work
in order to automate some build/deployment infrastructure. It's still fresh
;)


On 6 August 2014 17:42, Ralph Goers  wrote:

> I wouldn’t have asked for a patch submission if I didn’t plan to consider
> it. That said, we are all volunteers here and sometimes don’t get to things
> as quickly as we would like.
>
> Ralph
>
> On Aug 6, 2014, at 1:24 PM, Ang Xu  wrote:
>
> > Hi,
> >
> > Is there any plan to merge this patch to the main branch? This
> > functionality seems extremely useful when modifying config file is not an
> > option.
> >
> > Thanks,
> > Ang
> >
> > On 6/25/14, 12:19 AM, "Phil Wray"  wrote:
> >
> >> Classification: For internal use only
> >>
> >> Hey Ralph.
> >> Sure - have created:
> >> LOG4J2-681 Add ability to change log level for any class/package
> >> dynamically via jmx
> >>
> >> cheers,
> >> Phil
> >>
> >>
> >>
> >>
> >>
> >> From:
> >> Ralph Goers 
> >> To:
> >> Log4J Users List ,
> >> Date:
> >> 24/06/2014 15:34
> >> Subject:
> >> Re: how to change logging level for a class at runtime
> >>
> >>
> >>
> >> Phil,
> >>
> >> That looks pretty good.  It would be great if you could create a Jira
> >> issue and add that as a patch
> >>
> >> Sent from my iPad
> >>
> >>> On Jun 24, 2014, at 7:01 AM, Phil Wray  wrote:
> >>>
> >>> Classification: Public
> >>>
> >>> Hi Ralph,
> >>> Just to confirm running latest trunk version its possible to change
> >> levels
> >>> at runtime using code as per your docs.
> >>> Thanks for the help.
> >>> I see a tag for 2.0-rc2 was taken a couple of days ago - I'm guessing
> >> this
> >>> is being released imminently?
> >>>
> >>> In case it helps others I ended up with the following util to let us
> >>> change levels via jmx, just using whatever existing appender the logger
> >>> would have had.
> >>>
> >>>   @ManagedOperation
> >>>   public String changeLogLevel(String loggerName, String level){
> >>>   Level newLevel = Level.toLevel(level);
> >>>   LoggerContext ctx = (LoggerContext)
> >> LogManager.getContext(
> >>> false);
> >>>   Configuration config = ctx.getConfiguration();
> >>>   LoggerConfig loggerConfig =
> >>> config.getLoggerConfig(loggerName);
> >>>   String msg;
> >>>
> >>>   if (loggerName.equals(loggerConfig.getName())){
> >>>   Level oldLevel = loggerConfig.getLevel();
> >>>   loggerConfig.setLevel(newLevel);
> >>>   msg = String.format("Modified existing logger %s
> >>> level from %s to %s", loggerName, oldLevel, newLevel);
> >>>   } else {
> >>>   createCopyFrom(loggerConfig, loggerName,
> >> newLevel,
> >>> config);
> >>>   msg = String.format("Added new logger %s with
> >>> level %s previously used logger %s with level %s", loggerName,
> >>> newLevel,
> >>
> >>> loggerConfig.getName(), loggerConfig.getLevel());
> >>>   }
> >>>   ctx.updateLoggers();
> >>>   LOG.info(msg);
> >>>   return msg;
> >>>   }
> >>>
> >>>   private void createCopyFrom(LoggerConfig original, String name,
> >>> Level level, Configuration config){
> >>>   AppenderRef[] refs = original.getAppenderRefs().toArray(
> >>> new AppenderRef[]{});
> >>>   Filter filter = original.getFilter();
> >>>   LoggerConfig copy = LoggerConfig.createLogger(
> >>>   "false",
> >>>   level,
> >>>   name,
> >>>   Boolean.toString
> >>> (original.isIncludeLocation()),
> >>>   refs, null, config, filter);
> >>>
> >>>   for (Appender appender :
> >>> original.getAppenders().values()){
> >>>   copy.addAppender(appender, null, null);
> >>>   }
> >>>   config.addLogger(name, copy);
> >>>   }
> >>>
> >>> cheers,
> >>> Phil
> >>>
> >>>
> >>>
> >>>
> >>> From:
> >>> Phil Wray/ext/dbcom
> >>> To:
> >>> "Log4J Users List" ,
> >>> Date:
> >>> 24/06/2014 11:16
> >>> Subject:
> >>> Re: how to change logging level for a class at runtime
> >>>
> >>>
> >>> Classification: Public
> >>>
> >>> Hi Ralph,
> >>> Sorry hadn't looked at the latest source  - see you've made changes to
> >>> Configuration to allow adding of LoggerConfig via the interface that
> >>> are
> >>
> >>> not yet in the release candidate jar.
> >>> I'll take the latest source and build from that.
> >>>
> >>>
> >>> thanks,
> >>> Phil
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> From:
> >>> Phil Wray/ext/dbcom
> >>> To:
> >>> "Log4J Users List" ,
> >>> Date:
> >>> 24/06/2014 09:07
> >>> Subject:
> >>> Re: how to change logging level for a class at runtime
> >>>
> >>>
> >>> Classification: Public
> >>>
> >>> Hi Ralph,
> >>> Thanks for getting back, but the examples do not show how to change
> >> leve

Re: Set the file name based on command line args

2014-08-06 Thread Matt Sicker
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/StackFrame.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.go...@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’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 
> > >> 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 <
> > ralph.go...@dslextreme.com
> > >>>
> >  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  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: log4j-user-unsubscr...@logging.apache.org
> > > For additional commands, e-mail:
> log4j-user-h...@logging.apache.org
> > 
> > 
> >  --
> >  E-Ma

Re: Set the log level based on command line args

2014-08-06 Thread Matt Sicker
I'm pretty sure the root logger has an implicit default configuration if
it's missing from your config file.


On 6 August 2014 15:57, Arwen Pond  wrote:

> Do you have to specify a root logger in the configuration?
>
> additivity="false" solved my issue.  Thanks.
>
> -Original Message-
> From: Ralph Goers [mailto:ralph.go...@dslextreme.com]
> Sent: Wednesday, August 06, 2014 1:17 PM
> To: Log4J Users List
> Subject: Re: Set the log level based on command line args
>
> I should also add that your configuration didn't show a root logger.
>  There is always a root logger so I suspect you are also logging to it.  If
> you make all your loggers be configured with additivity="false" that should
> stop happening.
>
> Ralph
>
> On Aug 6, 2014, at 1:13 PM, Ralph Goers 
> wrote:
>
> > Please see
> http://logging.apache.org/log4j/2.x/manual/configuration.html#Additivity
> >
> > Ralph
> >
>
>
> 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: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>
>


-- 
Matt Sicker 


Re: problems with web app and JndiContextSelector

2014-08-06 Thread Matt Sicker
Oh, well that wouldn't really help things at this point as I think there
are still some strange issues in the OSGi support in Log4j anyhow. I'll see
if I can take a look at this since we use the same version of Weblogic at
my work (thus I actually know a little bit about this application).


On 6 August 2014 16:31, Mike Calmus  wrote:

> I don't know for sure, but based upon my reading online it appears that may
> be a new feature for 12c which we are not yet using.
>
>
> On Wed, Aug 6, 2014 at 1:33 PM, Matt Sicker  wrote:
>
> > Are system libraries in Weblogic loaded as OSGi bundles?
> >
> >
> > On 6 August 2014 11:39, Mike Calmus  wrote:
> >
> > > After extensive trial and error I think I have things boiled down. In
> my
> > > list "works" means that I see logging. For some there may be caveats.
> > >
> > > All tests were run using Weblogic 10.3.6 (a Servlet 2.5 container)
> > running
> > > on Java 7. There were no difference when using Log4j 2.0 versus 2.0.1.
> > >
> > > When I load the log4j libraries as a part of the server's startup
> classes
> > > (out current preferred configuration with Log4j 1.2.x):
> > >
> > > 1) Standard web-app configuration with configuration file specified in
> > > web.xml does not work
> > > 2) Configured with JndiContextSelector as the Log4jContextSelector
> system
> > > property it doesn't work when I have things configured correctly. If I
> > > exclude the JNDI lookup environment properties I get an error in the
> > System
> > > log, but logging works.
> > >
> > > Removing the Log4j libraries from System startup and instead bundle
> them
> > > with the application (no other changes)
> > > Scenario 1 above now works.
> > > The JNDI configuration does not work.
> > >
> > >
> > >
> > >
> > > On Fri, Aug 1, 2014 at 3:16 PM, Mike Calmus  wrote:
> > >
> > > > We're using a Servlet 2.5 container and configuration. I added the
> > > > Log4jContextSelector environment variable to the container startup as
> > > well
> > > > as loading all the Log4j 2.0 jars with the container. I added the
> > > following
> > > > items to my web.xml:
> > > >
> > > >   
> > > > isLog4jContextSelectorNamed
> > > > true
> > > >   
> > > >   
> > > > log4jContextName
> > > > myapp
> > > >   
> > > >   
> > > > log4jConfiguration
> > > >
> > > >
> > >
> >
> file:///${sys:projectprops}/myapp/default/log4j2.xml
> > > >   
> > > >   
> > > >
> > > >
> > >
> >
> org.apache.logging.log4j.web.Log4jServletContextListener
> > > >   
> > > >   
> > > > log4jServletFilter
> > > >
> > > >
> > >
> >
> org.apache.logging.log4j.web.Log4jServletFilter
> > > >   
> > > >   
> > > > log4jServletFilter
> > > > /*
> > > > REQUEST
> > > > FORWARD
> > > > INCLUDE
> > > > ERROR
> > > >   
> > > > With just this, logging works fine, but I get an error when the JNDI
> > > > lookup fails.
> > > >
> > > >   
> > > > Sets the logging context for the
> web-app
> > > > log4j/context-name
> > > > java.lang.String
> > > > myapp
> > > >   
> > > > The JNDI lookup error goes away but logging stops working.
> > > >
> > > > I also tried adding the following with no change in results.
> > > >
> > > >   
> > > > URL for configuring log4j context
> > > > log4j/configuration-resource
> > > > java.lang.String
> > > >
> > > >
> > >
> >
> file:///${sys:projectprops}/myapp/default/log4j2.xml
> > > >   
> > > >
> > > >
> > > > On Tue, Jul 29, 2014 at 11:37 AM, Ralph Goers <
> > > ralph.go...@dslextreme.com>
> > > > wrote:
> > > >
> > > >> The best would be a sample project that demonstrates the problem.
> At a
> > > >> minimum I would think the web.xml and log4j 2 configuration.
> > > >>
> > > >> Ralph
> > > >>
> > > >> On Jul 29, 2014, at 5:47 AM, Mike Calmus  wrote:
> > > >>
> > > >> > I am having problems moving our web app over to Log4j 2.0 using
> JNDI
> > > >> > lookups. I followed the configuration documentation and am not
> > getting
> > > >> any
> > > >> > errors, but nothing is being logged to my configured appenders.
> > > >> Weirdly, if
> > > >> > I remove the JNDI env-entry configuration from web.xml logging
> seems
> > > to
> > > >> > work, albeit with the expected NameNotFoundException in the server
> > > >> output.
> > > >> >
> > > >> > One possibly relevant configuration difference is that we load the
> > > log4j
> > > >> > jar files as part of server startup so each app doesn't have to
> load
> > > >> them.
> > > >> >
> > > >> > Any ideas? What configuration can I provide to help troubleshoot?
> > > >> >
> > > >> > Thanks.
> > > >>
> > > >>
> > > >>
> -
> > > >> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> > > >> For additional commands, e-mail: log4j-user-h...@logging.apache.org
> > > >>
> > > >>
> > > >
> > >
> >
> >
> >
> > --
> > Matt Sicker 
> >
>



-- 
Matt Sicker 


Re: Set the file name based on command line args

2014-08-06 Thread Gary Gregory
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/StackFrame.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.go...@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’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 
> > > >> 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 <
> > > ralph.go...@dslextreme.com
> > > >>>
> > >  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  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 se