You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Maple Wang <ma...@hotmail.com> on 2016/03/28 10:35:42 UTC

is there any way to add a marker to a logger rather than a log

Hi,

 

Marker is great feature for classifying and filtering log content, but I
have a question about how to use marker in logging API. In official guide
for log4j2.x, normally, we need to do as blow:

 

Marker myMarker =  MarkerManager.getMarker("myMarker");

LOGGER.info(myMarker,"some log message");

 

This is good, but in my situation, I want to add a marker directly to a
LOGGER, then, every time user use "LOGGER.info("some log message");", the
marker will be added automatically. Is there any way to help me to achieve
this?

 

Thanks in advance.

 

Best regards.


RE: is there any way to add a marker to a logger rather than a log

Posted by Maple Wang <ma...@hotmail.com>.
Hi Remko,

Thanks for your suggestion, I extends the ExtendedLoggerWrapper and override
logMessage(String fqcn, Level level, Marker marker, Message message,
Throwable t) to add my specific marker, it works. But I still wonder if it's
possible to enable user to add marker to logger through API directly, it
could be a feature implemented in the feature.

Best regards.

-----Original Message-----
From: Remko Popma [mailto:remko.popma@gmail.com] 
Sent: Tuesday, March 29, 2016 12:23 PM
To: Log4J Users List
Subject: Re: is there any way to add a marker to a logger rather than a log

The log4j API does not provide a way to "set" a marker that will be emitted
on all events produced by that logger. 

However, one idea is to generate a logger wrapper and write the above logic
in the wrapper. Log4j provides a tool to generate logger wrappers for custom
log levels. This will give a good starting point. 

Let me know if you have questions. 
Remko

Sent from my iPhone

> On 2016/03/29, at 10:58, Maple Wang <ma...@hotmail.com> wrote:
> 
> Hi Gary,
> 
> Yes, I want to use specific marker on one more loggers, I mean current way
of using marker is not so convenient if I want to add same marker to
multiple log records, so I require to add marker to a logger directly, then
all log records using this logger will have this marker automatically, do we
have this feature now in log4j2.5? or is there any workaround to achieve
this?
> 
> Best regards.
> 
> -----Original Message-----
> From: Gary Gregory [mailto:garydgregory@gmail.com]
> Sent: Monday, March 28, 2016 10:41 PM
> To: Log4J Users List
> Subject: Re: is there any way to add a marker to a logger rather than 
> a log
> 
> Do you plan on using this marker with more than one logger?
> 
> Gary
>> On Mar 28, 2016 1:35 AM, "Maple Wang" <ma...@hotmail.com>
wrote:
>> 
>> Hi,
>> 
>> 
>> 
>> Marker is great feature for classifying and filtering log content, 
>> but I have a question about how to use marker in logging API. In 
>> official guide for log4j2.x, normally, we need to do as blow:
>> 
>> 
>> 
>> Marker myMarker =  MarkerManager.getMarker("myMarker");
>> 
>> LOGGER.info(myMarker,"some log message");
>> 
>> 
>> 
>> This is good, but in my situation, I want to add a marker directly to 
>> a LOGGER, then, every time user use "LOGGER.info("some log 
>> message");", the marker will be added automatically. Is there any way 
>> to help me to achieve this?
>> 
>> 
>> 
>> Thanks in advance.
>> 
>> 
>> 
>> Best regards.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 

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



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


Re: is there any way to add a marker to a logger rather than a log

Posted by Remko Popma <re...@gmail.com>.
The log4j API does not provide a way to "set" a marker that will be emitted on all events produced by that logger. 

However, one idea is to generate a logger wrapper and write the above logic in the wrapper. Log4j provides a tool to generate logger wrappers for custom log levels. This will give a good starting point. 

Let me know if you have questions. 
Remko

Sent from my iPhone

> On 2016/03/29, at 10:58, Maple Wang <ma...@hotmail.com> wrote:
> 
> Hi Gary,
> 
> Yes, I want to use specific marker on one more loggers, I mean current way of using marker is not so convenient if I want to add same marker to multiple log records, so I require to add marker to a logger directly, then all log records using this logger will have this marker automatically, do we have this feature now in log4j2.5? or is there any workaround to achieve this?
> 
> Best regards.
> 
> -----Original Message-----
> From: Gary Gregory [mailto:garydgregory@gmail.com] 
> Sent: Monday, March 28, 2016 10:41 PM
> To: Log4J Users List
> Subject: Re: is there any way to add a marker to a logger rather than a log
> 
> Do you plan on using this marker with more than one logger?
> 
> Gary
>> On Mar 28, 2016 1:35 AM, "Maple Wang" <ma...@hotmail.com> wrote:
>> 
>> Hi,
>> 
>> 
>> 
>> Marker is great feature for classifying and filtering log content, but 
>> I have a question about how to use marker in logging API. In official 
>> guide for log4j2.x, normally, we need to do as blow:
>> 
>> 
>> 
>> Marker myMarker =  MarkerManager.getMarker("myMarker");
>> 
>> LOGGER.info(myMarker,"some log message");
>> 
>> 
>> 
>> This is good, but in my situation, I want to add a marker directly to 
>> a LOGGER, then, every time user use "LOGGER.info("some log 
>> message");", the marker will be added automatically. Is there any way 
>> to help me to achieve this?
>> 
>> 
>> 
>> Thanks in advance.
>> 
>> 
>> 
>> Best regards.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 

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


RE: is there any way to add a marker to a logger rather than a log

Posted by Maple Wang <ma...@hotmail.com>.
Hi Gary,

Yes, I want to use specific marker on one more loggers, I mean current way of using marker is not so convenient if I want to add same marker to multiple log records, so I require to add marker to a logger directly, then all log records using this logger will have this marker automatically, do we have this feature now in log4j2.5? or is there any workaround to achieve this?

Best regards.

-----Original Message-----
From: Gary Gregory [mailto:garydgregory@gmail.com] 
Sent: Monday, March 28, 2016 10:41 PM
To: Log4J Users List
Subject: Re: is there any way to add a marker to a logger rather than a log

Do you plan on using this marker with more than one logger?

Gary
On Mar 28, 2016 1:35 AM, "Maple Wang" <ma...@hotmail.com> wrote:

> Hi,
>
>
>
> Marker is great feature for classifying and filtering log content, but 
> I have a question about how to use marker in logging API. In official 
> guide for log4j2.x, normally, we need to do as blow:
>
>
>
> Marker myMarker =  MarkerManager.getMarker("myMarker");
>
> LOGGER.info(myMarker,"some log message");
>
>
>
> This is good, but in my situation, I want to add a marker directly to 
> a LOGGER, then, every time user use "LOGGER.info("some log 
> message");", the marker will be added automatically. Is there any way 
> to help me to achieve this?
>
>
>
> Thanks in advance.
>
>
>
> Best regards.
>
>


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


Re: is there any way to add a marker to a logger rather than a log

Posted by Gary Gregory <ga...@gmail.com>.
Do you plan on using this marker with more than one logger?

Gary
On Mar 28, 2016 1:35 AM, "Maple Wang" <ma...@hotmail.com> wrote:

> Hi,
>
>
>
> Marker is great feature for classifying and filtering log content, but I
> have a question about how to use marker in logging API. In official guide
> for log4j2.x, normally, we need to do as blow:
>
>
>
> Marker myMarker =  MarkerManager.getMarker("myMarker");
>
> LOGGER.info(myMarker,"some log message");
>
>
>
> This is good, but in my situation, I want to add a marker directly to a
> LOGGER, then, every time user use "LOGGER.info("some log message");", the
> marker will be added automatically. Is there any way to help me to achieve
> this?
>
>
>
> Thanks in advance.
>
>
>
> Best regards.
>
>