Showing posts with label log4j. Show all posts
Showing posts with label log4j. Show all posts

Monday, September 19, 2016

Hibernate : log4j.xml logging category and binding parameters




down voteaccepted
Here's the list of logger categories:
Category                    Function

org.hibernate.SQL           Log all SQL DML statements as they are executed
org.hibernate.type          Log all JDBC parameters
org.hibernate.tool.hbm2ddl  Log all SQL DDL statements as they are executed
org.hibernate.pretty        Log the state of all entities (max 20 entities) associated with the session at flush time
org.hibernate.cache         Log all second-level cache activity
org.hibernate.transaction   Log transaction related activity
org.hibernate.jdbc          Log all JDBC resource acquisition
org.hibernate.hql.ast.AST   Log HQL and SQL ASTs during query parsing
org.hibernate.secure        Log all JAAS authorization requests
org.hibernate               Log everything (a lot of information, but very useful for troubleshooting) 
Formatted for pasting into a log4j XML configuration file:
<!-- Log all SQL DML statements as they are executed -->
<Logger name="org.hibernate.SQL" level="debug" />
<!-- Log all JDBC parameters -->
<Logger name="org.hibernate.type" level="debug" />
<!-- Log all SQL DDL statements as they are executed -->
<Logger name="org.hibernate.tool.hbm2ddl" level="debug" />
<!-- Log the state of all entities (max 20 entities) associated with the session at flush time -->
<Logger name="org.hibernate.pretty" level="debug" />
<!-- Log all second-level cache activity -->
<Logger name="org.hibernate.cache" level="debug" />
<!-- Log transaction related activity -->
<Logger name="org.hibernate.transaction" level="debug" />
<!-- Log all JDBC resource acquisition -->
<Logger name="org.hibernate.jdbc" level="debug" />
<!-- Log HQL and SQL ASTs during query parsing -->
<Logger name="org.hibernate.hql.ast.AST" level="debug" />
<!-- Log all JAAS authorization requests -->
<Logger name="org.hibernate.secure" level="debug" />
<!-- Log everything (a lot of information, but very useful for troubleshooting) -->
<Logger name="org.hibernate" level="debug" />
NB: Most of the loggers use the DEBUG level, however org.hibernate.type uses TRACE. In previous versions of Hibernate org.hibernate.type also used DEBUG, but as of Hibernate 3 you must set the level to TRACE (or ALL) in order to see the JDBC parameter binding logging.
And a category is specified as such:
<logger name="org.hibernate">
    <level value="ALL" />
    <appender-ref ref="FILE"/>
</logger>
It must be placed before the root element.

Thursday, July 7, 2016

Log4j : logging one package to log file and another package to another logfile ... on different levels.

Sending the only com.dashboard.process [debug] information to a file.... AND
Sending the info messages of com.dashboard [info] information to another file including the info
messages of com.dashboard.process.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//LOGGER" "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
<log4j:configuration>
 <!-- an appender is an output destination, such as the console or a file; names of appenders are arbitrarily chosen -->
 <appender name="stdout" class="org.apache.log4j.ConsoleAppender">
  <layout class="org.apache.log4j.EnhancedPatternLayout">
   <param name="ConversionPattern" value="%d %-5p %c{1} (%F:%L) %m%n" />

  </layout>
 </appender>
 <appender name="stderr" class="org.apache.log4j.ConsoleAppender">
  <param name="target" value="System.err" />
  <layout class="org.apache.log4j.PatternLayout">
   <param name="ConversionPattern" value="%-5p %d [%t][%F:%L] : %m%n" />
  </layout>
 </appender>
 <appender name="file" class="org.apache.log4j.RollingFileAppender">
  <param name="File" value="${log4j.dir}/dashboard.log" />
  <param name="MaxFileSize" value="2Mb" />
  <param name="MaxBackupIndex" value="5" />
  <layout class="org.apache.log4j.PatternLayout">
   <param name="ConversionPattern" value="%-5p %d [%t][%F:%L] : %m%n" />
  </layout>
 </appender>
 <appender name="harvestor" class="org.apache.log4j.RollingFileAppender">
  <param name="File" value="${log4j.dir}/dashboard-harvest.log" />
  <param name="MaxFileSize" value="2Mb" />
  <param name="MaxBackupIndex" value="5" />
  <layout class="org.apache.log4j.PatternLayout">
   <param name="ConversionPattern" value="%-5p %d [%t][%F:%L] : %m%n" />
  </layout>
 </appender>

 <category name="org.springframework.ui.velocity">
  <priority value="WARN" />
 </category>
 <category name="org.springframework.web.servlet.view.velocity">
  <priority value="WARN" />
 </category>
 <category name="org.apache.velocity.runtime">
  <priority value="WARN" />
 </category>
 <category name="org.springframework.web.util" additivity="false">
  <priority value="WARN" />
 </category>
 <category name="org.eclipse.jetty.servlet">
  <priority value="WARN" />
 </category>
 <category name="com.dashboard.process" additivity="false">
  <priority value="DEBUG"></priority>
 </category>
 <category name="com.dashboard" additivity="true">
  <priority value="INFO"></priority>
 </category>

 <!-- the root category -->
 <!-- all log messages of level "debug" or higher will be logged, unless defined otherwise all log messages will be logged to the appender 
  "stdout", unless defined otherwise -->
  
  <logger name="com.dashboard">
    <level value="INFO" />
    <appender-ref ref="file" />
  </logger>

 <logger name="com.dashboard.process" additivity="false">
  <level value="DEBUG" />
  <appender-ref ref="harvestor" />
 </logger>


</log4j:configuration>


Wednesday, March 14, 2012

Please Log Everything with a Log4j.xml to my screen....

It's sad to put this down however every time I need it, I forget the syntax... whats the proper syntax to answer my "please log everything to the screen" question...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//LOGGER" "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
<log4j:configuration>
    <!-- 
         an appender is an output destination, such as the console or a file;
         names of appenders are arbitrarily chosen
    -->
    <appender name="stdout" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
   <param name="ConversionPattern"  value="%d %-5p %c (%F:%L) %m%n"/>  

        </layout>
    </appender>
     <appender name="stderr" class="org.apache.log4j.ConsoleAppender">
        <param name="target" value="System.err"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%-5p %d [%t][%F:%L] : %m%n" />
        </layout>
    </appender>
 
    <!-- the root category -->
        <!-- 
            all log messages of level "debug" or higher will be logged, unless defined otherwise 
            all log messages will be logged to the appender "stdout", unless defined otherwise 
        -->
<root>
        <priority value="ALL"/>
        <appender-ref ref="stdout" />
        <appender-ref ref="stderr" />
    </root>
</log4j:configuration>