commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Jakarta-commons Wiki] Update of "SCXML/Tutorials/Logging" by NestorUrquiza
Date Fri, 17 Nov 2006 19:37:25 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Jakarta-commons Wiki" for change notification.

The following page has been changed by NestorUrquiza:
http://wiki.apache.org/jakarta-commons/SCXML/Tutorials/Logging

------------------------------------------------------------------------------
  
  
  {{{
-                 logger =
- LogManager.exists("scxml.app.log");
+     logger = LogManager.exists("scxml.app.log");
-                 if (logger == null)
+     if (logger == null)
-                 {
-                     Logger logger =
- Logger.getLogger("scxml.app.log");
+     {
+         Logger logger = Logger.getLogger("scxml.app.log");
+         Logger rootLogger = Logger.getRootLogger();
+         SimpleLayout rootLayout = new SimpleLayout();
+         Appender rootAppender = new ConsoleAppender();
+         rootLogger.addAppender(rootAppender);
+         rootLogger.setLevel(Level.OFF);
  
-                     // Prepare log engine for
- commons-scxml
-                     // We need to provide
- commons-scxml package with a standard
- 		    //By default do not log anything that uses
- commons-logging
-                     Logger rootLogger =
- Logger.getRootLogger();
-                     SimpleLayout rootLayout = new
- SimpleLayout();
-                     Appender rootAppender = new
- ConsoleAppender();
-                    
- rootLogger.addAppender(rootAppender);
-                     rootLogger.setLevel(Level.OFF);
- 
- 		    //Specific layout pattern for custom application
+ 	//Specific layout pattern for custom application
+         String pattern = "%d{yyyy/MM/dd HH:mm:ss.SSS} @ " + Constants.LOG_HINT + " @ SCXML
Engine @ %m%n";
+         PatternLayout layout = new PatternLayout(pattern);
-                     String pattern = "%d{yyyy/MM/dd
- HH:mm:ss.SSS} @ "
-                             + Constants.LOG_HINT + " @
- SCXML Engine @ %m%n";
-                     PatternLayout layout = new
- PatternLayout(pattern);
-                     boolean append = true;
+         boolean append = true;
-                     boolean bufferedIO = false;
+         boolean bufferedIO = false;
-                     int bufferSize = 10;
+         int bufferSize = 10;
-                     String filename =
- "completePathOfYourFileNameAddingTimestampToNameForExample.log";
+         String filename = "completePathOfYourFileNameAddingTimestampToNameForExample.log";
-                     if
- (logger.getAppender("scxml.app.appdr") == null)
+         if(logger.getAppender("scxml.app.appdr") == null)
+             {
+                 FileAppender appdr = null;
+                 try
                      {
+                         appdr = new FileAppender(layout, filename, append, bufferedIO, bufferSize);
+                         appdr.setImmediateFlush(true);
+                         appdr.setName("scxml.app.appdr");
-                         // WriterAppender appdr =
- null;
-                         FileAppender appdr = null;
- 
-                         try
-                         {
-                             appdr = new
- FileAppender(layout, filename, append,
-                                     bufferedIO,
- bufferSize);
-                            
- appdr.setImmediateFlush(true);
-                            
- appdr.setName("scxml.app.appdr");
-                         }
+                     }
-                         catch (IOException e)
+                     catch (IOException e)
-                         {
+                     {
-                             //deal with it.
+                         //deal with it.
-                         }
+                     }
                          logger.addAppender(appdr);
                          logger.setLevel(Level.INFO);
                          logger.setAdditivity(false);
                      }
                  }
+         }
+     }
  }}} 
  
  With the code above you will be able to obtain the
  info messages from Var and Assign needed to debug what is going on inside the State Machine
Engine (Using last version of commons-logging -1.1- and Log4J -1.2.14- the TRACE comes up
like a DEBUG message so at least for these versions it makes sense to use INFO instead):
  
  For Var:
- 
+ {{{
  String msg = "Var." + name + "=" + varStr;
          if( appLog.isInfoEnabled() )
             appLog.info( msg );
- 
+ }}}
  
  Warning: With the above Log4J version you should avoid using the same file to log your custom
System messages and the ones from commons-SCXML if your System does not use commons-logging
as well. Otherwise you might experiment some flushing problems resulting in trace lines missing
in the output. There are several posts related to this issue and there is no a clear and homegeneous
solution about it.
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message