You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Claus Ibsen <ci...@silverbullet.dk> on 2008/09/16 12:41:19 UTC

RE: [SPAM] Re: Custom log messages

Hi

You can prefix the categoy (package name) with the same prefix

To("log:com.mycompany.ValidatingAgainstXMLSchema")
To("log:com.mycompany.ValidationOK")

And have them logged in the same file

log4j.logger.com.mycompany = special

log4j.appender.special=org.apache.log4j.FileAppender
log4j.appender.special.layout=org.apache.log4j.PatternLayout
log4j.appender.special.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
log4j.appender.special.file=myspecial.log
log4j.appender.special.append=true



Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk

-----Original Message-----
From: James Strachan [mailto:james.strachan@gmail.com] 
Sent: 16. september 2008 12:34
To: camel-user@activemq.apache.org
Subject: [SPAM] Re: Custom log messages

2008/9/16 raulvk.soa <ra...@gmail.com>:
> Nevermind. Sorry I got confused. Obviously you can make different log
> categories use the same Appender!
>
> That would be a temporary solution, as architecturally speaking we would be
> overloading the log4j with an awful amount of loggers, which I am not happy
> doing.
>
> Do you think it is feasible to achieve this by extending the Logger class
> and using it as a processor? What method would I have to override? Any
> special considerations? I think I may attempt to do this...

I'm not quite sure I follow. Claus's example uses a single Logger
called "ValidatingAgainstXMLSchema" or whatever. i.e. you can use a
single Logger if you want - the URI log:foo defines the logger to use.
There's not one per message or anything like that. Each different log
URI uses a different logger, so its up to you to define how many
different logger/categories you want to use.

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com

Re: [SPAM] Re: Custom log messages

Posted by James Strachan <ja...@gmail.com>.
2008/9/16 raulvk.soa <ra...@gmail.com>:
>
> Yep, I just realised that was possible.
>
> Do you know if there is a way to get rid of the full category name and only
> print out the last token on the log file? i.e. print out
> "ValidatingAgainstXMLSchema" instead of
> "com.mycompany.ValidatingAgainstXMLSchema".
>
> I am aware that I can truncate it at a fixed position, but I cannot
> guarantee that my final tokens will all be the same length...

Using this config tends to just print the last path of the category

log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n

For more information see
http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html

i.e. use %c{x} where x is the number of right hand paths to print, so
%c{1} just prints the last one

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com

RE: [SPAM] RE: [SPAM] Re: Custom log messages

Posted by Claus Ibsen <ci...@silverbullet.dk>.
Hi

You can do all sorts of thing with -% in log4j:
[%-15.15c]. I guess it should be possible to skip X.

Or you Can make your category very small, such as x ;

To("log:xValidatingAgainstSchma")



Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk

-----Original Message-----
From: raulvk.soa [mailto:raulvk.soa@gmail.com] 
Sent: 16. september 2008 13:05
To: camel-user@activemq.apache.org
Subject: [SPAM] RE: [SPAM] Re: Custom log messages


Yep, I just realised that was possible.

Do you know if there is a way to get rid of the full category name and only
print out the last token on the log file? i.e. print out
"ValidatingAgainstXMLSchema" instead of
"com.mycompany.ValidatingAgainstXMLSchema".

I am aware that I can truncate it at a fixed position, but I cannot
guarantee that my final tokens will all be the same length...



Claus Ibsen wrote:
> 
> Hi
> 
> You can prefix the categoy (package name) with the same prefix
> 
> To("log:com.mycompany.ValidatingAgainstXMLSchema")
> To("log:com.mycompany.ValidationOK")
> 
> And have them logged in the same file
> 
> log4j.logger.com.mycompany = special
> 
> log4j.appender.special=org.apache.log4j.FileAppender
> log4j.appender.special.layout=org.apache.log4j.PatternLayout
> log4j.appender.special.layout.ConversionPattern=%d [%-15.15t] %-5p
> %-30.30c{1} - %m%n
> log4j.appender.special.file=myspecial.log
> log4j.appender.special.append=true
> 
> 
> 
> Med venlig hilsen
>  
> Claus Ibsen
> ......................................
> Silverbullet
> Skovsgårdsvænget 21
> 8362 Hørning
> Tlf. +45 2962 7576
> Web: www.silverbullet.dk
> 
> -----Original Message-----
> From: James Strachan [mailto:james.strachan@gmail.com] 
> Sent: 16. september 2008 12:34
> To: camel-user@activemq.apache.org
> Subject: [SPAM] Re: Custom log messages
> 
> 2008/9/16 raulvk.soa <ra...@gmail.com>:
>> Nevermind. Sorry I got confused. Obviously you can make different log
>> categories use the same Appender!
>>
>> That would be a temporary solution, as architecturally speaking we would
>> be
>> overloading the log4j with an awful amount of loggers, which I am not
>> happy
>> doing.
>>
>> Do you think it is feasible to achieve this by extending the Logger class
>> and using it as a processor? What method would I have to override? Any
>> special considerations? I think I may attempt to do this...
> 
> I'm not quite sure I follow. Claus's example uses a single Logger
> called "ValidatingAgainstXMLSchema" or whatever. i.e. you can use a
> single Logger if you want - the URI log:foo defines the logger to use.
> There's not one per message or anything like that. Each different log
> URI uses a different logger, so its up to you to define how many
> different logger/categories you want to use.
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source Integration
> http://open.iona.com
> 
> 

-- 
View this message in context: http://www.nabble.com/Custom-log-messages-tp19508418s22882p19509593.html
Sent from the Camel - Users mailing list archive at Nabble.com.


RE: [SPAM] Re: Custom log messages

Posted by "raulvk.soa" <ra...@gmail.com>.
Yep, I just realised that was possible.

Do you know if there is a way to get rid of the full category name and only
print out the last token on the log file? i.e. print out
"ValidatingAgainstXMLSchema" instead of
"com.mycompany.ValidatingAgainstXMLSchema".

I am aware that I can truncate it at a fixed position, but I cannot
guarantee that my final tokens will all be the same length...



Claus Ibsen wrote:
> 
> Hi
> 
> You can prefix the categoy (package name) with the same prefix
> 
> To("log:com.mycompany.ValidatingAgainstXMLSchema")
> To("log:com.mycompany.ValidationOK")
> 
> And have them logged in the same file
> 
> log4j.logger.com.mycompany = special
> 
> log4j.appender.special=org.apache.log4j.FileAppender
> log4j.appender.special.layout=org.apache.log4j.PatternLayout
> log4j.appender.special.layout.ConversionPattern=%d [%-15.15t] %-5p
> %-30.30c{1} - %m%n
> log4j.appender.special.file=myspecial.log
> log4j.appender.special.append=true
> 
> 
> 
> Med venlig hilsen
>  
> Claus Ibsen
> ......................................
> Silverbullet
> Skovsgårdsvænget 21
> 8362 Hørning
> Tlf. +45 2962 7576
> Web: www.silverbullet.dk
> 
> -----Original Message-----
> From: James Strachan [mailto:james.strachan@gmail.com] 
> Sent: 16. september 2008 12:34
> To: camel-user@activemq.apache.org
> Subject: [SPAM] Re: Custom log messages
> 
> 2008/9/16 raulvk.soa <ra...@gmail.com>:
>> Nevermind. Sorry I got confused. Obviously you can make different log
>> categories use the same Appender!
>>
>> That would be a temporary solution, as architecturally speaking we would
>> be
>> overloading the log4j with an awful amount of loggers, which I am not
>> happy
>> doing.
>>
>> Do you think it is feasible to achieve this by extending the Logger class
>> and using it as a processor? What method would I have to override? Any
>> special considerations? I think I may attempt to do this...
> 
> I'm not quite sure I follow. Claus's example uses a single Logger
> called "ValidatingAgainstXMLSchema" or whatever. i.e. you can use a
> single Logger if you want - the URI log:foo defines the logger to use.
> There's not one per message or anything like that. Each different log
> URI uses a different logger, so its up to you to define how many
> different logger/categories you want to use.
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source Integration
> http://open.iona.com
> 
> 

-- 
View this message in context: http://www.nabble.com/Custom-log-messages-tp19508418s22882p19509593.html
Sent from the Camel - Users mailing list archive at Nabble.com.