Re: How to have a separate log file for a thread and all sub threads?

2019-04-29 Thread Benjamin Jaton
Yes I've explored that route a little bit, inspired by the existing
ClassLoaderContextSelector implementation.

One thing I'm not sure about is how do you "set" the log level on a whole
LoggerContext?

On Mon, Apr 29, 2019 at 12:03 PM Ralph Goers 
wrote:

> If you created a ThreadGroupContextSelector it probably would perform
> better, but you might be trading one set of problems for another.
>
> Ralph
>
> > On Apr 29, 2019, at 11:58 AM, Benjamin Jaton 
> wrote:
> >
> > I ended up making a DynamicThreadholdFilter to be able to resolve the log
> > level dynamically.
> >
> > What's not so great is that this management of the log level with a
> "post"
> > filter requires the logger to let everything through (TRACE).
> > So then methods like isDebugEnabled() will always return true.
> >
> > Anyways for my use case we'll have to go with this as we need a log level
> > per job (threadgroup).
> >
> > On Mon, Apr 29, 2019 at 11:43 AM Matt Sicker  wrote:
> >
> >> Requiring the use of ThreadContext data everywhere can slow things
> >> down a little, though not sure by how much.
> >>
> >> On Thu, 25 Apr 2019 at 13:35, Benjamin Jaton 
> >> wrote:
> >>>
> >>> I've used ThresholdFilter to have the log level check at the level of
> the
> >>> (sub) appender:
> >>>
> >>>  "ThresholdFilter": {
> >>>"level": "${my:threadgroup.jobLogLevel}",
> >>>"onMatch": "ACCEPT",
> >>>"onMismatch": "DENY"
> >>>  }
> >>>
> >>> Of course then I need to have the root logger in TRACE to let
> everything
> >> in
> >>> to be filtered later on by the appender:
> >>>
> >>>"loggers": {
> >>>  "root": {
> >>>"level": "TRACE",
> >>>"additivity": "false",
> >>>"includeLocation": "true",
> >>>"AppenderRef": {
> >>>  "ref": "JobsRoutingAppender"
> >>>}
> >>>  }
> >>>}
> >>>
> >>> What do you think of this?
> >>> Is performance a concern with this approach?
> >>>
> >>> On Thu, Apr 25, 2019 at 9:33 AM Ralph Goers <
> ralph.go...@dslextreme.com>
> >>> wrote:
> >>>
> >>>> Another possibility would be to have a ThreadGroupContextSelector and
> >> then
> >>>> use a different LoggerContext and configuration for each ThreadGroup.
> >>>> However, that could get very complicated. The RoutingAppender pretty
> >> much
> >>>> accomplishes the same thing and would be much easier to do.
> >>>>
> >>>> Ralph
> >>>>
> >>>>> On Apr 25, 2019, at 9:21 AM, Matt Sicker  wrote:
> >>>>>
> >>>>> Oh damn, right, bit of a limitation there. I'll ponder on this a bit.
> >>>>>
> >>>>> On Thu, 25 Apr 2019 at 11:18, Ralph Goers <
> >> ralph.go...@dslextreme.com>
> >>>> wrote:
> >>>>>>
> >>>>>> Matt, Benjamin’s issue is that he has no control over what is
> >> running
> >>>> in the “jobs” but he wants all the logs for a “job” to end up in the
> >> same
> >>>> appender. His definition of a job is that he is creating a thread to
> >> run it
> >>>> and everything under that thread should route to that Appender. So he
> >>>> cannot control what logger names are used much less whether they have
> >>>> Markers or not.
> >>>>>>
> >>>>>> Ralph
> >>>>>>
> >>>>>>> On Apr 25, 2019, at 8:59 AM, Matt Sicker  wrote:
> >>>>>>>
> >>>>>>> On Wed, 24 Apr 2019 at 18:47, Benjamin Jaton <
> >> benjamin.ja...@gmail.com>
> >>>> wrote:
> >>>>>>>> I've implemented the solution based on ThreadGroups. Now I am
> >> trying
> >>>> to
> >>>>>>>> have a separate log level per job. The goal is to be able to set
> >> one
> >>>> job in
> >>>>>>>> DEBUG or

Re: How to have a separate log file for a thread and all sub threads?

2019-04-29 Thread Benjamin Jaton
I ended up making a DynamicThreadholdFilter to be able to resolve the log
level dynamically.

What's not so great is that this management of the log level with a "post"
filter requires the logger to let everything through (TRACE).
So then methods like isDebugEnabled() will always return true.

Anyways for my use case we'll have to go with this as we need a log level
per job (threadgroup).

On Mon, Apr 29, 2019 at 11:43 AM Matt Sicker  wrote:

> Requiring the use of ThreadContext data everywhere can slow things
> down a little, though not sure by how much.
>
> On Thu, 25 Apr 2019 at 13:35, Benjamin Jaton 
> wrote:
> >
> > I've used ThresholdFilter to have the log level check at the level of the
> > (sub) appender:
> >
> >   "ThresholdFilter": {
> > "level": "${my:threadgroup.jobLogLevel}",
> > "onMatch": "ACCEPT",
> > "onMismatch": "DENY"
> >   }
> >
> > Of course then I need to have the root logger in TRACE to let everything
> in
> > to be filtered later on by the appender:
> >
> > "loggers": {
> >   "root": {
> > "level": "TRACE",
> > "additivity": "false",
> > "includeLocation": "true",
> > "AppenderRef": {
> >   "ref": "JobsRoutingAppender"
> > }
> >   }
> > }
> >
> > What do you think of this?
> > Is performance a concern with this approach?
> >
> > On Thu, Apr 25, 2019 at 9:33 AM Ralph Goers 
> > wrote:
> >
> > > Another possibility would be to have a ThreadGroupContextSelector and
> then
> > > use a different LoggerContext and configuration for each ThreadGroup.
> > > However, that could get very complicated. The RoutingAppender pretty
> much
> > > accomplishes the same thing and would be much easier to do.
> > >
> > > Ralph
> > >
> > > > On Apr 25, 2019, at 9:21 AM, Matt Sicker  wrote:
> > > >
> > > > Oh damn, right, bit of a limitation there. I'll ponder on this a bit.
> > > >
> > > > On Thu, 25 Apr 2019 at 11:18, Ralph Goers <
> ralph.go...@dslextreme.com>
> > > wrote:
> > > >>
> > > >> Matt, Benjamin’s issue is that he has no control over what is
> running
> > > in the “jobs” but he wants all the logs for a “job” to end up in the
> same
> > > appender. His definition of a job is that he is creating a thread to
> run it
> > > and everything under that thread should route to that Appender. So he
> > > cannot control what logger names are used much less whether they have
> > > Markers or not.
> > > >>
> > > >> Ralph
> > > >>
> > > >>> On Apr 25, 2019, at 8:59 AM, Matt Sicker  wrote:
> > > >>>
> > > >>> On Wed, 24 Apr 2019 at 18:47, Benjamin Jaton <
> benjamin.ja...@gmail.com>
> > > wrote:
> > > >>>> I've implemented the solution based on ThreadGroups. Now I am
> trying
> > > to
> > > >>>> have a separate log level per job. The goal is to be able to set
> one
> > > job in
> > > >>>> DEBUG or TRACE while the others stay in WARN. Possible?
> > > >>>> The RoutingAppender creates an appender per route but as far as I
> > > know I
> > > >>>> cannot set a log level on the appender object. I guess filters
> could
> > > be
> > > >>>> used but is there something simpler I'm missing?
> > > >>>
> > > >>> I think you'd be better off using markers for that. See
> > > >>> https://logging.apache.org/log4j/2.x/manual/markers.html
> > > >>>
> > > >>> You might also be able to just use a naming scheme for your loggers
> > > >>> that automatically makes them separately configurable as typical
> > > >>> loggers. For example, say you use a naming scheme
> > > >>> "com.example.threadgroup." as your loggers. Then you
> could
> > > >>> configure them by name as usual.
> > > >>>
> > > >>> --
> > > >>> Matt Sicker 
> > > >>>
> > > >>>
> -
> &

Re: How to have a separate log file for a thread and all sub threads?

2019-04-25 Thread Benjamin Jaton
I've used ThresholdFilter to have the log level check at the level of the
(sub) appender:

  "ThresholdFilter": {
"level": "${my:threadgroup.jobLogLevel}",
"onMatch": "ACCEPT",
"onMismatch": "DENY"
  }

Of course then I need to have the root logger in TRACE to let everything in
to be filtered later on by the appender:

"loggers": {
  "root": {
"level": "TRACE",
"additivity": "false",
"includeLocation": "true",
"AppenderRef": {
  "ref": "JobsRoutingAppender"
}
  }
}

What do you think of this?
Is performance a concern with this approach?

On Thu, Apr 25, 2019 at 9:33 AM Ralph Goers 
wrote:

> Another possibility would be to have a ThreadGroupContextSelector and then
> use a different LoggerContext and configuration for each ThreadGroup.
> However, that could get very complicated. The RoutingAppender pretty much
> accomplishes the same thing and would be much easier to do.
>
> Ralph
>
> > On Apr 25, 2019, at 9:21 AM, Matt Sicker  wrote:
> >
> > Oh damn, right, bit of a limitation there. I'll ponder on this a bit.
> >
> > On Thu, 25 Apr 2019 at 11:18, Ralph Goers 
> wrote:
> >>
> >> Matt, Benjamin’s issue is that he has no control over what is running
> in the “jobs” but he wants all the logs for a “job” to end up in the same
> appender. His definition of a job is that he is creating a thread to run it
> and everything under that thread should route to that Appender. So he
> cannot control what logger names are used much less whether they have
> Markers or not.
> >>
> >> Ralph
> >>
> >>> On Apr 25, 2019, at 8:59 AM, Matt Sicker  wrote:
> >>>
> >>> On Wed, 24 Apr 2019 at 18:47, Benjamin Jaton 
> wrote:
> >>>> I've implemented the solution based on ThreadGroups. Now I am trying
> to
> >>>> have a separate log level per job. The goal is to be able to set one
> job in
> >>>> DEBUG or TRACE while the others stay in WARN. Possible?
> >>>> The RoutingAppender creates an appender per route but as far as I
> know I
> >>>> cannot set a log level on the appender object. I guess filters could
> be
> >>>> used but is there something simpler I'm missing?
> >>>
> >>> I think you'd be better off using markers for that. See
> >>> https://logging.apache.org/log4j/2.x/manual/markers.html
> >>>
> >>> You might also be able to just use a naming scheme for your loggers
> >>> that automatically makes them separately configurable as typical
> >>> loggers. For example, say you use a naming scheme
> >>> "com.example.threadgroup." as your loggers. Then you could
> >>> configure them by name as usual.
> >>>
> >>> --
> >>> Matt Sicker 
> >>>
> >>> -
> >>> 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
> >>
> >
> >
> > --
> > Matt Sicker 
> >
> > -
> > 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: How to have a separate log file for a thread and all sub threads?

2019-04-24 Thread Benjamin Jaton
OK thanks. It's good to know the limitations, I think it's good enough for
my use case.

I've implemented the solution based on ThreadGroups. Now I am trying to
have a separate log level per job. The goal is to be able to set one job in
DEBUG or TRACE while the others stay in WARN. Possible?
The RoutingAppender creates an appender per route but as far as I know I
cannot set a log level on the appender object. I guess filters could be
used but is there something simpler I'm missing?

On Wed, Apr 24, 2019 at 4:16 PM Ralph Goers 
wrote:

> You could keep track of the ThreadGroups that represent jobs. Then
> traverse the parent of each ThreadGroup until one matches a registered job.
> But even this isn’t foolproof since the application can create a
> ThreadGroup with a parent ThreadGroup outside anything you know about. But
> I would think it would work in the majority of cases.
>
> Ralph
>
>
> > On Apr 24, 2019, at 1:53 PM, Benjamin Jaton 
> wrote:
> >
> > Yes, indeed when I replace t1.run() with t1.start() it does output:
> > t1 threadgroup = mygroup
> > t2 threadgroup = mygroup
> > Thank you!
> >
> > So this could be a fine solution as long as the third party libs don't
> > override the ThreadGroup of the threads they create.
> > If they do override the threadgroup, there is no way to have 1 log file
> per
> > job correct?
> >
> > Thanks again for the help,
> > Benjamin
> >
> >
> >
> > On Wed, Apr 24, 2019 at 11:33 AM Ralph Goers  >
> > wrote:
> >
> >> The relevant section is -
> >>
> https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#Thread-java.lang.ThreadGroup-java.lang.Runnable-
> >> <
> >>
> https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#Thread-java.lang.ThreadGroup-java.lang.Runnable-
> >>> .
> >>
> >> Your test isn’t valid because you have 3 threads. The first is the main
> >> thread with a thread group of main, the second thread is created in the
> >> first Thread but directly associated with thread group “my group”. The
> >> third thread is created in thread “main” and so is in ThreadGroup main.
> >> While you may have created the third Thread within the scope of the
> second
> >> Thread Object, the code to create the third thread was not executed
> within
> >> the execution of Thread 2 as this program only has a single thread of
> >> execution. Thread 2 and 3 are never started.
> >>
> >> In other words Thread 3 must be executed from the call stack of Thread
> 2’s
> >> run method while Thread 2 is in control of the execution.
> >>
> >> Ralph
> >>
> >>> On Apr 24, 2019, at 9:21 AM, Benjamin Jaton 
> >> wrote:
> >>>
> >>> Could you point me to the relevant section?
> >>>
> >>> I did the following test:
> >>> final ThreadGroup g = new ThreadGroup("mygroup");
> >>> Thread t1 = new Thread(g, () -> {
> >>> Thread t2 = new Thread(() -> { });
> >>> System.out.println("t2 threadgroup = " +
> t2.getThreadGroup().getName());
> >>> });
> >>> System.out.println("t1 threadgroup = " +
> t1.getThreadGroup().getName());
> >>> t1.run();
> >>>
> >>> And I get:
> >>> t1 threadgroup = mygroup
> >>> t2 threadgroup = main
> >>>
> >>> t2 is started from t1 yet didn't inherit the threadgroup. What am I
> >> missing?
> >>>
> >>> On Wed, Apr 24, 2019 at 6:05 AM Apache 
> >> wrote:
> >>>
> >>>> My reading of the javadoc for Thread indicates the do by default.
> >>>>
> >>>> Ralph
> >>>>
> >>>> On Apr 23, 2019, at 10:12 PM, Benjamin Jaton <
> benjamin.ja...@gmail.com>
> >>>> wrote:
> >>>>
> >>>>>> If you want all the threads in a “job” then I would create the
> parent
> >>>>> thread with its own thread group and use the thread group name in the
> >>>>> lookup.
> >>>>>
> >>>>> But how do I assign the thread group to threads that 3rd party
> >> libraries
> >>>>> create? I don't think child threads naturally inherit the ThreadGroup
> >> of
> >>>>> their parents.
> >>>>>
> >>>>> On Tue, Apr 23, 2019 at 8:36 PM Ralph Goers <
> >> ralph.go...@dslextreme.com>
> >>>>> wrote:
> >>>>>
> >>

Re: How to have a separate log file for a thread and all sub threads?

2019-04-24 Thread Benjamin Jaton
Yes, indeed when I replace t1.run() with t1.start() it does output:
t1 threadgroup = mygroup
t2 threadgroup = mygroup
Thank you!

So this could be a fine solution as long as the third party libs don't
override the ThreadGroup of the threads they create.
If they do override the threadgroup, there is no way to have 1 log file per
job correct?

Thanks again for the help,
Benjamin



On Wed, Apr 24, 2019 at 11:33 AM Ralph Goers 
wrote:

> The relevant section is -
> https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#Thread-java.lang.ThreadGroup-java.lang.Runnable-
> <
> https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#Thread-java.lang.ThreadGroup-java.lang.Runnable-
> >.
>
> Your test isn’t valid because you have 3 threads. The first is the main
> thread with a thread group of main, the second thread is created in the
> first Thread but directly associated with thread group “my group”. The
> third thread is created in thread “main” and so is in ThreadGroup main.
> While you may have created the third Thread within the scope of the second
> Thread Object, the code to create the third thread was not executed within
> the execution of Thread 2 as this program only has a single thread of
> execution. Thread 2 and 3 are never started.
>
> In other words Thread 3 must be executed from the call stack of Thread 2’s
> run method while Thread 2 is in control of the execution.
>
> Ralph
>
> > On Apr 24, 2019, at 9:21 AM, Benjamin Jaton 
> wrote:
> >
> > Could you point me to the relevant section?
> >
> > I did the following test:
> > final ThreadGroup g = new ThreadGroup("mygroup");
> > Thread t1 = new Thread(g, () -> {
> > Thread t2 = new Thread(() -> { });
> > System.out.println("t2 threadgroup = " + t2.getThreadGroup().getName());
> > });
> > System.out.println("t1 threadgroup = " + t1.getThreadGroup().getName());
> > t1.run();
> >
> > And I get:
> > t1 threadgroup = mygroup
> > t2 threadgroup = main
> >
> > t2 is started from t1 yet didn't inherit the threadgroup. What am I
> missing?
> >
> > On Wed, Apr 24, 2019 at 6:05 AM Apache 
> wrote:
> >
> >> My reading of the javadoc for Thread indicates the do by default.
> >>
> >> Ralph
> >>
> >> On Apr 23, 2019, at 10:12 PM, Benjamin Jaton 
> >> wrote:
> >>
> >>>> If you want all the threads in a “job” then I would create the parent
> >>> thread with its own thread group and use the thread group name in the
> >>> lookup.
> >>>
> >>> But how do I assign the thread group to threads that 3rd party
> libraries
> >>> create? I don't think child threads naturally inherit the ThreadGroup
> of
> >>> their parents.
> >>>
> >>> On Tue, Apr 23, 2019 at 8:36 PM Ralph Goers <
> ralph.go...@dslextreme.com>
> >>> wrote:
> >>>
> >>>> I think the solution is pretty simple. The RoutingAppender doesn’t
> only
> >>>> work with the ThreadContext. It works using a lookup. So if you were
> to
> >> use
> >>>> a ThreadLookup that used ${{thread:id}} you would get a new Appender
> for
> >>>> each thread id. To be honest, I am not sure why we haven’t created a
> >>>> ThreadLookup before. I could easily see multiple places were the
> thread
> >> id,
> >>>> name, priority or ThreadGroup name might want to be used.
> >>>>
> >>>> If you want all the threads in a “job” then I would create the parent
> >>>> thread with its own thread group and use the thread group name in the
> >>>> lookup.
> >>>>
> >>>> Ralph
> >>>>
> >>>>> On Apr 23, 2019, at 5:06 PM, Benjamin Jaton <
> benjamin.ja...@gmail.com>
> >>>> wrote:
> >>>>>
> >>>>> Hello,
> >>>>>
> >>>>> Several times I've been in a situation where in a given JVM I am
> trying
> >>>> to
> >>>>> run distinct jobs in separate threads, who themselves might spawn
> their
> >>>> own
> >>>>> threads.
> >>>>> In those situations I usually want the logging of each job in a
> >> separate
> >>>>> log file, and that has proven to be difficult.
> >>>>>
> >>>>> Log4j2 has a routing appender that allows to create a separate
> appender
> >>>> for
> >>>>> each job given that you can p

Re: How to have a separate log file for a thread and all sub threads?

2019-04-24 Thread Benjamin Jaton
Could you point me to the relevant section?

I did the following test:
final ThreadGroup g = new ThreadGroup("mygroup");
Thread t1 = new Thread(g, () -> {
Thread t2 = new Thread(() -> { });
System.out.println("t2 threadgroup = " + t2.getThreadGroup().getName());
});
System.out.println("t1 threadgroup = " + t1.getThreadGroup().getName());
t1.run();

And I get:
t1 threadgroup = mygroup
t2 threadgroup = main

t2 is started from t1 yet didn't inherit the threadgroup. What am I missing?

On Wed, Apr 24, 2019 at 6:05 AM Apache  wrote:

> My reading of the javadoc for Thread indicates the do by default.
>
> Ralph
>
> On Apr 23, 2019, at 10:12 PM, Benjamin Jaton 
> wrote:
>
> >> If you want all the threads in a “job” then I would create the parent
> > thread with its own thread group and use the thread group name in the
> > lookup.
> >
> > But how do I assign the thread group to threads that 3rd party libraries
> > create? I don't think child threads naturally inherit the ThreadGroup of
> > their parents.
> >
> > On Tue, Apr 23, 2019 at 8:36 PM Ralph Goers 
> > wrote:
> >
> >> I think the solution is pretty simple. The RoutingAppender doesn’t only
> >> work with the ThreadContext. It works using a lookup. So if you were to
> use
> >> a ThreadLookup that used ${{thread:id}} you would get a new Appender for
> >> each thread id. To be honest, I am not sure why we haven’t created a
> >> ThreadLookup before. I could easily see multiple places were the thread
> id,
> >> name, priority or ThreadGroup name might want to be used.
> >>
> >> If you want all the threads in a “job” then I would create the parent
> >> thread with its own thread group and use the thread group name in the
> >> lookup.
> >>
> >> Ralph
> >>
> >>> On Apr 23, 2019, at 5:06 PM, Benjamin Jaton 
> >> wrote:
> >>>
> >>> Hello,
> >>>
> >>> Several times I've been in a situation where in a given JVM I am trying
> >> to
> >>> run distinct jobs in separate threads, who themselves might spawn their
> >> own
> >>> threads.
> >>> In those situations I usually want the logging of each job in a
> separate
> >>> log file, and that has proven to be difficult.
> >>>
> >>> Log4j2 has a routing appender that allows to create a separate appender
> >> for
> >>> each job given that you can provide a routing key that's unique for
> each
> >>> job. But what key to use for this?
> >>> I've been using a ThreadContext variable that I set at the level of the
> >> job
> >>> thread, and any child thread that I have control over.
> >>>
> >>> But the problem is that I don't always have control over this.
> Sometimes
> >>> third party APIs let you feed a custom ThreadFactory, sometimes they
> >> don't.
> >>> When they don't, I can't set that ThreadContext variable and part of
> the
> >>> job logging will be misrouted to a different appender.
> >>>
> >>> Is there a way to work around this so that there is 1 log file for each
> >> job
> >>> that would gather all the logging of the sub threads?
> >>>
> >>> Thanks,
> >>> Benjamin
> >>
> >>
> >>
> >> -
> >> 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: How to have a separate log file for a thread and all sub threads?

2019-04-23 Thread Benjamin Jaton
> If you want all the threads in a “job” then I would create the parent
thread with its own thread group and use the thread group name in the
lookup.

But how do I assign the thread group to threads that 3rd party libraries
create? I don't think child threads naturally inherit the ThreadGroup of
their parents.

On Tue, Apr 23, 2019 at 8:36 PM Ralph Goers 
wrote:

> I think the solution is pretty simple. The RoutingAppender doesn’t only
> work with the ThreadContext. It works using a lookup. So if you were to use
> a ThreadLookup that used ${{thread:id}} you would get a new Appender for
> each thread id. To be honest, I am not sure why we haven’t created a
> ThreadLookup before. I could easily see multiple places were the thread id,
> name, priority or ThreadGroup name might want to be used.
>
> If you want all the threads in a “job” then I would create the parent
> thread with its own thread group and use the thread group name in the
> lookup.
>
> Ralph
>
> > On Apr 23, 2019, at 5:06 PM, Benjamin Jaton 
> wrote:
> >
> > Hello,
> >
> > Several times I've been in a situation where in a given JVM I am trying
> to
> > run distinct jobs in separate threads, who themselves might spawn their
> own
> > threads.
> > In those situations I usually want the logging of each job in a separate
> > log file, and that has proven to be difficult.
> >
> > Log4j2 has a routing appender that allows to create a separate appender
> for
> > each job given that you can provide a routing key that's unique for each
> > job. But what key to use for this?
> > I've been using a ThreadContext variable that I set at the level of the
> job
> > thread, and any child thread that I have control over.
> >
> > But the problem is that I don't always have control over this. Sometimes
> > third party APIs let you feed a custom ThreadFactory, sometimes they
> don't.
> > When they don't, I can't set that ThreadContext variable and part of the
> > job logging will be misrouted to a different appender.
> >
> > Is there a way to work around this so that there is 1 log file for each
> job
> > that would gather all the logging of the sub threads?
> >
> > Thanks,
> > Benjamin
>
>
>
> -
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>
>


How to have a separate log file for a thread and all sub threads?

2019-04-23 Thread Benjamin Jaton
Hello,

Several times I've been in a situation where in a given JVM I am trying to
run distinct jobs in separate threads, who themselves might spawn their own
threads.
In those situations I usually want the logging of each job in a separate
log file, and that has proven to be difficult.

Log4j2 has a routing appender that allows to create a separate appender for
each job given that you can provide a routing key that's unique for each
job. But what key to use for this?
I've been using a ThreadContext variable that I set at the level of the job
thread, and any child thread that I have control over.

But the problem is that I don't always have control over this. Sometimes
third party APIs let you feed a custom ThreadFactory, sometimes they don't.
When they don't, I can't set that ThreadContext variable and part of the
job logging will be misrouted to a different appender.

Is there a way to work around this so that there is 1 log file for each job
that would gather all the logging of the sub threads?

Thanks,
Benjamin


BLOCKED jstack on AsyncAppender

2018-05-31 Thread Benjamin Jaton
Hello,

Would anyone have an idea why the AsyncAppender ends up up in a blocked
state given the following stack:

Thread 20497: (state = BLOCKED)
- sun.misc.Unsafe.park(boolean, long) @bci=0 (Compiled frame; information
may be imprecise)
- java.util.concurrent.locks.LockSupport.park(java.lang.Object) @bci=14,
line=175 (Compiled frame)
-
java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt()
@bci=1, line=836 (Compiled frame)
-
java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(java.util.concurrent.locks.AbstractQueuedSynchronizer$Node,
int) @bci=67, line=870 (Compiled frame)
- java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(int)
@bci=17, line=1199 (Compiled frame)
- java.util.concurrent.locks.ReentrantLock$NonfairSync.lock() @bci=21,
line=209 (Compiled frame)
- java.util.concurrent.locks.ReentrantLock.lock() @bci=4, line=285
(Compiled frame)
- java.util.concurrent.ArrayBlockingQueue.offer(java.lang.Object) @bci=10,
line=327 (Compiled frame)
-
org.apache.logging.log4j.core.appender.AsyncAppender.transfer(org.apache.logging.log4j.core.LogEvent)
@bci=31, line=173 (Compiled frame)
-
org.apache.logging.log4j.core.appender.AsyncAppender.append(org.apache.logging.log4j.core.LogEvent)
@bci=71, line=160 (Compiled frame)
-
org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(org.apache.logging.log4j.core.LogEvent)
@bci=5, line=156 (Compiled frame)
-
org.apache.logging.log4j.core.config.AppenderControl.callAppender0(org.apache.logging.log4j.core.LogEvent)
@bci=14, line=129 (Compiled frame)
-
org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(org.apache.logging.log4j.core.LogEvent)
@bci=10, line=120 (Compiled frame)
-
org.apache.logging.log4j.core.config.AppenderControl.callAppender(org.apache.logging.log4j.core.LogEvent)
@bci=11, line=84 (Compiled frame)
-
org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(org.apache.logging.log4j.core.LogEvent)
@bci=20, line=447 (Compiled frame)
-
org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(org.apache.logging.log4j.core.LogEvent)
@bci=12, line=432 (Compiled frame)
-
org.apache.logging.log4j.core.config.LoggerConfig.log(org.apache.logging.log4j.core.LogEvent)
@bci=10, line=416 (Compiled frame)
- org.apache.logging.log4j.core.config.LoggerConfig.log(java.lang.String,
java.lang.String, org.apache.logging.log4j.Marker,
org.apache.logging.log4j.Level, org.apache.logging.log4j.message.Message,
java.lang.Throwable) @bci=198, line=402 (Compiled frame)
-
org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(org.apache.logging.log4j.util.Supplier,
java.lang.String, java.lang.String, org.apache.logging.log4j.Marker,
org.apache.logging.log4j.Level, org.apache.logging.log4j.message.Message,
java.lang.Throwable) @bci=19, line=63 (Compiled frame)
- org.apache.logging.log4j.core.Logger.logMessage(java.lang.String,
org.apache.logging.log4j.Level, org.apache.logging.log4j.Marker,
org.apache.logging.log4j.message.Message, java.lang.Throwable) @bci=47,
line=146 (Compiled frame)
-
org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(java.lang.String,
org.apache.logging.log4j.Level, org.apache.logging.log4j.Marker,
org.apache.logging.log4j.message.Message, java.lang.Throwable) @bci=8,
line=2091 (Compiled frame)
- org.apache.logging.log4j.spi.AbstractLogger.logMessage(java.lang.String,
org.apache.logging.log4j.Level, org.apache.logging.log4j.Marker,
java.lang.String, java.lang.Throwable) @bci=17, line=1988 (Compiled frame)
-
org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(java.lang.String,
org.apache.logging.log4j.Level, org.apache.logging.log4j.Marker,
java.lang.String, java.lang.Throwable) @bci=21, line=1960 (Compiled frame)
- org.apache.logging.log4j.spi.AbstractLogger.info(java.lang.String)
@bci=13, line=1297 (Compiled frame)

Thanks
Benjamin


Re: Log4j2 RollingFileAppender message not in order?

2018-02-21 Thread Benjamin Jaton
Ah thanks for the thoughts /feedback. I was just curious to know what you
would think of such a design for apps that needs to guaranty ordering.
Thanks!

On Tue, Feb 20, 2018 at 2:36 PM, Remko Popma <remko.po...@gmail.com> wrote:

> To come back to our questions, what version of Log4j are you using?
> Are you seeing log entries that are out of order in the same thread?
>
> (Shameless plug) Every java main() method deserves http://picocli.info
>
> > On Feb 21, 2018, at 7:15, Matt Sicker <boa...@gmail.com> wrote:
> >
> > On 20 February 2018 at 11:32, Benjamin Jaton <benjamin.ja...@gmail.com>
> > wrote:
> >
> >> In the case of a multi threaded application, not async, would it be
> >> possible to have avoid the potential mis ordering by having a 500ms (for
> >> example) window of collection for log events, and instead of logging the
> >> next log event in the queue, the logic would be search for the oldest
> event
> >> in the queue and log it.
> >>
> >
> > So like a priority queue/heap, where ordering is determined by log event
> > timestamp? Sounds like that could make a neat appender meta plugin (meta
> > like the routing appender, though perhaps it could be a plugin specific
> to
> > async loggers like a policy/strategy type class), though it may be
> overkill
> > for most scenarios unless log files must absolutely be done in exact
> > timestamp order. Plus, if you're using async logging, this could
> > potentially have a noticeable affect on performance (e.g., we could use
> > BlockingPriorityQueue, though now we cancel out the performance gains of
> > avoiding a blocking queue; or we could use a persistent data structure,
> but
> > then we lose GC-free logging, though chances are that BPQ already causes
> > garbage as it is).
> >
> > The tl;dr of this is that if you're logging synchronously and want events
> > in order, fitting in a PriorityQueue or BlockingPriorityQueue (depending
> on
> > single or multi producer scenarios respectively) would be the general way
> > to go, though it's not ideal for performance probably.
> >
> >
> > --
> > Matt Sicker <boa...@gmail.com>
>
> -
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>
>


Re: Log4j2 RollingFileAppender message not in order?

2018-02-20 Thread Benjamin Jaton
In the case of a multi threaded application, not async, would it be
possible to have avoid the potential mis ordering by having a 500ms (for
example) window of collection for log events, and instead of logging the
next log event in the queue, the logic would be search for the oldest event
in the queue and log it.
I haven't looked for where that happens in the code so maybe this is not
applicable or the performance impact would be too high.


On Thu, Dec 14, 2017 at 3:52 PM, Remko Popma <remko.po...@gmail.com> wrote:

> Best to upgrade to 2.10 if you’re not on it yet.
>
> Cheers!
>
> (Shameless plug) Every java main() method deserves http://picocli.info
>
> > On Dec 15, 2017, at 8:45, Benjamin Jaton <benjamin.ja...@gmail.com>
> wrote:
> >
> > Oh interesting. Well this one appender is not async but it is multi
> > threaded, so I think that explains it.
> > Useful to know about 2031 though.
> >
> > Thanks
> > Benjamin
> >
> >> On Thu, Dec 14, 2017 at 2:54 PM, Remko Popma <remko.po...@gmail.com>
> wrote:
> >>
> >> Are you using Log4j 2.10?
> >> The reason I’m asking is that the 2.10 release contains a fix for
> >> https://issues.apache.org/jira/browse/LOG4J2-2031.
> >>
> >> Prior to 2.10, there was a possibility that log events ended up out of
> >> order in the log when you’re using async loggers or async appender and
> the
> >> appender could not keep up with the logging rate. Once the queue is
> full,
> >> previous versions of Log4j2 would bypass the queue and log directly to
> the
> >> appender.
> >>
> >> From 2.10, this only happens if Log4j2 determines there’s a risk for
> >> deadlock, otherwise the thread will enqueue the log event (possibly
> >> blocking until space is available in the queue).
> >>
> >> Remko
> >>
> >> (Shameless plug) Every java main() method deserves http://picocli.info
> >>
> >>> On Dec 15, 2017, at 7:22, Ralph Goers <ralph.go...@dslextreme.com>
> >> wrote:
> >>>
> >>> In a multi-threaded application it is entirely possible that log
> entries
> >> might be appear to be out of order. This is because the LogEvent will
> >> populate the timestamp field but then another thread might get control,
> >> generate its log event, and then pass it to the appender before the
> first
> >> thread got a chance to pass the event to the appender. Are you seeing
> log
> >> entries that are out of order in the same thread? That shouldn’t happen.
> >>>
> >>> Ralph
> >>>
> >>>> On Dec 14, 2017, at 3:09 PM, Benjamin Jaton <benjamin.ja...@gmail.com
> >
> >> wrote:
> >>>>
> >>>> Hello,
> >>>>
> >>>> I am seeing logs that are not in order in the log file, it this
> expected
> >>>> when using a RollingFile appender?
> >>>>
> >>>> "appenders" : {
> >>>>"appender" : [ {
> >>>>  "type" : "RollingFile",
> >>>>  "name" : "ServerAppender",
> >>>>  "PatternLayout" : {
> >>>>"pattern" : "%d{-MM-dd HH:mm:ss,SSS} %-5p %c{1}:%L - %m%n"
> >>>>  },
> >>>>  "fileName" : "server.log",
> >>>>  "filePattern" : "server-%d{-MM-dd_HH-mm-ss}.log.zip",
> >>>>  "SizeBasedTriggeringPolicy" : {
> >>>>"size" : "100MB"
> >>>>  },
> >>>>  "bufferedIO" : "true",
> >>>>  "bufferSize" : "8192",
> >>>>  "immediateFlush" : "true",
> >>>>  "DefaultRolloverStrategy" : (...)
> >>>>}
> >>>>
> >>>> Thanks
> >>>> Benjamin
> >>>
> >>>
> >>>
> >>> -
> >>> 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: reusing a logger+appender

2018-02-14 Thread Benjamin Jaton
Yes I have been using the composite config feature, it does help.

It would be nice to be able to configure the logging of a component in the
component itself, instead of having to add it in the initial logging
configuration of all the potential applications that might use it.
In particular if some components are loaded dynamically, we might not know
in advance what will be used/necessary.
Also defining appenders "just in case" they might be used is sometimes not
ideal, as some appenders issue connections requests or create resources on
creation.

Benjamin

On Wed, Feb 7, 2018 at 8:53 PM, Ralph Goers <ralph.go...@dslextreme.com>
wrote:

> Are you saying you want to merge a new configuration with the existing
> one? Log4j supports a composite configuration but the files that make up
> the composite have to be known from the beginning.
>
> Ralph
>
> > On Feb 7, 2018, at 6:22 PM, Benjamin Jaton <benjamin.ja...@gmail.com>
> wrote:
> >
> > I am specifically asking about how to feed that conf in the log4j2
> engine,
> > are there methods to enrich the existing log4j2 appenders/loggers?
> >
> > On Wed, Feb 7, 2018 at 4:37 PM, Matt Sicker <boa...@gmail.com> wrote:
> >
> >> You could potentially use JNDI to load and store your configuration if
> >> using Java EE. Otherwise, you could also set the config file name system
> >> property to locate a common config file (at least through the local file
> >> system or class path).
> >>
> >> On Wed, Feb 7, 2018 at 18:01, Benjamin Jaton <benjamin.ja...@gmail.com>
> >> wrote:
> >>
> >>> Hello,
> >>>
> >>> I would like to have a piece of code use Log4J2 to log events in a CSV
> >>> format. So the appender and logger configuration are specific to this
> >> task.
> >>>
> >>> The problem is that there are several JVMs that might invoke this task
> >> (not
> >>> at the same time though). Therefore I would think that each of those
> JVMs
> >>> need to have the same definition of logger+appender in their log4j2
> conf.
> >>>
> >>> Is there a way to load a log4j2 file on demand that would make the
> >>> appenders/loggers in it available? (without breaking the existing ones)
> >>>
> >>> Or maybe you will think of a better way to do this?
> >>>
> >>> Note: I am using JSON to configure log4j2.
> >>>
> >>> Thanks,
> >>> Benjamin
> >>>
> >> --
> >> Matt Sicker <boa...@gmail.com>
> >>
>
>
>
> -
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>
>


reusing a logger+appender

2018-02-07 Thread Benjamin Jaton
Hello,

I would like to have a piece of code use Log4J2 to log events in a CSV
format. So the appender and logger configuration are specific to this task.

The problem is that there are several JVMs that might invoke this task (not
at the same time though). Therefore I would think that each of those JVMs
need to have the same definition of logger+appender in their log4j2 conf.

Is there a way to load a log4j2 file on demand that would make the
appenders/loggers in it available? (without breaking the existing ones)

Or maybe you will think of a better way to do this?

Note: I am using JSON to configure log4j2.

Thanks,
Benjamin


Log4j2 RollingFileAppender message not in order?

2017-12-14 Thread Benjamin Jaton
Hello,

I am seeing logs that are not in order in the log file, it this expected
when using a RollingFile appender?

"appenders" : {
  "appender" : [ {
"type" : "RollingFile",
"name" : "ServerAppender",
"PatternLayout" : {
  "pattern" : "%d{-MM-dd HH:mm:ss,SSS} %-5p %c{1}:%L - %m%n"
},
"fileName" : "server.log",
"filePattern" : "server-%d{-MM-dd_HH-mm-ss}.log.zip",
"SizeBasedTriggeringPolicy" : {
  "size" : "100MB"
},
"bufferedIO" : "true",
"bufferSize" : "8192",
"immediateFlush" : "true",
"DefaultRolloverStrategy" : (...)
  }

Thanks
Benjamin


SMTP appender and TLS

2017-02-21 Thread Benjamin Jaton
Hello,

Is there a way to use TLS when sending emails through the SMTP appender?
https://logging.apache.org/log4j/2.x/manual/appenders.html#SMTPAppender

Thanks
Benjamin


Re: ClassNotFoundException trying to use JDBC appender

2016-11-29 Thread Benjamin Jaton
Would that help?
http://stackoverflow.com/questions/24179375/eclipse-rcp-java-lang-classnotfoundexception-a-runtime
in particular:
Bundle-ClassPath: .,lib/library.jar


On Tue, Nov 29, 2016 at 4:48 PM, Gary Gregory 
wrote:

> OSGi and class loaders make for complications and tricky debugging sessions
> :-(
>
> Gary
>
> On Tue, Nov 29, 2016 at 2:08 PM, Michael Carman <
> michael.j.car...@gmail.com>
> wrote:
>
> > To try to tease out whether my problem is at the Eclipse level or the
> Log4j
> > level I experimented with loading my class via reflection.
> >
> > static {
> > try {
> > Class   clazz  = Class.forName("x.y.z.LogDB");
> > Method method = clazz.getMethod("getConnection");
> > Connection connection = (Connection) method.invoke(clazz);
> > connection.close();
> > } catch (Exception e) {
> > e.printStackTrace();
> > }
> > logger = LogManager.getLogger();
> > }
> >
> > My attempt at reflection is successful. The call to
> LogManager.getLogger()
> > results in a ClassNotFoundException. This implies that my problem is that
> > Log4j isn't picking up on the class path used within my plugin. Is there
> a
> > way to configure that? Searching for "log4j classpath" turns up lots of
> > things about where to put the log4j.properties file.
> >
> > I can't be the first person to try to use a JDBC appender with Eclipse
> RCP.
> >
> > -Mike
> >
> >
> > On Tue, Nov 29, 2016 at 3:27 PM Michael Carman <
> michael.j.car...@gmail.com
> > >
> > wrote:
> >
> > > Yes, getConnection() is static. Log4j isn't getting far enough to
> attempt
> > > calling it, though. An explicit call to LogDB.getConnection()  is
> > > successful but Log4j's attempts to invoke it via reflection fails
> trying
> > to
> > > load the class. That holds true even if I move my LogDB into the
> plug-in
> > > for my application and pre-load it! e.g., in the Activator for my main
> > > plug-in:
> > >
> > > static {
> > > try {
> > > LogDB.getConnection(); // succeeds
> > > } catch (SQLException e) {
> > > e.printStackTrace();
> > > }
> > > LogManager.getLogger(); // throws ClassNotFoundException
> > > }
> > >
> > > It seems like some sort of class path configuration problem, but I
> can't
> > > figure out what to set.
> > >
> > > -Mike
> > >
> > > On Tue, Nov 29, 2016 at 2:43 PM Gary Gregory 
> > > wrote:
> > >
> > > Is your getConnection() method static?
> > >
> > > Gary
> > >
> > > On Tue, Nov 29, 2016 at 9:04 AM, Michael Carman <
> > > michael.j.car...@gmail.com>
> > > wrote:
> > >
> > > > I'm using Log4j2 in an Eclipse RCP application. I've been using a
> > > > RollingFileAppender and am trying to switch to a JDBC appender backed
> > by
> > > a
> > > > ConnectionFactory. I've implemented this using the examples at
> > > > https://logging.apache.org/log4j/2.x/manual/appenders.
> > html#JDBCAppender
> > > as
> > > > a guide but get a ClassNotFoundException at each call to
> > > > LogManager.getLogger(). e.g.
> > > >
> > > > 2016-11-29 10:23:06,233 main ERROR java.lang.ClassNotFoundException:
> > > > x.y.z.LogDB java.lang.ClassNotFoundException: x.y.z.LogDB
> > > > at
> > > > org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(
> > > > BundleLoader.java:506)
> > > > at
> > > > org.eclipse.osgi.internal.loader.BundleLoader.findClass(
> > > > BundleLoader.java:422)
> > > > at
> > > > org.eclipse.osgi.internal.loader.BundleLoader.findClass(
> > > > BundleLoader.java:410)
> > > > at
> > > > org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(
> > > > DefaultClassLoader.java:107)
> > > > at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
> > > > at java.lang.Class.forName0(Native Method)
> > > > at java.lang.Class.forName(Class.java:264)
> > > > at
> > > > org.apache.logging.log4j.util.LoaderUtil.loadClass(
> > LoaderUtil.java:141)
> > > > at
> > > > org.apache.logging.log4j.core.appender.db.jdbc.
> > > > FactoryMethodConnectionSource.createConnectionSource(
> > > > FactoryMethodConnectionSource.java:82)
> > > > ...
> > > >
> > > > My log4j2.xml defines the appender as:
> > > >
> > > > 
> > > >   
> > > >   
> > > >   
> > > >   
> > > >   
> > > >   
> > > >   
> > > >   
> > > >   
> > > > 
> > > >
> > > > I've looked at the obvious things: the name of my factory class
> matches
> > > > between my code and config file, it's declared public, and its
> package
> > is
> > > > exported by the parent plug-in. (The parent plug-in is also required
> by
> > > > other plugins via their manifests.) I can't see why the class loader
> > > > shouldn't be able to find it. I assume there's something simple and
> > > stupid
> > > > that I'm missing.
> > > >
> > > > I'm using Eclipse 3.6.2 (Helios) and Log4j 2.7.
> > > >
> > > > -Mike
> > > >
> > >
> > >
> > >
> > > --
> > > E-Mail: garydgreg...@gmail.com | ggreg...@apache.org
> > > Java Persistence with Hibernate, Second Edition
> > > <
> > > 

Re: Log4j2 script to generate hash

2016-11-10 Thread Benjamin Jaton
I have a weird problem where using a global script seems to cause log4j to
not be able to resolve my properties any more:

Log4j2 2.7

The code:
System.setProperty("log4j.configurationFile",
"/usr/local/apps/test.json");
LogManager.getLogger(Test.class).error("test");

The conf:
{
  "configuration" : {
"status" : "warn",
"scripts": {
  "ScriptFile": { "name":"test.filter", "path": "/tmp/test.groovy" }
},
"properties" : {
  "property" : [ {
"name" : "server.log.level",
"value" : "INFO"
  } ]
},
"appenders" : {
  "appender" : [ {
"type" : "Console",
"name" : "STDOUT",
"PatternLayout" : {
  "pattern" : "%m (Logger log level = ${server.log.level})%n"
}
  } ]
},
"loggers" : {
  "root" : {
"level" : "${server.log.level}",
"AppenderRef" : {
  "ref" : "STDOUT"
}
  }
}
  }
}

The output without the highlighted section:
  test (Logger log level = INFO)

The output with the highlighted section:
  2016-11-10 16:30:25,351 main WARN Error while converting string
[${server.log.level}] to type [class org.apache.logging.log4j.Level]. Using
default value [null].
  test (Logger log level = ${server.log.level})

The script /tmp/test.groovy only contains "return true"

I think I'll open a bug for this if you're ok with it.

Thanks
Ben


On Thu, Nov 10, 2016 at 3:59 PM, Benjamin Jaton <benjamin.ja...@gmail.com>
wrote:

> Ah, indeed, I have access to a variable named "logger", excellent.
>
> Here is the script I am trying to use:
>
> ---
> import java.security.MessageDigest
> import org.apache.logging.log4j.ThreadContext
>
> def genmd5(String s) {
> MessageDigest.getInstance("MD5").digest(s.bytes).
> encodeHex().toString()
> }
>
> ThreadContext.put("md5message", genmd5(message.getFormattedMessage()))
> return true
> ---
>
> Another question: is there a was to put the script in the JSON
> configuration file directly?
> The doc uses XML format with CDATA, but I'm not sure how that would
> translate in JSON.
>
> Thanks!
> Ben
>
> On Thu, Nov 10, 2016 at 3:49 PM, Remko Popma <remko.po...@gmail.com>
> wrote:
>
>> Can you show your script?
>>
>> Looking at the code, the documentation is wrong and the Logger object is
>> bound to variable "logger" instead.
>>
>> Which variables are available depends on which filter method is called.
>> This depends on where the filter is configured. The LogEvent is not
>> available for global filters. "logger" should be available for global
>> filters.
>>
>> https://github.com/apache/logging-log4j2/blob/master/log4j-
>> core/src/main/java/org/apache/logging/log4j/core/filter/ScriptFilter.java
>>
>>
>>
>>
>> Sent from my iPhone
>>
>> > On 11 Nov 2016, at 7:15, Benjamin Jaton <benjamin.ja...@gmail.com>
>> wrote:
>> >
>> > Sure, here it is:
>> >
>> > {
>> >  "configuration" : {
>> >"status" : "warn",
>> >"scripts": {
>> >  "ScriptFile": { "name":"test.filter", "path":
>> > "/usr/local/apps/test.groovy" }
>> >},
>> >"ScriptFilter": {
>> >  "onMatch": "ACCEPT",
>> >  "onMisMatch": "DENY",
>> >  "ScriptRef": { "ref": "test.filter" }
>> >},
>> >"appenders" : {
>> >  "appender" : [ {
>> >"type" : "Console",
>> >"name" : "STDOUT",
>> >"PatternLayout" : {
>> >  "pattern" : "%d{-MM-dd HH:mm:ss} %-5p %c{1.}:%L -
>> > [%X{md5message}] %m%n"
>> >}
>> >  } ]
>> >},
>> >"loggers" : {
>> >  "root" : {
>> >"level" : "INFO",
>> >"additivity" : "false",
>> >"includeLocation" : "true",
>> >"AppenderRef" : {
>> >  "ref" : "STDOUT"
>> >  

Re: Log4j2 script to generate hash

2016-11-10 Thread Benjamin Jaton
Ah, indeed, I have access to a variable named "logger", excellent.

Here is the script I am trying to use:

---
import java.security.MessageDigest
import org.apache.logging.log4j.ThreadContext

def genmd5(String s) {
MessageDigest.getInstance("MD5").digest(s.bytes).encodeHex().toString()
}

ThreadContext.put("md5message", genmd5(message.getFormattedMessage()))
return true
---

Another question: is there a was to put the script in the JSON
configuration file directly?
The doc uses XML format with CDATA, but I'm not sure how that would
translate in JSON.

Thanks!
Ben

On Thu, Nov 10, 2016 at 3:49 PM, Remko Popma <remko.po...@gmail.com> wrote:

> Can you show your script?
>
> Looking at the code, the documentation is wrong and the Logger object is
> bound to variable "logger" instead.
>
> Which variables are available depends on which filter method is called.
> This depends on where the filter is configured. The LogEvent is not
> available for global filters. "logger" should be available for global
> filters.
>
> https://github.com/apache/logging-log4j2/blob/master/
> log4j-core/src/main/java/org/apache/logging/log4j/core/
> filter/ScriptFilter.java
>
>
>
>
> Sent from my iPhone
>
> > On 11 Nov 2016, at 7:15, Benjamin Jaton <benjamin.ja...@gmail.com>
> wrote:
> >
> > Sure, here it is:
> >
> > {
> >  "configuration" : {
> >"status" : "warn",
> >"scripts": {
> >  "ScriptFile": { "name":"test.filter", "path":
> > "/usr/local/apps/test.groovy" }
> >},
> >"ScriptFilter": {
> >  "onMatch": "ACCEPT",
> >  "onMisMatch": "DENY",
> >  "ScriptRef": { "ref": "test.filter" }
> >},
> >"appenders" : {
> >  "appender" : [ {
> >"type" : "Console",
> >"name" : "STDOUT",
> >"PatternLayout" : {
> >  "pattern" : "%d{-MM-dd HH:mm:ss} %-5p %c{1.}:%L -
> > [%X{md5message}] %m%n"
> >}
> >  } ]
> >},
> >"loggers" : {
> >  "root" : {
> >"level" : "INFO",
> >"additivity" : "false",
> >"includeLocation" : "true",
> >"AppenderRef" : {
> >  "ref" : "STDOUT"
> >}
> >  }
> >}
> >  }
> > }
> >
> >> On Thu, Nov 10, 2016 at 9:01 AM, Remko Popma <remko.po...@gmail.com>
> wrote:
> >>
> >> Can you show your configuration?
> >>
> >> Sent from my iPhone
> >>
> >>>> On 11 Nov 2016, at 1:56, Benjamin Jaton <benjamin.ja...@gmail.com>
> >>> wrote:
> >>>
> >>> I tried all the variables in the doc, no luck:
> >>>
> >>> Caused by: groovy.lang.MissingPropertyException: No such property:
> >>> loggerName for class: Script2
> >>>   at
> >>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(
> >> ScriptBytecodeAdapter.java:53)
> >>>   at
> >>> org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(
> >> PogoGetPropertySite.java:52)
> >>>   at
> >>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.
> >> callGroovyObjectGetProperty(AbstractCallSite.java:307)
> >>>   at Script2.run(Script2.groovy:8)
> >>>   at
> >>> org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(
> >> GroovyScriptEngineImpl.java:343)
> >>>   ... 12 more
> >>>
> >>>> On Wed, Nov 9, 2016 at 10:54 PM, Remko Popma <remko.po...@gmail.com>
> >> wrote:
> >>>>
> >>>> According to this https://logging.apache.org/
> >>>> log4j/2.x/manual/filters.html#Script you should be able to use the
> >>>> variable named loggerName in global script filters.
> >>>>
> >>>> Sent from my iPhone
> >>>>
> >>>>>> On 10 Nov 2016, at 4:31, Benjamin Jaton <benjamin.ja...@gmail.com>
> >>>>> wrote:
> >>>>>
> >>>>> Hmm, I'm not sure, I tried to do this in groovy:
> >>>>>
> >>>>> println(args[0])
> >>>>>
> >>>>>

Re: Log4j2 script to generate hash

2016-11-10 Thread Benjamin Jaton
Sure, here it is:

{
  "configuration" : {
"status" : "warn",
"scripts": {
  "ScriptFile": { "name":"test.filter", "path":
"/usr/local/apps/test.groovy" }
},
"ScriptFilter": {
  "onMatch": "ACCEPT",
  "onMisMatch": "DENY",
  "ScriptRef": { "ref": "test.filter" }
},
"appenders" : {
  "appender" : [ {
"type" : "Console",
"name" : "STDOUT",
"PatternLayout" : {
  "pattern" : "%d{-MM-dd HH:mm:ss} %-5p %c{1.}:%L -
[%X{md5message}] %m%n"
}
  } ]
},
"loggers" : {
  "root" : {
"level" : "INFO",
"additivity" : "false",
"includeLocation" : "true",
"AppenderRef" : {
  "ref" : "STDOUT"
}
  }
}
  }
}

On Thu, Nov 10, 2016 at 9:01 AM, Remko Popma <remko.po...@gmail.com> wrote:

> Can you show your configuration?
>
> Sent from my iPhone
>
> > On 11 Nov 2016, at 1:56, Benjamin Jaton <benjamin.ja...@gmail.com>
> wrote:
> >
> > I tried all the variables in the doc, no luck:
> >
> > Caused by: groovy.lang.MissingPropertyException: No such property:
> > loggerName for class: Script2
> >at
> > org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(
> ScriptBytecodeAdapter.java:53)
> >at
> > org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(
> PogoGetPropertySite.java:52)
> >at
> > org.codehaus.groovy.runtime.callsite.AbstractCallSite.
> callGroovyObjectGetProperty(AbstractCallSite.java:307)
> >at Script2.run(Script2.groovy:8)
> >at
> > org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(
> GroovyScriptEngineImpl.java:343)
> >... 12 more
> >
> >> On Wed, Nov 9, 2016 at 10:54 PM, Remko Popma <remko.po...@gmail.com>
> wrote:
> >>
> >> According to this https://logging.apache.org/
> >> log4j/2.x/manual/filters.html#Script you should be able to use the
> >> variable named loggerName in global script filters.
> >>
> >> Sent from my iPhone
> >>
> >>> On 10 Nov 2016, at 4:31, Benjamin Jaton <benjamin.ja...@gmail.com>
> >> wrote:
> >>>
> >>> Hmm, I'm not sure, I tried to do this in groovy:
> >>>
> >>> println(args[0])
> >>>
> >>> But I get:
> >>> Caused by: groovy.lang.MissingPropertyException: No such property:
> args
> >> for
> >>> class: Script2
> >>>   at
> >>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(
> >> ScriptBytecodeAdapter.java:53)
> >>>   at
> >>> org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(
> >> PogoGetPropertySite.java:52)
> >>>   at
> >>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.
> >> callGroovyObjectGetProperty(AbstractCallSite.java:307)
> >>>   at Script2.run(Script2.groovy:8)
> >>>   at
> >>> org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(
> >> GroovyScriptEngineImpl.java:343)
> >>>   ... 12 more
> >>>
> >>> Then I tried:
> >>>
> >>> println(parameters)
> >>>
> >>> But it returns 'null'
> >>>
> >>>> On Tue, Nov 8, 2016 at 5:18 PM, Remko Popma <remko.po...@gmail.com>
> >> wrote:
> >>>>
> >>>> All filter methods have a Logger object as the first parameter. Can
> you
> >>>> use that?
> >>>>
> >>>> Sent from my iPhone
> >>>>
> >>>>> On 9 Nov 2016, at 9:45, Benjamin Jaton <benjamin.ja...@gmail.com>
> >> wrote:
> >>>>>
> >>>>> As far as I know, there is no way for a global filter to know which
> >>>> logger
> >>>>> we're working it for.
> >>>>> Which in my case is not the best since I would compute a hash for all
> >> the
> >>>>> messages of all my loggers, instead of just the one I need them for.
> >>>>>
> >>>>> On Tue, Nov 8, 2016 at 4:30 PM, Benjamin Jaton <
> >> benjamin.ja...@gmail.com
> >>>>>
> >>>>> wrote:
> >>>>>
> >>>&g

Re: Log4j2 script to generate hash

2016-11-10 Thread Benjamin Jaton
I tried all the variables in the doc, no luck:

Caused by: groovy.lang.MissingPropertyException: No such property:
loggerName for class: Script2
at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
at
org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
at Script2.run(Script2.groovy:8)
at
org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:343)
... 12 more

On Wed, Nov 9, 2016 at 10:54 PM, Remko Popma <remko.po...@gmail.com> wrote:

> According to this https://logging.apache.org/
> log4j/2.x/manual/filters.html#Script you should be able to use the
> variable named loggerName in global script filters.
>
> Sent from my iPhone
>
> > On 10 Nov 2016, at 4:31, Benjamin Jaton <benjamin.ja...@gmail.com>
> wrote:
> >
> > Hmm, I'm not sure, I tried to do this in groovy:
> >
> >  println(args[0])
> >
> > But I get:
> > Caused by: groovy.lang.MissingPropertyException: No such property: args
> for
> > class: Script2
> >at
> > org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(
> ScriptBytecodeAdapter.java:53)
> >at
> > org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(
> PogoGetPropertySite.java:52)
> >at
> > org.codehaus.groovy.runtime.callsite.AbstractCallSite.
> callGroovyObjectGetProperty(AbstractCallSite.java:307)
> >at Script2.run(Script2.groovy:8)
> >at
> > org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(
> GroovyScriptEngineImpl.java:343)
> >... 12 more
> >
> > Then I tried:
> >
> >  println(parameters)
> >
> > But it returns 'null'
> >
> >> On Tue, Nov 8, 2016 at 5:18 PM, Remko Popma <remko.po...@gmail.com>
> wrote:
> >>
> >> All filter methods have a Logger object as the first parameter. Can you
> >> use that?
> >>
> >> Sent from my iPhone
> >>
> >>> On 9 Nov 2016, at 9:45, Benjamin Jaton <benjamin.ja...@gmail.com>
> wrote:
> >>>
> >>> As far as I know, there is no way for a global filter to know which
> >> logger
> >>> we're working it for.
> >>> Which in my case is not the best since I would compute a hash for all
> the
> >>> messages of all my loggers, instead of just the one I need them for.
> >>>
> >>> On Tue, Nov 8, 2016 at 4:30 PM, Benjamin Jaton <
> benjamin.ja...@gmail.com
> >>>
> >>> wrote:
> >>>
> >>>> Ah, I can't use 'logEvent' but I can use 'message', perfect, thank
> you!
> >>>>
> >>>>> On Tue, Nov 8, 2016 at 4:21 PM, Remko Popma <remko.po...@gmail.com>
> >> wrote:
> >>>>>
> >>>>> Yes Filters can be applied at different stages of the logging
> pipeline.
> >>>>> The Filter interface has separate methods for these stages. Different
> >>>>> parameters are passed to these methods.
> >>>>>
> >>>>> Sent from my iPhone
> >>>>>
> >>>>>> On 9 Nov 2016, at 8:57, Benjamin Jaton <benjamin.ja...@gmail.com>
> >>>>> wrote:
> >>>>>>
> >>>>>> Ah, interesting. I seem to be able to make modification using this
> >>>>> global
> >>>>>> filter.
> >>>>>>
> >>>>>> However I don't seem to have access to the log event that way?
> >>>>>>
> >>>>>> Caused by: groovy.lang.MissingPropertyException: No such property:
> >>>>> logEvent
> >>>>>> for class: Script2
> >>>>>>  at
> >>>>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(Scr
> >>>>> iptBytecodeAdapter.java:53)
> >>>>>>  at
> >>>>>> org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.get
> >>>>> Property(PogoGetPropertySite.java:52)
> >>>>>>  at
> >>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGr
> >>>>> oovyObjectGetProperty(AbstractCallSite.java:307)
> >>>>>>  at Script2.run(Script2.groovy:8)
> >>>>>>  at
> >>>>>> org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(Groov
> >>>>> yScriptEngineImpl.java:343)

Re: Log4j2 script to generate hash

2016-11-09 Thread Benjamin Jaton
Hmm, I'm not sure, I tried to do this in groovy:

  println(args[0])

But I get:
Caused by: groovy.lang.MissingPropertyException: No such property: args for
class: Script2
at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
at
org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
at Script2.run(Script2.groovy:8)
at
org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:343)
... 12 more

Then I tried:

  println(parameters)

But it returns 'null'

On Tue, Nov 8, 2016 at 5:18 PM, Remko Popma <remko.po...@gmail.com> wrote:

> All filter methods have a Logger object as the first parameter. Can you
> use that?
>
> Sent from my iPhone
>
> > On 9 Nov 2016, at 9:45, Benjamin Jaton <benjamin.ja...@gmail.com> wrote:
> >
> > As far as I know, there is no way for a global filter to know which
> logger
> > we're working it for.
> > Which in my case is not the best since I would compute a hash for all the
> > messages of all my loggers, instead of just the one I need them for.
> >
> > On Tue, Nov 8, 2016 at 4:30 PM, Benjamin Jaton <benjamin.ja...@gmail.com
> >
> > wrote:
> >
> >> Ah, I can't use 'logEvent' but I can use 'message', perfect, thank you!
> >>
> >>> On Tue, Nov 8, 2016 at 4:21 PM, Remko Popma <remko.po...@gmail.com>
> wrote:
> >>>
> >>> Yes Filters can be applied at different stages of the logging pipeline.
> >>> The Filter interface has separate methods for these stages. Different
> >>> parameters are passed to these methods.
> >>>
> >>> Sent from my iPhone
> >>>
> >>>> On 9 Nov 2016, at 8:57, Benjamin Jaton <benjamin.ja...@gmail.com>
> >>> wrote:
> >>>>
> >>>> Ah, interesting. I seem to be able to make modification using this
> >>> global
> >>>> filter.
> >>>>
> >>>> However I don't seem to have access to the log event that way?
> >>>>
> >>>> Caused by: groovy.lang.MissingPropertyException: No such property:
> >>> logEvent
> >>>> for class: Script2
> >>>>   at
> >>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(Scr
> >>> iptBytecodeAdapter.java:53)
> >>>>   at
> >>>> org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.get
> >>> Property(PogoGetPropertySite.java:52)
> >>>>   at
> >>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGr
> >>> oovyObjectGetProperty(AbstractCallSite.java:307)
> >>>>   at Script2.run(Script2.groovy:8)
> >>>>   at
> >>>> org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(Groov
> >>> yScriptEngineImpl.java:343)
> >>>>   ... 12 more
> >>>>
> >>>>> On Tue, Nov 8, 2016 at 3:47 PM, Remko Popma <remko.po...@gmail.com>
> >>> wrote:
> >>>>>
> >>>>> If you make it a global filter it will get applied before the
> LogEvent
> >>> is
> >>>>> constructed. Please try that.
> >>>>>
> >>>>> Remko
> >>>>>
> >>>>> Sent from my iPhone
> >>>>>
> >>>>>> On 9 Nov 2016, at 7:02, Benjamin Jaton <benjamin.ja...@gmail.com>
> >>> wrote:
> >>>>>>
> >>>>>> I am applying it on the root logger.
> >>>>>>
> >>>>>>> On Tue, Nov 8, 2016 at 12:47 PM, Matt Sicker <boa...@gmail.com>
> >>> wrote:
> >>>>>>>
> >>>>>>> Where are you applying the filter? On the appender or somewhere
> else?
> >>>>>>>
> >>>>>>> On 8 November 2016 at 13:13, Benjamin Jaton <
> >>> benjamin.ja...@gmail.com>
> >>>>>>> wrote:
> >>>>>>>
> >>>>>>>> hello,
> >>>>>>>>
> >>>>>>>> I was playing with log4j2 filters to generate a hash in groovy
> that
> >>> I
> >>>>>>> would
> >>>>>>>> put in the threadcontext map, and then use in my log pattern:
> >>>>>>>>
> >>>>>>>> %d{-MM-dd HH:mm:ss} %-5p %c{1.}:%L - %m [%X{myhash}]
> >>>>>>>>
> >>>>>>>> But the hash is printed on the NEXT log message.
> >>>>>>>> My understanding is that at this point the log message is already
> >>>>>>> formatted
> >>>>>>>> and final.
> >>>>>>>>
> >>>>>>>> Is there another way I can use a custom script where the log event
> >>> can
> >>>>>>>> actually be modified?
> >>>>>>>>
> >>>>>>>> Thanks,
> >>>>>>>> Ben
> >>>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> --
> >>>>>>> Matt Sicker <boa...@gmail.com>
> >>>>>>>
> >>>>>
> >>>>> 
> -
> >>>>> 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
> >>>
> >>>
> >>
>
> -
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>
>


Re: Log4j2 script to generate hash

2016-11-08 Thread Benjamin Jaton
As far as I know, there is no way for a global filter to know which logger
we're working it for.
Which in my case is not the best since I would compute a hash for all the
messages of all my loggers, instead of just the one I need them for.

On Tue, Nov 8, 2016 at 4:30 PM, Benjamin Jaton <benjamin.ja...@gmail.com>
wrote:

> Ah, I can't use 'logEvent' but I can use 'message', perfect, thank you!
>
> On Tue, Nov 8, 2016 at 4:21 PM, Remko Popma <remko.po...@gmail.com> wrote:
>
>> Yes Filters can be applied at different stages of the logging pipeline.
>> The Filter interface has separate methods for these stages. Different
>> parameters are passed to these methods.
>>
>> Sent from my iPhone
>>
>> > On 9 Nov 2016, at 8:57, Benjamin Jaton <benjamin.ja...@gmail.com>
>> wrote:
>> >
>> > Ah, interesting. I seem to be able to make modification using this
>> global
>> > filter.
>> >
>> > However I don't seem to have access to the log event that way?
>> >
>> > Caused by: groovy.lang.MissingPropertyException: No such property:
>> logEvent
>> > for class: Script2
>> >at
>> > org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(Scr
>> iptBytecodeAdapter.java:53)
>> >at
>> > org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.get
>> Property(PogoGetPropertySite.java:52)
>> >at
>> > org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGr
>> oovyObjectGetProperty(AbstractCallSite.java:307)
>> >at Script2.run(Script2.groovy:8)
>> >at
>> > org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(Groov
>> yScriptEngineImpl.java:343)
>> >... 12 more
>> >
>> >> On Tue, Nov 8, 2016 at 3:47 PM, Remko Popma <remko.po...@gmail.com>
>> wrote:
>> >>
>> >> If you make it a global filter it will get applied before the LogEvent
>> is
>> >> constructed. Please try that.
>> >>
>> >> Remko
>> >>
>> >> Sent from my iPhone
>> >>
>> >>> On 9 Nov 2016, at 7:02, Benjamin Jaton <benjamin.ja...@gmail.com>
>> wrote:
>> >>>
>> >>> I am applying it on the root logger.
>> >>>
>> >>>> On Tue, Nov 8, 2016 at 12:47 PM, Matt Sicker <boa...@gmail.com>
>> wrote:
>> >>>>
>> >>>> Where are you applying the filter? On the appender or somewhere else?
>> >>>>
>> >>>> On 8 November 2016 at 13:13, Benjamin Jaton <
>> benjamin.ja...@gmail.com>
>> >>>> wrote:
>> >>>>
>> >>>>> hello,
>> >>>>>
>> >>>>> I was playing with log4j2 filters to generate a hash in groovy that
>> I
>> >>>> would
>> >>>>> put in the threadcontext map, and then use in my log pattern:
>> >>>>>
>> >>>>> %d{-MM-dd HH:mm:ss} %-5p %c{1.}:%L - %m [%X{myhash}]
>> >>>>>
>> >>>>> But the hash is printed on the NEXT log message.
>> >>>>> My understanding is that at this point the log message is already
>> >>>> formatted
>> >>>>> and final.
>> >>>>>
>> >>>>> Is there another way I can use a custom script where the log event
>> can
>> >>>>> actually be modified?
>> >>>>>
>> >>>>> Thanks,
>> >>>>> Ben
>> >>>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>> --
>> >>>> Matt Sicker <boa...@gmail.com>
>> >>>>
>> >>
>> >> -
>> >> 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: Log4j2 script to generate hash

2016-11-08 Thread Benjamin Jaton
Ah, I can't use 'logEvent' but I can use 'message', perfect, thank you!

On Tue, Nov 8, 2016 at 4:21 PM, Remko Popma <remko.po...@gmail.com> wrote:

> Yes Filters can be applied at different stages of the logging pipeline.
> The Filter interface has separate methods for these stages. Different
> parameters are passed to these methods.
>
> Sent from my iPhone
>
> > On 9 Nov 2016, at 8:57, Benjamin Jaton <benjamin.ja...@gmail.com> wrote:
> >
> > Ah, interesting. I seem to be able to make modification using this global
> > filter.
> >
> > However I don't seem to have access to the log event that way?
> >
> > Caused by: groovy.lang.MissingPropertyException: No such property:
> logEvent
> > for class: Script2
> >at
> > org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(
> ScriptBytecodeAdapter.java:53)
> >at
> > org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(
> PogoGetPropertySite.java:52)
> >at
> > org.codehaus.groovy.runtime.callsite.AbstractCallSite.
> callGroovyObjectGetProperty(AbstractCallSite.java:307)
> >at Script2.run(Script2.groovy:8)
> >at
> > org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(
> GroovyScriptEngineImpl.java:343)
> >... 12 more
> >
> >> On Tue, Nov 8, 2016 at 3:47 PM, Remko Popma <remko.po...@gmail.com>
> wrote:
> >>
> >> If you make it a global filter it will get applied before the LogEvent
> is
> >> constructed. Please try that.
> >>
> >> Remko
> >>
> >> Sent from my iPhone
> >>
> >>> On 9 Nov 2016, at 7:02, Benjamin Jaton <benjamin.ja...@gmail.com>
> wrote:
> >>>
> >>> I am applying it on the root logger.
> >>>
> >>>> On Tue, Nov 8, 2016 at 12:47 PM, Matt Sicker <boa...@gmail.com>
> wrote:
> >>>>
> >>>> Where are you applying the filter? On the appender or somewhere else?
> >>>>
> >>>> On 8 November 2016 at 13:13, Benjamin Jaton <benjamin.ja...@gmail.com
> >
> >>>> wrote:
> >>>>
> >>>>> hello,
> >>>>>
> >>>>> I was playing with log4j2 filters to generate a hash in groovy that I
> >>>> would
> >>>>> put in the threadcontext map, and then use in my log pattern:
> >>>>>
> >>>>> %d{-MM-dd HH:mm:ss} %-5p %c{1.}:%L - %m [%X{myhash}]
> >>>>>
> >>>>> But the hash is printed on the NEXT log message.
> >>>>> My understanding is that at this point the log message is already
> >>>> formatted
> >>>>> and final.
> >>>>>
> >>>>> Is there another way I can use a custom script where the log event
> can
> >>>>> actually be modified?
> >>>>>
> >>>>> Thanks,
> >>>>> Ben
> >>>>>
> >>>>
> >>>>
> >>>>
> >>>> --
> >>>> Matt Sicker <boa...@gmail.com>
> >>>>
> >>
> >> -
> >> 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: Log4j2 script to generate hash

2016-11-08 Thread Benjamin Jaton
Ah, interesting. I seem to be able to make modification using this global
filter.

However I don't seem to have access to the log event that way?

Caused by: groovy.lang.MissingPropertyException: No such property: logEvent
for class: Script2
at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
at
org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
at Script2.run(Script2.groovy:8)
at
org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:343)
... 12 more

On Tue, Nov 8, 2016 at 3:47 PM, Remko Popma <remko.po...@gmail.com> wrote:

> If you make it a global filter it will get applied before the LogEvent is
> constructed. Please try that.
>
> Remko
>
> Sent from my iPhone
>
> > On 9 Nov 2016, at 7:02, Benjamin Jaton <benjamin.ja...@gmail.com> wrote:
> >
> > I am applying it on the root logger.
> >
> >> On Tue, Nov 8, 2016 at 12:47 PM, Matt Sicker <boa...@gmail.com> wrote:
> >>
> >> Where are you applying the filter? On the appender or somewhere else?
> >>
> >> On 8 November 2016 at 13:13, Benjamin Jaton <benjamin.ja...@gmail.com>
> >> wrote:
> >>
> >>> hello,
> >>>
> >>> I was playing with log4j2 filters to generate a hash in groovy that I
> >> would
> >>> put in the threadcontext map, and then use in my log pattern:
> >>>
> >>> %d{-MM-dd HH:mm:ss} %-5p %c{1.}:%L - %m [%X{myhash}]
> >>>
> >>> But the hash is printed on the NEXT log message.
> >>> My understanding is that at this point the log message is already
> >> formatted
> >>> and final.
> >>>
> >>> Is there another way I can use a custom script where the log event can
> >>> actually be modified?
> >>>
> >>> Thanks,
> >>> Ben
> >>>
> >>
> >>
> >>
> >> --
> >> Matt Sicker <boa...@gmail.com>
> >>
>
> -
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>
>


Re: Log4j2 script to generate hash

2016-11-08 Thread Benjamin Jaton
I am applying it on the root logger.

On Tue, Nov 8, 2016 at 12:47 PM, Matt Sicker <boa...@gmail.com> wrote:

> Where are you applying the filter? On the appender or somewhere else?
>
> On 8 November 2016 at 13:13, Benjamin Jaton <benjamin.ja...@gmail.com>
> wrote:
>
> > hello,
> >
> > I was playing with log4j2 filters to generate a hash in groovy that I
> would
> > put in the threadcontext map, and then use in my log pattern:
> >
> > %d{-MM-dd HH:mm:ss} %-5p %c{1.}:%L - %m [%X{myhash}]
> >
> > But the hash is printed on the NEXT log message.
> > My understanding is that at this point the log message is already
> formatted
> > and final.
> >
> > Is there another way I can use a custom script where the log event can
> > actually be modified?
> >
> > Thanks,
> > Ben
> >
>
>
>
> --
> Matt Sicker <boa...@gmail.com>
>


Log4j2 script to generate hash

2016-11-08 Thread Benjamin Jaton
hello,

I was playing with log4j2 filters to generate a hash in groovy that I would
put in the threadcontext map, and then use in my log pattern:

%d{-MM-dd HH:mm:ss} %-5p %c{1.}:%L - %m [%X{myhash}]

But the hash is printed on the NEXT log message.
My understanding is that at this point the log message is already formatted
and final.

Is there another way I can use a custom script where the log event can
actually be modified?

Thanks,
Ben


DefaultRolloverStrategy max attribute and IfAccumulatedFileCount

2016-10-18 Thread Benjamin Jaton
Hello,

I wonder about the relationship between the max attribute and the
IfAccumulatedFileCount.

I had wrongly assumed that if you used the Delete policy, then the max
attribute wasn't needed.
But that resulted in having a cap on the number of log files to 7 (which is
the DEFAULT_WINDOW_SIZE in DefaultRolloverStrategy)

In this example:
https://logging.apache.org/log4j/2.x/manual/appenders.html#DefaultRolloverStrategy

  

  

  


  

  

  

max is cleverly set to 100, when IfAccumulatedFileCount is set to 10.

Could we reasonably assume that max is not very useful here?

I'm thinking about setting it to the same value, or just setting max to a
very high value (100).

Thoughts?


DefaultRolloverStrategy.createStrategy - access the appender

2016-10-07 Thread Benjamin Jaton
Hello,

When configuring the rollover strategy for an appender, is there a way to
access the name of the appender from this method:
DefaultRolloverStrategy.createStrategy ?

I'm trying to write my own and I could use that name for my implementation.

Thanks,
Benjamin


Re: Sharing common log4j2 configuration

2016-06-29 Thread Benjamin Jaton
That is great!
I had to update my custom ConfigurationFactory to create those
CompositeConfiguration but once I did it seems to work well, thanks!

On Wed, Jun 29, 2016 at 4:01 PM, Ralph Goers <ralph.go...@dslextreme.com>
wrote:

> Log4j 2.6.1 supports composite configurations.  See
> http://logging.apache.org/log4j/2.x/manual/configuration.html#CompositeConfiguration
> .
>
> Ralph
>
> > On Jun 29, 2016, at 3:00 PM, Benjamin Jaton <benjamin.ja...@gmail.com>
> wrote:
> >
> > Hello again,
> >
> > Is there a way to define a set appenders/logger/props and use them in
> > several log4j2 configuration files?
> >
> > Like:
> > I define sub-conf C
> > Then I create conf A that "imports" C,
> > and conf B that "imports" C as well.
> >
> > I know about x:include (https://issues.apache.org/jira/browse/LOG4J2-341
> ),
> > I was wondering if there were anything like it for JSON?
> >
> > If not, would that be something that can be done programmatically?
> >
> > Thanks,
> > Ben
>
>
>
> -
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>
>


Sharing common log4j2 configuration

2016-06-29 Thread Benjamin Jaton
Hello again,

Is there a way to define a set appenders/logger/props and use them in
several log4j2 configuration files?

Like:
I define sub-conf C
Then I create conf A that "imports" C,
and conf B that "imports" C as well.

I know about x:include (https://issues.apache.org/jira/browse/LOG4J2-341),
I was wondering if there were anything like it for JSON?

If not, would that be something that can be done programmatically?

Thanks,
Ben


Re: Reloading appender after property value changes

2016-06-28 Thread Benjamin Jaton
Alright, thanks for you feedback.

Here is the JIRA: https://issues.apache.org/jira/browse/LOG4J2-1450

On Tue, Jun 28, 2016 at 3:41 PM, Remko Popma <remko.po...@gmail.com> wrote:

> I see. With current log4j, you'd need to reload the config then.
>
> I wouldn't like to implement reloading just one appender (but perhaps
> others think differently).
>
> Without looking at the code, supporting dynamically evaluation of double
> $'s in SmtpAppender seems like a good approach. Can you raise a Jira
> feature request for that?
>
> Sent from my iPhone
>
> > On 2016/06/29, at 1:33, Benjamin Jaton <benjamin.ja...@gmail.com> wrote:
> >
> > Ah I forgot about this trick.
> >
> > It doesn't seem to be supported by the SMTPAppender:
> >
> >
> ---
> > 2016-06-28 09:30:06,562 main ERROR SmtpManager
> > SMTP:5bea43473970a15b1a4dbd9dcce1c4f6 caught exception while sending
> e-mail
> > notification.: javax.mail.SendFailedException: Invalid Addresses;
> >  nested exception is:
> >com.sun.mail.smtp.SMTPAddressFailedException: 553-5.1.2 The recipient
> > address <${email.recipient}> is not a valid
> > 553 5.1.2 RFC-5321 address. t128sm520507pfb.14 - gsmtp
> > javax.mail.SendFailedException: Invalid Addresses;
> >  nested exception is:
> >com.sun.mail.smtp.SMTPAddressFailedException: 553-5.1.2 *The recipient
> > address <${email.recipient}> is not a valid*
> > 553 5.1.2 RFC-5321 address. t128sm520507pfb.14 - gsmtp
> >
> >at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1996)
> >at
> com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1240)
> >at javax.mail.Transport.send0(Transport.java:255)
> >at javax.mail.Transport.send(Transport.java:124)
> >at
> >
> org.apache.logging.log4j.core.net.SmtpManager.sendMultipartMessage(SmtpManager.java:257)
> >at
> >
> org.apache.logging.log4j.core.net.SmtpManager.sendEvents(SmtpManager.java:172)
> >at
> >
> org.apache.logging.log4j.core.appender.SmtpAppender.append(SmtpAppender.java:177)
> >at
> >
> org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:155)
> >at
> >
> org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:128)
> >at
> >
> org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:119)
> >at
> >
> org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
> >at
> >
> org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:390)
> >at
> >
> org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:375)
> >at
> >
> org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:359)
> >at
> >
> org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:349)
> >at
> >
> org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:63)
> >at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:146)
> >at
> >
> org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2002)
> >at
> >
> org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1974)
> >at
> >
> org.apache.logging.log4j.spi.AbstractLogger.error(AbstractLogger.java:738)
> >at Test.main(Test.java:19)
> > Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 553-5.1.2 The
> > recipient address <${email.recipient}> is not a valid
> > 553 5.1.2 RFC-5321 address. t128sm520507pfb.14 - gsmtp
> >
> >at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1849)
> >... 20 more
> >
> ---
> >
> >
> > Or when I try it with the port:
> >
> >
> ---
> > 2016-06-28 09:29:03,268 main ERROR *Could not parse "${email.smtp.port}"
> *as
> > an integer,  using default value 0: java.lang.NumberFormatException: For
> > input string: "${email.smtp.port}"
> >
> ---
> >
> >
> >
> > Thanks
> > Ben
> >
> >
> >> On Mon, Jun 27, 2016 at 3:36 PM, Remko Popma <remko.po...@gmail.com>
> wrote:
&g

Re: Reloading appender after property value changes

2016-06-28 Thread Benjamin Jaton
Ah I forgot about this trick.

It doesn't seem to be supported by the SMTPAppender:

---
2016-06-28 09:30:06,562 main ERROR SmtpManager
SMTP:5bea43473970a15b1a4dbd9dcce1c4f6 caught exception while sending e-mail
notification.: javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 553-5.1.2 The recipient
address <${email.recipient}> is not a valid
553 5.1.2 RFC-5321 address. t128sm520507pfb.14 - gsmtp
 javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 553-5.1.2 *The recipient
address <${email.recipient}> is not a valid*
553 5.1.2 RFC-5321 address. t128sm520507pfb.14 - gsmtp

at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1996)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1240)
at javax.mail.Transport.send0(Transport.java:255)
at javax.mail.Transport.send(Transport.java:124)
at
org.apache.logging.log4j.core.net.SmtpManager.sendMultipartMessage(SmtpManager.java:257)
at
org.apache.logging.log4j.core.net.SmtpManager.sendEvents(SmtpManager.java:172)
at
org.apache.logging.log4j.core.appender.SmtpAppender.append(SmtpAppender.java:177)
at
org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:155)
at
org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:128)
at
org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:119)
at
org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
at
org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:390)
at
org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:375)
at
org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:359)
at
org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:349)
at
org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:63)
at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:146)
at
org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2002)
at
org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1974)
at
org.apache.logging.log4j.spi.AbstractLogger.error(AbstractLogger.java:738)
at Test.main(Test.java:19)
Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 553-5.1.2 The
recipient address <${email.recipient}> is not a valid
553 5.1.2 RFC-5321 address. t128sm520507pfb.14 - gsmtp

at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1849)
... 20 more
---


Or when I try it with the port:

---
2016-06-28 09:29:03,268 main ERROR *Could not parse "${email.smtp.port}" *as
an integer,  using default value 0: java.lang.NumberFormatException: For
input string: "${email.smtp.port}"
---



Thanks
Ben


On Mon, Jun 27, 2016 at 3:36 PM, Remko Popma <remko.po...@gmail.com> wrote:

> Have you tried configuring with two leading '$' characters?
>
> http://logging.apache.org/log4j/2.x/manual/configuration.html#RuntimeLookup
>
>
> Sent from my iPhone
>
> > On 2016/06/28, at 3:17, Benjamin Jaton <benjamin.ja...@gmail.com> wrote:
> >
> > Hello,
> >
> > I have a simple appender like:
> >
> > {
> >"type" : "smtp",
> >"name" : "EmailAppender",
> >"subject" : "${email.subject}",
> >"to" : "${email.recipient}",
> >"from" : "${email.from}",
> >"smtpProtocol" : "${email.smtp.protocol}",
> >"smtpHost" : "${email.smtp.host}",
> >"smtpPort" : "${email.smtp.port}",
> >"smtpUsername" : "${email.smtp.username}",
> >"smtpPassword" : "${email.smtp.password}"
> > }
> >
> > When I have a updated value for one of those property (for example
> > ${email.subject} has changed, what's the simplest way to reload the
> > appender so that it takes that new value?
> > Do we have to force a full reconfiguration?
> >
> > Thanks
> > Ben
>
> -
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>
>


Re: Reloading appender after property value changes

2016-06-27 Thread Benjamin Jaton
I am using a custom LookUp class that implements StrLookup:

{
  "configuration" : {
"packages" : "my.custom.logging.plugins",

So the monitoringInterval won't detect any change of property that's fed in
there.

I wonder if it's possible to reload just an appender and not the whole
configuration?

On Mon, Jun 27, 2016 at 11:23 AM, Matt Sicker <boa...@gmail.com> wrote:

> I know one simple way would be to use the monitorInterval attribute on
> Configuration and then touching the file to change its last modified time.
> There might be a better solution, though. You can programmatically cause a
> reconfiguration as well.
>
> On 27 June 2016 at 13:17, Benjamin Jaton <benjamin.ja...@gmail.com> wrote:
>
> > Hello,
> >
> > I have a simple appender like:
> >
> > {
> > "type" : "smtp",
> > "name" : "EmailAppender",
> > "subject" : "${email.subject}",
> > "to" : "${email.recipient}",
> > "from" : "${email.from}",
> > "smtpProtocol" : "${email.smtp.protocol}",
> > "smtpHost" : "${email.smtp.host}",
> > "smtpPort" : "${email.smtp.port}",
> > "smtpUsername" : "${email.smtp.username}",
> > "smtpPassword" : "${email.smtp.password}"
> > }
> >
> > When I have a updated value for one of those property (for example
> > ${email.subject} has changed, what's the simplest way to reload the
> > appender so that it takes that new value?
> > Do we have to force a full reconfiguration?
> >
> > Thanks
> > Ben
> >
>
>
>
> --
> Matt Sicker <boa...@gmail.com>
>


Reloading appender after property value changes

2016-06-27 Thread Benjamin Jaton
Hello,

I have a simple appender like:

{
"type" : "smtp",
"name" : "EmailAppender",
"subject" : "${email.subject}",
"to" : "${email.recipient}",
"from" : "${email.from}",
"smtpProtocol" : "${email.smtp.protocol}",
"smtpHost" : "${email.smtp.host}",
"smtpPort" : "${email.smtp.port}",
"smtpUsername" : "${email.smtp.username}",
"smtpPassword" : "${email.smtp.password}"
}

When I have a updated value for one of those property (for example
${email.subject} has changed, what's the simplest way to reload the
appender so that it takes that new value?
Do we have to force a full reconfiguration?

Thanks
Ben


Re: Log4j2 ThreadContext for child threads

2016-04-27 Thread Benjamin Jaton
That's awesome!
I didn't know about
http://docs.oracle.com/javase/6/docs/api/java/lang/InheritableThreadLocal.html

Thanks Remko

On Tue, Apr 26, 2016 at 5:12 PM, Remko Popma <remko.po...@gmail.com> wrote:

> There you go! It's documented near the bottom of the manual page:
>
> http://logging.apache.org/log4j/2.x/manual/thread-context.html
>
>
> Sent from my iPhone
>
> > On 2016/04/27, at 8:58, Benjamin Jaton <benjamin.ja...@gmail.com> wrote:
> >
> > Hi all,
> >
> > I am using the ThreadContext a lot, but I am sometimes in a situation
> where
> > I would need to set some variable for a task that runs in a thread that
> > might spawn children threads. I need that logging variable to be also
> > available to those child threads.
> >
> > Unless I create the sub threads manually and pass the variable myself,
> it's
> > not possible for a thread to know where it comes from and grab the
> variable
> > from its ancestors right?
> >
> > Just asking because maybe someone has run into the same problem.
> >
> > Thanks!
> > Ben
>
> -
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>
>


Log4j2 ThreadContext for child threads

2016-04-26 Thread Benjamin Jaton
Hi all,

I am using the ThreadContext a lot, but I am sometimes in a situation where
I would need to set some variable for a task that runs in a thread that
might spawn children threads. I need that logging variable to be also
available to those child threads.

Unless I create the sub threads manually and pass the variable myself, it's
not possible for a thread to know where it comes from and grab the variable
from its ancestors right?

Just asking because maybe someone has run into the same problem.

Thanks!
Ben


Re: RollingFileAppender maxDelayMillis?

2015-11-11 Thread Benjamin Jaton
Thanks a lot for the explanation, much clearer now.

Here is the JIRA: https://issues.apache.org/jira/browse/LOG4J2-1197

On Tue, Nov 10, 2015 at 11:39 PM, Remko Popma <remko.po...@gmail.com> wrote:

> On Wed, Nov 11, 2015 at 2:34 PM, Benjamin Jaton <benjamin.ja...@gmail.com>
> wrote:
>
> > On Tue, Nov 10, 2015 at 6:13 PM, Remko Popma <remko.po...@gmail.com>
> > wrote:
> >
> > > To check my understanding: the problem is that with bufferedIO=true the
> > > buffer contains log events that you want to see, but the buffer is only
> > > flushed to disk when it is full (which is not frequent enough); is that
> > > correct?
> > >
> >
> > Yes that is correct.
> > Typical scenario is when the server is not in production, so almost no
> > traffic except for the request manually triggered by the operator,
> usually
> > in order to debug something.
> >
> >
> > > If you use AsyncAppender or Async Loggers, the buffer will be flushed
> > when
> > > the queue is empty. This results in efficient IO (lumping together IO
> > > operations where possible), but at the same time your log file always
> > > reflects the most recent message.
> > >
> >
> > So I have a dumb question. What's the difference between bufferedIO and
> > AsyncAppender?
> > Isn't bufferedIO a kind of asynchronous treatment of the log messages?
> I'm
> > sorry I'm a bit confused.
> >
>
> No problem at all. BufferedIO is not asynchronous. The difference between
> bufferedIO and Async Appenders/Loggers is that the async stuff deals with a
> queue of log event objects and happens further upstream, where bufferedIO
> deals with a byte[] array buffer and happens further downstream.
>
> When you use Async Appenders/Loggers, each time your application logs
> something a Log Event object is added to a queue. A background thread takes
> these events off the queue, asks the Layout to turn the event into a byte[]
> array and uses the Appender to send these bytes to their destination.
>
> Without Async Appenders/Loggers, there is no queue, and this work happens
> in your application thread (the Layout turns the event into a byte[] array
> and the Appender sends these bytes to their destination).
>
> When the configuration has bufferedIO="true", the Appender will save up the
> byte[] arrays for multiple log events together in an in-memory buffer first
> instead of writing each byte[] array to its destination immediately,
> to reduce the number of expensive I/O operations. As you noticed, this
> sometimes results in data sitting in this in-memory buffer for a long time.
>
> Now, with Async Appenders/Loggers, we can use what Martin Thompson calls
> "smart
> batching
> <http://mechanical-sympathy.blogspot.jp/2011/10/smart-batching.html>":
> when
> the background thread processes a log event, it checks if the queue is now
> empty (no further log events are in the pipeline to be processed) and if it
> is, it will also call Appender.flush() in addition to the above.
>
>
>
> > >
> > > For synchronous buffered logging, I can see how a smarter flushing
> > > mechanism would be useful.
> > >
> > > Question is, what would trigger the check (whether the buffer needs to
> be
> > > flushed)?
> > >
> > > Easiest is to check with each log event, but if no new event arrives
> you
> > > still end up with a stale buffer. Better than nothing, but not great.
> > >
> > > An alternative is to check periodically from a background thread and
> > flush
> > > if the buffer is non-empty. This probably gives the best results but is
> > > fairly complex to implement.
> > >
> >
> > That was what I had in mind but I don't know the complexity.
> >
> >
> > >
> > > I need to think about this a bit more, but for now I would suggest
> using
> > > async logging. It may be a good idea to create a Jira ticket for this.
> > >
> >
> > OK I will create a Jira for this.
> >
> >
> > >
> > > Remko
> > >
> > > > On 2015/11/11, at 5:16, Gary Gregory <garydgreg...@gmail.com> wrote:
> > > >
> > > > And more generally, can all appenders benefit from such a setting?
> > > >
> > > > Gary
> > > >
> > > > On Tue, Nov 10, 2015 at 11:04 AM, Benjamin Jaton <
> > > benjamin.ja...@gmail.com>
> > > > wrote:
> > > >
> > > >> Hi,
> > > >>
> > > >> I am wondering 

Re: Log4j2 - HTML emails pattern

2015-11-10 Thread Benjamin Jaton
I am trying to use a logger in order to send "alerts" to the user. So for
me 1 log = 1 email (hence LOG4J2-1071).
I use the regular PatternLayout to produce a simple but full HTML page with
my alert email template.

For the HTMLLayout to be usable, it would have to allow to customize the
pattern, header and footer.
Bonus points if we could use the MDC in the email subject.

Ben

On Mon, Nov 9, 2015 at 11:48 AM, Gary Gregory <garydgreg...@gmail.com>
wrote:

> Ben,
>
> Is there a way the current HTML layout could be customized to be better
> suited to your use-case?
>
> Gary
>
> On Mon, Nov 9, 2015 at 11:09 AM, Benjamin Jaton <benjamin.ja...@gmail.com>
> wrote:
>
> > Thanks the feedback.
> > I found that the easiest way to achieve this was to have the
> PatternLayout
> > class support to set the contentType to "text/html".
> > Then one can write HTML directly in the pattern.
> >
> > Thanks again,
> > Ben
> >
> > On Mon, Nov 9, 2015 at 6:51 AM, Remko Popma <remko.po...@gmail.com>
> wrote:
> >
> > > Ben,
> > >
> > > The built-in HTML layout (
> > >
> >
> https://logging.apache.org/log4j/2.x/log4j-core/xref/org/apache/logging/log4j/core/layout/HtmlLayout.html
> > )
> > > does not support much customization.
> > >
> > > It sounds like you may want to create a custom layout and specify that
> > > layout with the SMTP appender.
> > >
> > > This manual page may be a good place to get started:
> > > http://logging.apache.org/log4j/2.x/manual/extending.html#Layouts
> > >
> > > Best regards,
> > > Remko
> > >
> > > > On 2015/11/06, at 4:55, Benjamin Jaton <benjamin.ja...@gmail.com>
> > wrote:
> > > >
> > > > Hi,
> > > >
> > > > I am using the SMTPAppender with a custom pattern:
> > > >  "PatternLayout" : { "pattern" : "%m" }
> > > >
> > > > But the email is sent as text.
> > > >
> > > > I saw that there is a HTMLLayout but it doesn't seem to accept a
> > pattern?
> > > >
> > > > How can I produce a custom HTML message?
> > > >
> > > > Thanks!
> > > > Ben
> > >
> >
>
>
>
> --
> E-Mail: garydgreg...@gmail.com | ggreg...@apache.org
> 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
>


RollingFileAppender maxDelayMillis?

2015-11-10 Thread Benjamin Jaton
Hi,

I am wondering if it would make sense to have a maxDelayMillis parameter
for the RollingFileAppender (like FlumeAppender).

Use case:
You have a web server access log, you produce an HTTP request and expect to
see it (and the response) in the access logs right away-ish (or at least
control how much you have to wait).

Thoughts?
Ben


Re: RollingFileAppender maxDelayMillis?

2015-11-10 Thread Benjamin Jaton
On Tue, Nov 10, 2015 at 6:13 PM, Remko Popma <remko.po...@gmail.com> wrote:

> To check my understanding: the problem is that with bufferedIO=true the
> buffer contains log events that you want to see, but the buffer is only
> flushed to disk when it is full (which is not frequent enough); is that
> correct?
>

Yes that is correct.
Typical scenario is when the server is not in production, so almost no
traffic except for the request manually triggered by the operator, usually
in order to debug something.


> If you use AsyncAppender or Async Loggers, the buffer will be flushed when
> the queue is empty. This results in efficient IO (lumping together IO
> operations where possible), but at the same time your log file always
> reflects the most recent message.
>

So I have a dumb question. What's the difference between bufferedIO and
AsyncAppender?
Isn't bufferedIO a kind of asynchronous treatment of the log messages? I'm
sorry I'm a bit confused.


>
> For synchronous buffered logging, I can see how a smarter flushing
> mechanism would be useful.
>
> Question is, what would trigger the check (whether the buffer needs to be
> flushed)?
>
> Easiest is to check with each log event, but if no new event arrives you
> still end up with a stale buffer. Better than nothing, but not great.
>
> An alternative is to check periodically from a background thread and flush
> if the buffer is non-empty. This probably gives the best results but is
> fairly complex to implement.
>

That was what I had in mind but I don't know the complexity.


>
> I need to think about this a bit more, but for now I would suggest using
> async logging. It may be a good idea to create a Jira ticket for this.
>

OK I will create a Jira for this.


>
> Remko
>
> > On 2015/11/11, at 5:16, Gary Gregory <garydgreg...@gmail.com> wrote:
> >
> > And more generally, can all appenders benefit from such a setting?
> >
> > Gary
> >
> > On Tue, Nov 10, 2015 at 11:04 AM, Benjamin Jaton <
> benjamin.ja...@gmail.com>
> > wrote:
> >
> >> Hi,
> >>
> >> I am wondering if it would make sense to have a maxDelayMillis parameter
> >> for the RollingFileAppender (like FlumeAppender).
> >>
> >> Use case:
> >> You have a web server access log, you produce an HTTP request and
> expect to
> >> see it (and the response) in the access logs right away-ish (or at least
> >> control how much you have to wait).
> >>
> >> Thoughts?
> >> Ben
> >>
> >
> >
> >
> > --
> > E-Mail: garydgreg...@gmail.com | ggreg...@apache.org
> > 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: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>
>


Re: Log4j2 - HTML emails pattern

2015-11-10 Thread Benjamin Jaton
You mean just put HTML in the pattern directly?
You need to content type of the email to be set to text/html, other you
would just see the HTML code in the email.

On Tue, Nov 10, 2015 at 9:21 PM, Matt Sicker <boa...@gmail.com> wrote:

> It seems abusive, but couldn't you just use the PatternLayout and
> interweave HTML?


> On 10 November 2015 at 11:57, Benjamin Jaton <benjamin.ja...@gmail.com>
> wrote:
>
> > I am trying to use a logger in order to send "alerts" to the user. So for
> > me 1 log = 1 email (hence LOG4J2-1071).
> > I use the regular PatternLayout to produce a simple but full HTML page
> with
> > my alert email template.
> >
> > For the HTMLLayout to be usable, it would have to allow to customize the
> > pattern, header and footer.
> > Bonus points if we could use the MDC in the email subject.
> >
> > Ben
> >
> > On Mon, Nov 9, 2015 at 11:48 AM, Gary Gregory <garydgreg...@gmail.com>
> > wrote:
> >
> > > Ben,
> > >
> > > Is there a way the current HTML layout could be customized to be better
> > > suited to your use-case?
> > >
> > > Gary
> > >
> > > On Mon, Nov 9, 2015 at 11:09 AM, Benjamin Jaton <
> > benjamin.ja...@gmail.com>
> > > wrote:
> > >
> > > > Thanks the feedback.
> > > > I found that the easiest way to achieve this was to have the
> > > PatternLayout
> > > > class support to set the contentType to "text/html".
> > > > Then one can write HTML directly in the pattern.
> > > >
> > > > Thanks again,
> > > > Ben
> > > >
> > > > On Mon, Nov 9, 2015 at 6:51 AM, Remko Popma <remko.po...@gmail.com>
> > > wrote:
> > > >
> > > > > Ben,
> > > > >
> > > > > The built-in HTML layout (
> > > > >
> > > >
> > >
> >
> https://logging.apache.org/log4j/2.x/log4j-core/xref/org/apache/logging/log4j/core/layout/HtmlLayout.html
> > > > )
> > > > > does not support much customization.
> > > > >
> > > > > It sounds like you may want to create a custom layout and specify
> > that
> > > > > layout with the SMTP appender.
> > > > >
> > > > > This manual page may be a good place to get started:
> > > > > http://logging.apache.org/log4j/2.x/manual/extending.html#Layouts
> > > > >
> > > > > Best regards,
> > > > > Remko
> > > > >
> > > > > > On 2015/11/06, at 4:55, Benjamin Jaton <benjamin.ja...@gmail.com
> >
> > > > wrote:
> > > > > >
> > > > > > Hi,
> > > > > >
> > > > > > I am using the SMTPAppender with a custom pattern:
> > > > > >  "PatternLayout" : { "pattern" : "%m" }
> > > > > >
> > > > > > But the email is sent as text.
> > > > > >
> > > > > > I saw that there is a HTMLLayout but it doesn't seem to accept a
> > > > pattern?
> > > > > >
> > > > > > How can I produce a custom HTML message?
> > > > > >
> > > > > > Thanks!
> > > > > > Ben
> > > > >
> > > >
> > >
> > >
> > >
> > > --
> > > E-Mail: garydgreg...@gmail.com | ggreg...@apache.org
> > > 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 <boa...@gmail.com>
>


Re: Log4j2 - HTML emails pattern

2015-11-09 Thread Benjamin Jaton
Thanks the feedback.
I found that the easiest way to achieve this was to have the PatternLayout
class support to set the contentType to "text/html".
Then one can write HTML directly in the pattern.

Thanks again,
Ben

On Mon, Nov 9, 2015 at 6:51 AM, Remko Popma <remko.po...@gmail.com> wrote:

> Ben,
>
> The built-in HTML layout (
> https://logging.apache.org/log4j/2.x/log4j-core/xref/org/apache/logging/log4j/core/layout/HtmlLayout.html)
> does not support much customization.
>
> It sounds like you may want to create a custom layout and specify that
> layout with the SMTP appender.
>
> This manual page may be a good place to get started:
> http://logging.apache.org/log4j/2.x/manual/extending.html#Layouts
>
> Best regards,
> Remko
>
> > On 2015/11/06, at 4:55, Benjamin Jaton <benjamin.ja...@gmail.com> wrote:
> >
> > Hi,
> >
> > I am using the SMTPAppender with a custom pattern:
> >  "PatternLayout" : { "pattern" : "%m" }
> >
> > But the email is sent as text.
> >
> > I saw that there is a HTMLLayout but it doesn't seem to accept a pattern?
> >
> > How can I produce a custom HTML message?
> >
> > Thanks!
> > Ben
>


Log4j2 - HTML emails pattern

2015-11-05 Thread Benjamin Jaton
Hi,

I am using the SMTPAppender with a custom pattern:
  "PatternLayout" : { "pattern" : "%m" }

But the email is sent as text.

I saw that there is a HTMLLayout but it doesn't seem to accept a pattern?

How can I produce a custom HTML message?

Thanks!
Ben


Re: Log4j2 set log level, cascade

2015-10-20 Thread Benjamin Jaton
It doesn't look like this is available in 2.3, was it added recently?
Any workaround for 2.3?

Thanks
Ben

On Tue, Oct 20, 2015 at 3:26 PM, Gary Gregory <garydgreg...@gmail.com>
wrote:

> Check out the
> APIs org.apache.logging.log4j.core.config.Configurator.setAllLevels(String,
> Level) and setLevel().
>
> Gary
>
> On Tue, Oct 20, 2015 at 3:13 PM, Benjamin Jaton <benjamin.ja...@gmail.com>
> wrote:
>
> > Hello,
> >
> > Here is a simple configuration:
> >
> > 
> > 
> >   
> > 
> >   
> > 
> >   
> >   
> > **
> >   
> > 
> > **
> >   
> > 
> > **
> >   
> > 
> >   
> > 
> >
> > I am trying to programmatically set the log level of "com.rli", but I
> can't
> > find the Loggers until they are used:
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > *System.setProperty("log4j.configurationFile",
> > "/tmp/test.xml");LogManager.getLogger("com.foo.Test");LoggerContext ctx =
> > (LoggerContext) LogManager.getContext(false);Configuration conf =
> > ctx.getConfiguration();for (Logger l : ctx.getLoggers()) {
> LoggerConfig
> > config = conf.getLoggerConfig(l.getName());System.out.println("Found
> > logger " + l.getName());}*
> > This will only show the com.foo.Test Logger because I created it just
> > before, but it will not find com.rli.Bar.
> > How can I get ALL the loggers, so that I can then set their log level?
> >
> > Note that setting directly the log level of "com.rli" will not work
> because
> > what is defined for com.rli.Bar in the conf file will take precedence.
> >
> > Thanks
> > Ben
> >
>
>
>
> --
> E-Mail: garydgreg...@gmail.com | ggreg...@apache.org
> 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
>


Log4j2 set log level, cascade

2015-10-20 Thread Benjamin Jaton
Hello,

Here is a simple configuration:



  

  

  
  
**
  

**
  

**
  

  


I am trying to programmatically set the log level of "com.rli", but I can't
find the Loggers until they are used:












*System.setProperty("log4j.configurationFile",
"/tmp/test.xml");LogManager.getLogger("com.foo.Test");LoggerContext ctx =
(LoggerContext) LogManager.getContext(false);Configuration conf =
ctx.getConfiguration();for (Logger l : ctx.getLoggers()) {LoggerConfig
config = conf.getLoggerConfig(l.getName());System.out.println("Found
logger " + l.getName());}*
This will only show the com.foo.Test Logger because I created it just
before, but it will not find com.rli.Bar.
How can I get ALL the loggers, so that I can then set their log level?

Note that setting directly the log level of "com.rli" will not work because
what is defined for com.rli.Bar in the conf file will take precedence.

Thanks
Ben


Re: JDBC Appender : how to have the pattern produce NULL?

2015-07-22 Thread Benjamin Jaton
I just tried it and it produces the same error.

column.layout.toSerializable(event) always produces a non-null String
because it is based on a StringBuilder.

So I don't think there is even a way for the code to set a column to NULL,
it will always be set to the Strings  or NULL, even if I write a custom
PatternConverter.


On Tue, Jul 21, 2015 at 5:21 PM, Remko Popma remko.po...@gmail.com wrote:

 Have you tried ThreadContext.remove(NUM)?

 Remko

 Sent from my iPhone

  On 2015/07/22, at 7:45, Benjamin Jaton benjamin.ja...@gmail.com wrote:
 
  Hello,
 
  I am using the JDBCAppender:
 
  {
   type : Jdbc,
   name : MyDatabaseAppender,
   tableName : LOGS,
   ignoreExceptions : false,
   ConnectionFactory : {
 class : test.ConnectionFactory,
 method : getDatabaseAppenderDataSource
   },
   Column : [
  { name : ID, pattern : %X{ID}, isUnicode : false },
  { name : NUM, pattern : %X{NUM}, isUnicode : false }
  ]
  }
 
  As you can see, I am using the ThreadContext to pass the variables.
 
  ThreadContext.put(ID, id++);
  ThreadContext.put(NUM, 41);
 
  The NUM column is of type BIGINT, and is nullable.
 
  I am trying to set it to NULL with:
   ThreadContext.put(NUM, NULL);
  or
   ThreadContext.put(NUM, null);
  or
   ThreadContext.put(NUM, );
 
  Every time I get
  Caused by: org.apache.derby.client.am.SqlException: Error for batch
 element
  #0: Invalid character string format for type BIGINT.
 at org.apache.derby.client.am.Statement.completeExecute(Unknown
 Source)
 
  I believe this is because, in
 
 org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.writeInternal()
  we always do
   this.statement.setString(i++, column.layout.toSerializable(event));
 
  So we always end up feeding the String  or NULL to the statement.
 
  Is there anything I can do to alter this behavior?
 
  Thanks

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




Re: RollingFileAppeneder MaxSize + keep 30 days

2015-07-06 Thread Benjamin Jaton
Bump.

So far my only option is to not use a size limit at all, and only use a 1
per day policy and keep 30 files.

Any pointer would be greatly appreciated.

On Fri, Jul 3, 2015 at 4:51 PM, Benjamin Jaton benjamin.ja...@gmail.com
wrote:

 I'm sorry my question was for log4j2, I should have been more precise :)

 On Fri, Jul 3, 2015 at 10:29 AM, Gary Gregory garydgreg...@gmail.com
 wrote:

 You can also find more goodies in the log4j 1 extras jar.
 Gary

  Original message 
 From: Simon simon_park_m...@yahoo.co.uk
 Date: 07/03/2015  10:22  (GMT-08:00)
 To: Log4J Users List log4j-user@logging.apache.org
 Subject: Re: RollingFileAppeneder MaxSize + keep 30 days

 If you're stuck on Log4J 1.2 then you could try out the
 TimeAndSizeRollingAppender available at www.simonsite.org.uk.

 Sent from TypeMail



 On 2 Jul 2015 23:54, at 23:54, Benjamin Jaton benjamin.ja...@gmail.com
 wrote:
 Hello,
 
 How can I define a RollingFileAppender that would roll when it reaches
 100MB, and that would discard any log older than 30 days (not before)?
 
 I need to keep 30 days of logs for auditing purposes, but I also want
 to
 limit the logs to a certain size as well.
 
 Thanks!
 Ben





Re: RollingFileAppeneder MaxSize + keep 30 days

2015-07-03 Thread Benjamin Jaton
I'm sorry my question was for log4j2, I should have been more precise :)

On Fri, Jul 3, 2015 at 10:29 AM, Gary Gregory garydgreg...@gmail.com
wrote:

 You can also find more goodies in the log4j 1 extras jar.
 Gary

  Original message 
 From: Simon simon_park_m...@yahoo.co.uk
 Date: 07/03/2015  10:22  (GMT-08:00)
 To: Log4J Users List log4j-user@logging.apache.org
 Subject: Re: RollingFileAppeneder MaxSize + keep 30 days

 If you're stuck on Log4J 1.2 then you could try out the
 TimeAndSizeRollingAppender available at www.simonsite.org.uk.

 Sent from TypeMail



 On 2 Jul 2015 23:54, at 23:54, Benjamin Jaton benjamin.ja...@gmail.com
 wrote:
 Hello,
 
 How can I define a RollingFileAppender that would roll when it reaches
 100MB, and that would discard any log older than 30 days (not before)?
 
 I need to keep 30 days of logs for auditing purposes, but I also want
 to
 limit the logs to a certain size as well.
 
 Thanks!
 Ben



RollingFileAppeneder MaxSize + keep 30 days

2015-07-02 Thread Benjamin Jaton
Hello,

How can I define a RollingFileAppender that would roll when it reaches
100MB, and that would discard any log older than 30 days (not before)?

I need to keep 30 days of logs for auditing purposes, but I also want to
limit the logs to a certain size as well.

Thanks!
Ben


Re: SMTP appender + filter

2015-06-26 Thread Benjamin Jaton
Ah yes of course!

What about :
Since bufferSize can't be set to 0, is it not possible to only include the
log message itself in the email?

Thanks a lot!


On Thu, Jun 25, 2015 at 5:41 PM, Ralph Goers ralph.go...@dslextreme.com
wrote:

 The level associated with the root appender is info. No debug events will
 make it past that.

 Ralph


  On Jun 25, 2015, at 3:39 PM, Benjamin Jaton benjamin.ja...@gmail.com
 wrote:
 
  Hello,
 
  I am trying to create a filter at the appender level that would show all
  the messages that contain Show.
  This is my test:
 
 LogManager.getLogger(Test.class).debug(Hide me!);
 LogManager.getLogger(Test.class).info(test);
 LogManager.getLogger(Test.class).debug(Show me (debug));
 LogManager.getLogger(Test.class).fatal(Hide me! (fatal));
 LogManager.getLogger(Test.class).info(Show me (info));
 LogManager.getLogger(Test.class).info(Hide me!);
 
  And this is the configuration:
 
  Configuration status=debug name=MyApp packages=
   Appenders
 SMTP name=Mail subject=Error Log to=... from=...
  smtpProtocol=... smtpHost=... smtpPort=... smtpUsername=...
  smtpPassword=... bufferSize=1
 RegexFilter regex=.*Show.* onMatch=ACCEPT onMismatch=DENY/
 PatternLayout
 pattern%5p %m%n/pattern
 /PatternLayout
 /SMTP
   /Appenders
   Loggers
 Root level=info
   AppenderRef ref=Mail/
 /Root
   /Loggers
  /Configuration
 
  This produces 1 email with:
  ---
   FATAL Hide me! (fatal)
   INFO Show me (info)
  ---
 
  I would expect 2 emails with:
  ---
   INFO test
   DEBUG Show me (debug)
  ---
   FATAL Hide me! (fatal)
   INFO Show me (info)
  ---
 
  I also tried this composite filter instead:
 Filters
   ThresholdFilter level=TRACE onMatch=NEUTRAL
  onMismatch=DENY /
   RegexFilter regex=.*Show.* onMatch=ACCEPT
 onMismatch=DENY/
 /Filters
 
  But same result, the DEBUG event is not triggering the appender somehow.
 
  Anyone has an idea how to do this?
 
 
  Bonus question: Since bufferSize can't be set to 0, is it not possible to
  only include the log message itself in the email?
 
  Many thanks!
  Ben



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




how to reinitialize log4j2 configuration?

2015-06-05 Thread Benjamin Jaton
Hello

After an initial configuration of log4j2 with:

Configurator.initialize(null, configLocation);

I would like to reinitialize it with a different URL

Configurator.initialize(null, configLocation2);

The problem is that the second call is ignored. I believe that once the
LoggerContext is STARTED it will ignore reconfigurations.

Is there a way to do this?

Thanks!
Ben