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 Rashmi Rubdi <de...@yahoo.com> on 2007/03/02 18:08:32 UTC

Newbie trying to change Standard Output log to File log

Hello Everyone, 

I'm new to Log4J. I think we're using Log4J version 1.2.8.
On Tomcat 5.5

I am using the basic Log4J properties file that comes with Hibernate Version 3.3.2 distribution:

By default the properties file is configured to send the output to the console 

Here's what came with Hibernate:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### direct messages to file hibernate.log ###
#log4j.appender.file=org.apache.log4j.FileAppender
#log4j.appender.file.File=hibernate.log
#log4j.appender.file.layout=org.apache.log4j.PatternLayout
#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'debug' ###

log4j.rootLogger=warn, stdout

#log4j.logger.org.hibernate=info
log4j.logger.org.hibernate=debug

### log HQL query parser activity
#log4j.logger.org.hibernate.hql.ast.AST=debug

### log just the SQL
#log4j.logger.org.hibernate.SQL=debug

### log JDBC bind parameters ###
log4j.logger.org.hibernate.type=info
#log4j.logger.org.hibernate.type=debug

### log schema export/update ###
log4j.logger.org.hibernate.tool.hbm2ddl=debug


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Then, I made changes to the above properties file, to make the output be logged in a file instead 
of standard output.

as follows upon searching on Google (but the output of the log still goes to standard output instead of a file)

### direct log messages to stdout ###
#log4j.appender.stdout=org.apache.log4j.ConsoleAppender
#log4j.appender.stdout.Target=System.out
#log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
#log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### direct messages to file hibernate.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=hibernate.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'debug' ###

#log4j.rootLogger=warn, stdout
log4j.rootLogger=warn, file

#log4j.logger.org.hibernate=info
log4j.logger.org.hibernate=info

### log HQL query parser activity
#log4j.logger.org.hibernate.hql.ast.AST=debug

### log just the SQL
#log4j.logger.org.hibernate.SQL=debug

### log JDBC bind parameters ###
#log4j.logger.org.hibernate.type=info
log4j.logger.org.hibernate.type=debug

### log schema export/update ###
log4j.logger.org.hibernate.tool.hbm2ddl=debug

I looked at the example here: http://ideoplex.com/id/386/controlling-hibernate-output-with-log4j to make the
above change, but I'm confused as to why the log is still being directed to the console rather than hibernate.log file.

I plan to read the Log4J manual and understand the various notations used in the properties file.

Any help is appreciated.

-Regards
Rashmi




 
____________________________________________________________________________________
Never miss an email again!
Yahoo! Toolbar alerts you the instant new Mail arrives.
http://tools.search.yahoo.com/toolbar/features/mail/

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


Re: Newbie trying to change Standard Output log to File log

Posted by Daniele Gagliardi <da...@eng.it>.
Hi Rashmi,
  you need to register an appender for every logger defined 
in your log4jproperties file. Logger present are:

# root logger (always present)
rootLogger

# Logger on top of hierarchy of loggers for hibernate package
org.hibernate

### loggger for HQL query parser activity
org.hibernate.hql.ast.AST
 
### loggger for just the SQL
org.hibernate.SQL
 
### loggger for JDBC bind parameters ###
org.hibernate.type
 
### logger for schema export/update ###
org.hibernate.tool.hbm2ddl

In this case (and this is a best practice), logger names are 
equals to packages in hibernate library. These loggers hinherit 
almost everything (appenders, for instance) by default from 
root logger and so they send their output to stdout (console, 
the appender registered for the root logger). If you need to send
output to another appender, you need to specify the appender name(s)
in the definition of every logger (or in the definition of the 
logger on top of hierarchy of their names):


log4j.logger.org.hibernate=debug,file
 
### log HQL query parser activity
log4j.logger.org.hibernate.hql.ast.AST=debug,file
 
### log just the SQL
log4j.logger.org.hibernate.SQL=debug,file
 
### log JDBC bind parameters ###
log4j.logger.org.hibernate.type=info,file
 
### log schema export/update ###
log4j.logger.org.hibernate.tool.hbm2ddl=debug,file

Now you registered 'file' appender for your loggers. Note that 
you could write only
log4j.logger.org.hibernate=debug,file

and don't specify appender for other loggers, because they are 
above in the hierarchy in respect with 'org.hibernate' logger:

### log HQL query parser activity
log4j.logger.org.hibernate.hql.ast.AST=debug
 
### log just the SQL
log4j.logger.org.hibernate.SQL=debug
 
### log JDBC bind parameters ###
log4j.logger.org.hibernate.type=info
 
### log schema export/update ###
log4j.logger.org.hibernate.tool.hbm2ddl=debug



Hope this can help.

Bye!



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


Re: Newbie trying to change Standard Output log to File log

Posted by Jacob Kjome <ho...@visi.com>.
Does HIbernate package log4j.properties in their library?  Where do 
you put your modified log4j.properties?  Log4j auto-configures itself 
in a static initializer and looks first for log4j.xml and then 
log4j.properties (if the former isn't found) in the default 
package.   Are you sure your modified version is being found instead 
of the unmodified version (or even some other Log4j config file in 
the classpath)?  Where do you put log4j.jar?  Where do you put the 
hibernate library?  Are hibernate.jar and log4j.jar in a shared 
classloader or in WEB-INF/lib?  Is your config file in 
WEB-INF/classes or a shared location?

These are all things to look into.  I would hasten to bet that your 
modified config file is not being utilized.  By answering the 
questions above, and thinking about how classloaders work (taking 
into account Tomcat's child-first webapp classloader), you should be 
able to solve the issue.

Jake

At 11:08 AM 3/2/2007, you wrote:
 >Hello Everyone,
 >
 >I'm new to Log4J. I think we're using Log4J version 1.2.8.
 >On Tomcat 5.5
 >
 >I am using the basic Log4J properties file that comes with Hibernate
 >Version 3.3.2 distribution:
 >
 >By default the properties file is configured to send the output to 
the console
 >
 >Here's what came with Hibernate:
 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 >
 >### direct log messages to stdout ###
 >log4j.appender.stdout=org.apache.log4j.ConsoleAppender
 >log4j.appender.stdout.Target=System.out
 >log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
 >log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p 
%c{1}:%L - %m%n
 >
 >### direct messages to file hibernate.log ###
 >#log4j.appender.file=org.apache.log4j.FileAppender
 >#log4j.appender.file.File=hibernate.log
 >#log4j.appender.file.layout=org.apache.log4j.PatternLayout
 >#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p 
%c{1}:%L - %m%n
 >
 >### set log levels - for more verbose logging change 'info' to 'debug' ###
 >
 >log4j.rootLogger=warn, stdout
 >
 >#log4j.logger.org.hibernate=info
 >log4j.logger.org.hibernate=debug
 >
 >### log HQL query parser activity
 >#log4j.logger.org.hibernate.hql.ast.AST=debug
 >
 >### log just the SQL
 >#log4j.logger.org.hibernate.SQL=debug
 >
 >### log JDBC bind parameters ###
 >log4j.logger.org.hibernate.type=info
 >#log4j.logger.org.hibernate.type=debug
 >
 >### log schema export/update ###
 >log4j.logger.org.hibernate.tool.hbm2ddl=debug
 >
 >
 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 >
 >Then, I made changes to the above properties file, to make the output
 >be logged in a file instead
 >of standard output.
 >
 >as follows upon searching on Google (but the output of the log still
 >goes to standard output instead of a file)
 >
 >### direct log messages to stdout ###
 >#log4j.appender.stdout=org.apache.log4j.ConsoleAppender
 >#log4j.appender.stdout.Target=System.out
 >#log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
 >#log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p
 >%c{1}:%L - %m%n
 >
 >### direct messages to file hibernate.log ###
 >log4j.appender.file=org.apache.log4j.FileAppender
 >log4j.appender.file.File=hibernate.log
 >log4j.appender.file.layout=org.apache.log4j.PatternLayout
 >log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
 >
 >### set log levels - for more verbose logging change 'info' to 'debug' ###
 >
 >#log4j.rootLogger=warn, stdout
 >log4j.rootLogger=warn, file
 >
 >#log4j.logger.org.hibernate=info
 >log4j.logger.org.hibernate=info
 >
 >### log HQL query parser activity
 >#log4j.logger.org.hibernate.hql.ast.AST=debug
 >
 >### log just the SQL
 >#log4j.logger.org.hibernate.SQL=debug
 >
 >### log JDBC bind parameters ###
 >#log4j.logger.org.hibernate.type=info
 >log4j.logger.org.hibernate.type=debug
 >
 >### log schema export/update ###
 >log4j.logger.org.hibernate.tool.hbm2ddl=debug
 >
 >I looked at the example here:
 >http://ideoplex.com/id/386/controlling-hibernate-output-with-log4j 
to make the
 >above change, but I'm confused as to why the log is still being
 >directed to the console rather than hibernate.log file.
 >
 >I plan to read the Log4J manual and understand the various notations
 >used in the properties file.
 >
 >Any help is appreciated.
 >
 >-Regards
 >Rashmi
 >
 >
 >
 >
 >
 >______________________________________________________________________
 >______________
 >Never miss an email again!
 >Yahoo! Toolbar alerts you the instant new Mail arrives.
 >http://tools.search.yahoo.com/toolbar/features/mail/
 >
 >---------------------------------------------------------------------
 >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