Jeff | 1 Aug 2008 05:51
Picon

ConsoleAppender and closing an SSH session

I just converted some apps to log4j 1.2.15. The log4j config creates a
ConsoleAppender and a FileAppender as follows.

log4j.rootLogger=INFO,CONSOLE,WIPATH

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d [%c{1}] %m%n

log4j.appender.WIPATH=org.apache.log4j.FileAppender
log4j.appender.WIPATH.File=/path/to/log/wipath.log
log4j.appender.WIPATH.layout=org.apache.log4j.PatternLayout
log4j.appender.WIPATH.layout.ConversionPattern=%d %-5p [%c{1}] %m%n

Normally these apps are launched from a serially connected character
terminal (think Wyse 50). The logging to console is there to make
non-techie users feel good and know that the application is running.

But if for some reason, I need to start the app from an SSH session
(putty), the application sometimes dies after I log out. Sometimes
right away, sometimes after some time has passed. Nothing about
interesting is written to the log file. Normally the app makes log
entries when it shuts down cleanly. The process is just gone. This did
not happen prior to implementing log4j. Previously, the app wrote to a
pre-configured file and to System.out. Closing an SSH session had no
ill effects.

OS is Linux, CentOS 4.6 32 bit under VMware Server 1.0.x. JRE is Sun
1.6.0_05-b13. There is no X display system installed.

(Continue reading)

Paul Smith | 1 Aug 2008 06:11

Re: ConsoleAppender and closing an SSH session

>
> But if for some reason, I need to start the app from an SSH session
> (putty), the application sometimes dies after I log out. Sometimes
> right away, sometimes after some time has passed. Nothing about
> interesting is written to the log file. Normally the app makes log
> entries when it shuts down cleanly. The process is just gone. This did
> not happen prior to implementing log4j. Previously, the app wrote to a
> pre-configured file and to System.out. Closing an SSH session had no
> ill effects.
>

This is not really a logging question per-se, but I feel for you.   
Unix process can die after the user shell that created them exits.  To  
be honest there doesn't appear to be a hard and fast rule as to this  
behaviour, but I'm quite confident it has nothing to do with log4j.   
the 'nohup' unix command was originally designed for this purpose, but  
there's an even better way.

Since you are launching a process that you want to stick around  
regardless of the connectivity of the shell process that launches it  
you should consider using the 'screen' application built into most  
*nix's.

host> screen -S "Some Logical Name"
host> /home/me/launchApp.sh
...
.
..

You can exit that terminal session at any time and it'll be safe from  
(Continue reading)

Jeff | 1 Aug 2008 06:41
Picon

Re: ConsoleAppender and closing an SSH session

On Thu, Jul 31, 2008 at 11:11 PM, Paul Smith <psmith <at> aconex.com> wrote:
>>
>> But if for some reason, I need to start the app from an SSH session
>> (putty), the application sometimes dies after I log out. Sometimes
>> right away, sometimes after some time has passed. Nothing about
>> interesting is written to the log file. Normally the app makes log
>> entries when it shuts down cleanly. The process is just gone. This did
>> not happen prior to implementing log4j. Previously, the app wrote to a
>> pre-configured file and to System.out. Closing an SSH session had no
>> ill effects.
>>
>
> This is not really a logging question per-se, but I feel for you.  Unix
> process can die after the user shell that created them exits.  To be honest
> there doesn't appear to be a hard and fast rule as to this behaviour, but
> I'm quite confident it has nothing to do with log4j.  the 'nohup' unix
> command was originally designed for this purpose, but there's an even better
> way.
>
> Since you are launching a process that you want to stick around regardless
> of the connectivity of the shell process that launches it you should
> consider using the 'screen' application built into most *nix's.
>
> host> screen -S "Some Logical Name"
> host> /home/me/launchApp.sh
> ...
> .
> ..
>
> You can exit that terminal session at any time and it'll be safe from a hang
(Continue reading)

Paul Smith | 1 Aug 2008 06:58

Re: ConsoleAppender and closing an SSH session

>
> Well I'm not convinced that this is completely unrelated to log4j.
> This set of apps has run for 8 years in one form or another and has
> been scripted to survive a logout. Now, with no changes except the
> introduction of log4j, the behavior has changed.
>

In your configuration example, you're using ConsoleAppender and a  
file.  By default Console appender will just write to System.out print  
stream which is exactly what System.out.println() does, and the  
FileAppender is really pretty basic, I can't explain how log4j would  
affect the stability of the process..  Log4j has been in use for  
nearly as long as your app, so I'd be very surprised if log4j was  
proved to be the culprit.

Are you sure some operating system upgrade or configuration on the  
host itself has not enforced some process conditions that weren't  
there before?

> In any case, I appreciate the pointer to screen. I will check it out.

couldn't live without 'screen'.  one of the best pointers a sysadmin  
ever showed me (that and an awful lot of awk/sed).

Paul
Thorbjørn Ravn Andersen | 1 Aug 2008 10:00
Picon

Re: ConsoleAppender and closing an SSH session

Jeff skrev  den 01-08-2008 06:41:
> Well I'm not convinced that this is completely unrelated to log4j.
> This set of apps has run for 8 years in one form or another and has
> been scripted to survive a logout. Now, with no changes except the
> introduction of log4j, the behavior has changed.
>   
I agree with Paul that I don't think this is a log4j issue as such, but 
that the actions taken by log4j may trigger the shutdown (a filled 
buffer that cannot be written?  an error message with nowhere to go?)

My knee-jerk reaction is to ask if you use "nohup" when starting your 
program over ssh?  If not, could you elaborate on "has been scripted to 
survive a logout"?

--
  Thorbjørn
Chrissy | 2 Aug 2008 00:17
Favicon

Multiple Appenders with single DailyRolling log file


My goal is to have a single DailyRolling log file but I would like to have a
different conversion pattern for a subpackage.  My current config resembles
the below.  This works but not surprisingly, the file doesn't roll over
because the second appender prevents it from rolling.  Is there another way
to do this?

log4j.logger.my.package=INFO,appender1
log4j.logger.my.package.subpackage=INFO,appender2
log4j.additivity.my.package.subpackage=false

log4j.appender.appender1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.appender1.File=${log.dir}/mylog.log
log4j.appender.appender1.DatePattern='.'yyyy-MM-dd
log4j.appender.appender1.layout=org.apache.log4j.PatternLayout
log4j.appender.appender1.layout.ConversionPattern=%d{HH:mm:ss MMM dd} %-5p -
%m%n

log4j.appender.appender2=org.apache.log4j.FileAppender
log4j.appender.appender2.File=${log.dir}/mylog.log
log4j.appender.appender2.DatePattern='.'yyyy-MM-dd
log4j.appender.appender2.layout=org.apache.log4j.PatternLayout
log4j.appender.appender2.layout.ConversionPattern=<<APPENDER2>>%d{HH:mm:ss
MMM dd} %-5p - %m%n

Thanks.

Chrissy.
--

-- 
View this message in context: http://www.nabble.com/Multiple-Appenders-with-single-DailyRolling-log-file-tp18783527p18783527.html
(Continue reading)

techie_india | 4 Aug 2008 07:02
Picon

RollingFileAppender not appending the file


Hi,

I have the following log4j.properties file:
# Set root logger level to DEBUG and add an appender called A1.

log4j.rootLogger=DEBUG, ConsoleAppender , FileAppender , XMLAppender

# ConsoleAppnder is set to be a ConsoleAppender.
log4j.appender.ConsoleAppender=org.apache.log4j.ConsoleAppender

# ConsoleAppender uses PatternLayout.
log4j.appender.ConsoleAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.ConsoleAppender.layout.ConversionPattern=%-4r [%t] %-5p %c %x
- %m%n

#FileAppender is a FileAppender which writes into the plain file 
log4j.appender.FileAppender=org.apache.log4j.RollingFileAppender
log4j.appender.FileAppender.File=log.txt
log4j.appender.FileAppender.MaxFileSize=1KB
log4j.appender.FileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.FileAppender.layout.ConversionPattern=%-4r [%t] %-5p %c %x -
%m%n

#XMLAppender is a FileAppender which writes into the XML file for chainsaw
log4j.appender.XMLAppender=org.apache.log4j.FileAppender
log4j.appender.XMLAppender.File=log.xml
log4j.appender.XMLAppender.MaxFileSize=1KB
log4j.appender.XMLAppender.layout=org.apache.log4j.xml.XMLLayout

(Continue reading)

Steven Keens | 4 Aug 2008 20:28
Favicon

NDC, MDC, or log.debug( new MyLogObj( "my message", context ) )?

Hello all:
I'm looking for opinions on whether to use an NDC, MDC, or use something like log.debug( new MyLogObj( "",
context) ).

I guess I should provide some background:
I have a database that stores the states of "jobs" that ran on the system.  Each job has a unique identifier. 
The database can also store log messages related to the job via a table named "joblogs" that has a foreign
key (column named "job_id") to the "jobs" table.

I have created an appender subclass that uses Hibernate to add the log messages to the "joblogs" table.  The
problem is that my appender needs to know the "job_id" (so that the foreign key "joblogs.job_id" can be
filled in).

I can think of 4 approaches to pass the job_id through to the appender.
1) Create loggers for each identifier.  I rejected this one pretty quickly because of the accumulation of
loggers and the requirement to parse the logger name. For example:
	Logger log = Logger.getLogger( " job.id.1" );

2) Create a new class (named something like JobLog) that is passed as the first parameter in the debug(),
info(), warn(), and error() functions.  This is the one I implemented before looking deeply into NDCs and
MDCs.  For example:
	
	private static final Logger log = Logger.getLogger( "job" );
	int jobId = 1;
	log.warn( new JobLogMsg( "Avoid doing that!", jobId ) );

3) Use MDC.
	private static final Logger log = Logger.getLogger( "job" );

	Integer jobId = new Ingteger(1);
(Continue reading)

Ashish Kulkarni | 4 Aug 2008 21:45
Picon

Logging messages using java 1.5 format string

Hi
Is there anyway to format the log messages using java 1.5 format
capabilities
for example i can have a nice formatted out put using
System.out.format("Number of Users on Registry %1$s, is %2$d",
registry.getName(), userSet.size());

Can i do some thing like
logger.debug("Number of Users on Registry %1$s, is %2$d",
registry.getName(), userSet.size());

I would hate to have to do
StringBuilder sb = new StringBuilder();
Formatter formatter = new Formatter(sb);
formatter.format("Number of Users on Registry %1$s, is %2$d",
registry.getName(), userSet.size());
logger.debug(sb);

to get formatted output,
Any ideas

Ashish
Thorbjørn Ravn Andersen | 4 Aug 2008 22:06
Picon

Re: Logging messages using java 1.5 format string

Ashish Kulkarni skrev  den 04-08-2008 21:45:
> Hi
> Is there anyway to format the log messages using java 1.5 format
> capabilities
> for example i can have a nice formatted out put using
> System.out.format("Number of Users on Registry %1$s, is %2$d",
> registry.getName(), userSet.size());
>   
Use slf4j as the logging interface and use log4j as the backend.

You can then call

log.debug("Name: {} Size {}", "Foo", new Integer(10));

--

-- 
  Thorbjørn Ravn Andersen          "... plus... Tubular Bells!"

Gmane