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 Umesh Awasthi <um...@gmail.com> on 2011/01/27 18:07:52 UTC

creating log4j log file name at run time

Hi All,

I am working on an module for import process which can be triggered by
various way by user click by schdular etc. and it will go with the phasse of
validation and if validation is success than final import. in order to show
up validation error to the user we want to use the log file so that if
validation failed we will just pick the log file and show that in a window.
So far everything was fine but now i need to create a logfile for each
import job something like when a job start get timestamp and name the log
file based on the time stamp also same time for each job i need to store the
log file name for that job so that later can pick the same log file for
display purpose.
i gone through various questions on found by googling  but seems that the
requirement was quite different. One approach which i came to know is to get
list of all appenders and den override the name of the file in the code but
since we are in web-application i am not sure about the thread safty and any
other potential issue
Can some one suggest me how i can create a seperate log file for each import
process instance.

-- 
With Regards
Umesh Awasthi
Software Engineers never die… They just go Offline
http://travelling-rants.blogspot.com/

Re: creating log4j log file name at run time

Posted by Rodney Beede <co...@rodneybeede.com>.
Yes but you also want to set the additivity for your appenders.

On Thu, Jan 27, 2011 at 10:18 AM, Umesh Awasthi <um...@gmail.com> wrote:
> Rodney ,
> Thanks for the replt
> i am new to Log4j can you descibe it a bit with some out line example so it
> will help me to pick the thing better way.
> what i am able to understand from your point is that you are saying
> something like
>
> SimpleLayout layout = new SimpleLayout();
>      FileAppender appender = new FileAppender(layout,"your
> filename",false);
>      logger.addAppender(appender);
>
> On Thu, Jan 27, 2011 at 10:41 PM, Rodney Beede
> <ma...@rodneybeede.com>wrote:
>
>> Simply create a new logger with no appenders and attach a new file
>> appender to that logger.  Use that new logger only for the class
>> running the import.
>>
>> On Thu, Jan 27, 2011 at 10:07 AM, Umesh Awasthi <um...@gmail.com>
>> wrote:
>> > Hi All,
>> >
>> > I am working on an module for import process which can be triggered by
>> > various way by user click by schdular etc. and it will go with the phasse
>> of
>> > validation and if validation is success than final import. in order to
>> show
>> > up validation error to the user we want to use the log file so that if
>> > validation failed we will just pick the log file and show that in a
>> window.
>> > So far everything was fine but now i need to create a logfile for each
>> > import job something like when a job start get timestamp and name the log
>> > file based on the time stamp also same time for each job i need to store
>> the
>> > log file name for that job so that later can pick the same log file for
>> > display purpose.
>> > i gone through various questions on found by googling  but seems that the
>> > requirement was quite different. One approach which i came to know is to
>> get
>> > list of all appenders and den override the name of the file in the code
>> but
>> > since we are in web-application i am not sure about the thread safty and
>> any
>> > other potential issue
>> > Can some one suggest me how i can create a seperate log file for each
>> import
>> > process instance.
>> >
>> > --
>> > With Regards
>> > Umesh Awasthi
>> > Software Engineers never die… They just go Offline
>> > http://travelling-rants.blogspot.com/
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>>
>
>
> --
> With Regards
> Umesh Awasthi
> Software Engineers never die… They just go Offline
> http://travelling-rants.blogspot.com/
>

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


Re: creating log4j log file name at run time

Posted by Umesh Awasthi <um...@gmail.com>.
Rodney ,
Thanks for the replt
i am new to Log4j can you descibe it a bit with some out line example so it
will help me to pick the thing better way.
what i am able to understand from your point is that you are saying
something like

SimpleLayout layout = new SimpleLayout();
      FileAppender appender = new FileAppender(layout,"your
filename",false);
      logger.addAppender(appender);

On Thu, Jan 27, 2011 at 10:41 PM, Rodney Beede
<ma...@rodneybeede.com>wrote:

> Simply create a new logger with no appenders and attach a new file
> appender to that logger.  Use that new logger only for the class
> running the import.
>
> On Thu, Jan 27, 2011 at 10:07 AM, Umesh Awasthi <um...@gmail.com>
> wrote:
> > Hi All,
> >
> > I am working on an module for import process which can be triggered by
> > various way by user click by schdular etc. and it will go with the phasse
> of
> > validation and if validation is success than final import. in order to
> show
> > up validation error to the user we want to use the log file so that if
> > validation failed we will just pick the log file and show that in a
> window.
> > So far everything was fine but now i need to create a logfile for each
> > import job something like when a job start get timestamp and name the log
> > file based on the time stamp also same time for each job i need to store
> the
> > log file name for that job so that later can pick the same log file for
> > display purpose.
> > i gone through various questions on found by googling  but seems that the
> > requirement was quite different. One approach which i came to know is to
> get
> > list of all appenders and den override the name of the file in the code
> but
> > since we are in web-application i am not sure about the thread safty and
> any
> > other potential issue
> > Can some one suggest me how i can create a seperate log file for each
> import
> > process instance.
> >
> > --
> > With Regards
> > Umesh Awasthi
> > Software Engineers never die… They just go Offline
> > http://travelling-rants.blogspot.com/
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
With Regards
Umesh Awasthi
Software Engineers never die… They just go Offline
http://travelling-rants.blogspot.com/

Re: creating log4j log file name at run time

Posted by Rodney Beede <ma...@rodneybeede.com>.
Simply create a new logger with no appenders and attach a new file
appender to that logger.  Use that new logger only for the class
running the import.

On Thu, Jan 27, 2011 at 10:07 AM, Umesh Awasthi <um...@gmail.com> wrote:
> Hi All,
>
> I am working on an module for import process which can be triggered by
> various way by user click by schdular etc. and it will go with the phasse of
> validation and if validation is success than final import. in order to show
> up validation error to the user we want to use the log file so that if
> validation failed we will just pick the log file and show that in a window.
> So far everything was fine but now i need to create a logfile for each
> import job something like when a job start get timestamp and name the log
> file based on the time stamp also same time for each job i need to store the
> log file name for that job so that later can pick the same log file for
> display purpose.
> i gone through various questions on found by googling  but seems that the
> requirement was quite different. One approach which i came to know is to get
> list of all appenders and den override the name of the file in the code but
> since we are in web-application i am not sure about the thread safty and any
> other potential issue
> Can some one suggest me how i can create a seperate log file for each import
> process instance.
>
> --
> With Regards
> Umesh Awasthi
> Software Engineers never die… They just go Offline
> http://travelling-rants.blogspot.com/
>

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