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 Extra Extra <ma...@yahoo.com> on 2006/02/28 11:15:06 UTC

Custom Conversion character

HI
  I want to add my custom conversion character in to log message.say GUID as %S
  for that i have extended Logger,LoggerFactory,LoggingEvent,RollingFileAppender,
  PatternLayout,PatternParser,PatternConverter,PropertyConfigurator.
   
  My problem is i have few component which are using log4j and use property file for configuration.but i have no code level access to those classes.
  when i run my application it is not showing value for my custom attribute(i have given some default values)
  It is not giving me any kind of error.
  what should i do   :- please guide me,
  my property file looks like
   
  log4j.rootLogger=DEBUG,ROOT
  log4j.logger=org.apache.log4j.test.CustomLogger
  log4j.appender.ROOT=org.apache.log4j.test.CustomRollingFileAppender
  log4j.appender.ROOT.File=C:/PropTest.log
  log4j.appender.ROOT.MaxFileSize=1000KB
  log4j.appender.ROOT.layout=org.apache.log4j.test.CustomPatternLayout
  log4j.appender.ROOT.layout.ConversionPattern=%n--------------------%nTime: %d%nGUID: %S%nMessage: %m
   
  %S is my custom character
   
  thanks in advance

		
---------------------------------
Brings words and photos together (easily) with
 PhotoMail  - it's free and works with Yahoo! Mail.

Re: Custom Conversion character

Posted by Javier Gonzalez <ja...@gmail.com>.
If I understand correctly, if you want to use your extended classes you'll
have to _replace_ the original log4j classes, not extend them. That's the
only way the app code will call your custom code when initializing a logger.

Isn't it possible to achieve your goals with custom Appenders and Layouts
only? Since appenders and layouts can be specified in the config files, that
would be the only way, IMHO, you can do this without messing with the app
code (which you don't have access to)

cheers,

Javier.

On 3/1/06, Extra Extra <ma...@yahoo.com> wrote:
>
> James,
>
>   Again confusion,
>
>   i dont have code level access to any of the classes of my application.
>   where do i put this MDC code.
>
>   i have just extended few classes from log4j and make jar file and i want
> to refer that CustomLogger and CustomLayouts from my property file.
>   but the problem is that my application(in code) is creating object of
> Original logger instead of CustomLogger and PropertyConfigurator instead of
> customPropConfigurator
>   i cant alter code and i have only property file threw which i can
> configure.
>
>   how do i override original Logger with my CustomLogger using property
> file.
>   is there any other classes i need to extend?????
>   i am new to log4j. so please if possible state it in detail,
>
>
>   thanks
>
> James Stauffer <st...@gmail.com> wrote:
>   Use MDC.
> In code set the value with MDC.put("GUID", value) and then you can use
> %X{GUID} in your config file.
>
> On 2/28/06, Extra Extra wrote:
> > HI
> > I want to add my custom conversion character in to log message.say GUID
> as %S
> > for that i have extended
> Logger,LoggerFactory,LoggingEvent,RollingFileAppender,
> > PatternLayout,PatternParser,PatternConverter,PropertyConfigurator.
> >
> > My problem is i have few component which are using log4j and use
> property file for configuration.but i have no code level access to those
> classes.
> > when i run my application it is not showing value for my custom
> attribute(i have given some default values)
> > It is not giving me any kind of error.
> > what should i do :- please guide me,
> > my property file looks like
> >
> > log4j.rootLogger=DEBUG,ROOT
> > log4j.logger=org.apache.log4j.test.CustomLogger
> > log4j.appender.ROOT=org.apache.log4j.test.CustomRollingFileAppender
> > log4j.appender.ROOT.File=C:/PropTest.log
> > log4j.appender.ROOT.MaxFileSize=1000KB
> > log4j.appender.ROOT.layout=org.apache.log4j.test.CustomPatternLayout
> >
> log4j.appender.ROOT.layout.ConversionPattern=%n--------------------%nTime:%d%nGUID: %S%nMessage: %m
> >
> > %S is my custom character
> >
> > thanks in advance
> >
> >
> > ---------------------------------
> > Brings words and photos together (easily) with
> > PhotoMail - it's free and works with Yahoo! Mail.
> >
>
>
> --
> James Stauffer
> Are you good? Take the test at http://www.livingwaters.com/good/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
>
>
> ---------------------------------
> Yahoo! Mail
> Bring photos to life! New PhotoMail  makes sharing a breeze.
>



--
Javier González Nicolini

Re: Custom Conversion character

Posted by Extra Extra <ma...@yahoo.com>.
James,
   
  Again confusion,
   
  i dont have code level access to any of the classes of my application.
  where do i put this MDC code.
   
  i have just extended few classes from log4j and make jar file and i want to refer that CustomLogger and CustomLayouts from my property file.
  but the problem is that my application(in code) is creating object of Original logger instead of CustomLogger and PropertyConfigurator instead of customPropConfigurator
  i cant alter code and i have only property file threw which i can configure.
   
  how do i override original Logger with my CustomLogger using property file.
  is there any other classes i need to extend?????
  i am new to log4j. so please if possible state it in detail, 
   
   
  thanks

James Stauffer <st...@gmail.com> wrote:
  Use MDC.
In code set the value with MDC.put("GUID", value) and then you can use
%X{GUID} in your config file.

On 2/28/06, Extra Extra wrote:
> HI
> I want to add my custom conversion character in to log message.say GUID as %S
> for that i have extended Logger,LoggerFactory,LoggingEvent,RollingFileAppender,
> PatternLayout,PatternParser,PatternConverter,PropertyConfigurator.
>
> My problem is i have few component which are using log4j and use property file for configuration.but i have no code level access to those classes.
> when i run my application it is not showing value for my custom attribute(i have given some default values)
> It is not giving me any kind of error.
> what should i do :- please guide me,
> my property file looks like
>
> log4j.rootLogger=DEBUG,ROOT
> log4j.logger=org.apache.log4j.test.CustomLogger
> log4j.appender.ROOT=org.apache.log4j.test.CustomRollingFileAppender
> log4j.appender.ROOT.File=C:/PropTest.log
> log4j.appender.ROOT.MaxFileSize=1000KB
> log4j.appender.ROOT.layout=org.apache.log4j.test.CustomPatternLayout
> log4j.appender.ROOT.layout.ConversionPattern=%n--------------------%nTime: %d%nGUID: %S%nMessage: %m
>
> %S is my custom character
>
> thanks in advance
>
>
> ---------------------------------
> Brings words and photos together (easily) with
> PhotoMail - it's free and works with Yahoo! Mail.
>


--
James Stauffer
Are you good? Take the test at http://www.livingwaters.com/good/

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



		
---------------------------------
Yahoo! Mail
Bring photos to life! New PhotoMail  makes sharing a breeze. 

Re: Custom Conversion character

Posted by James Stauffer <st...@gmail.com>.
Use MDC.
In code set the value with MDC.put("GUID", value) and then you can use
%X{GUID} in your config file.

On 2/28/06, Extra Extra <ma...@yahoo.com> wrote:
> HI
>   I want to add my custom conversion character in to log message.say GUID as %S
>   for that i have extended Logger,LoggerFactory,LoggingEvent,RollingFileAppender,
>   PatternLayout,PatternParser,PatternConverter,PropertyConfigurator.
>
>   My problem is i have few component which are using log4j and use property file for configuration.but i have no code level access to those classes.
>   when i run my application it is not showing value for my custom attribute(i have given some default values)
>   It is not giving me any kind of error.
>   what should i do   :- please guide me,
>   my property file looks like
>
>   log4j.rootLogger=DEBUG,ROOT
>   log4j.logger=org.apache.log4j.test.CustomLogger
>   log4j.appender.ROOT=org.apache.log4j.test.CustomRollingFileAppender
>   log4j.appender.ROOT.File=C:/PropTest.log
>   log4j.appender.ROOT.MaxFileSize=1000KB
>   log4j.appender.ROOT.layout=org.apache.log4j.test.CustomPatternLayout
>   log4j.appender.ROOT.layout.ConversionPattern=%n--------------------%nTime: %d%nGUID: %S%nMessage: %m
>
>   %S is my custom character
>
>   thanks in advance
>
>
> ---------------------------------
> Brings words and photos together (easily) with
>  PhotoMail  - it's free and works with Yahoo! Mail.
>


--
James Stauffer
Are you good? Take the test at http://www.livingwaters.com/good/

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