metamod:logging

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
metamod:logging [2010-07-07 08:08:36]
oysteint Added syntax highlighting to the Perl Synopsis
metamod:logging [2022-05-31 09:29:32] (current)
Line 20: Line 20:
  
 # 2. Use the Metamod::Config object # 2. Use the Metamod::Config object
 +use Metamod::Config;
 my $config = Metamod::Config->new(); my $config = Metamod::Config->new();
 $config->initLogger();  $config->initLogger(); 
  
 # 3. Use the static class function # 3. Use the static class function
 +use Metamod::Config;
 Metamod::Config::staticInitLogger($path_to_master_config); # or Metamod::Config::staticInitLogger(); Metamod::Config::staticInitLogger($path_to_master_config); # or Metamod::Config::staticInitLogger();
        
 #after initialisation #after initialisation
-use Log::Log4perl qw(get_logger);+use Log::Log4perl qw(get_logger); #this line can be before init as well
      
 my $logger = get_logger($category); my $logger = get_logger($category);
-$logger->error('something wrong just happend');+$logger->error("something wrong just happend\n"); # remember \n
 </code> </code>
      
 PHP: PHP:
    
 +<code php>
 +<?php
 +  # There are three possible ways to initialise the logger
  
 +  # 1. Initialise the default config
 +  require_once("../funcs/mmConfig.inc");
 +
 +  $mmConfig->initLogger(); # $mmConfig is created when mmConfig.inc is parsed
 + 
 +  # 2. Initialise using a different config
 +  require_once("../funcs/mmConfig.inc"); 
 +  $otherConfig = new MMConfig($path_to_other_config);
 +  $otherConfig->initLogger();
 + 
 +  # 3. Initialise using a static function that is basically option 2. reduced to one statement
 +  require_once("../funcs/mmConfig.inc"); 
 +  $otherConfig = MMConfig::getInstanceWithLogger();
 + 
 +  # after the logger is initialised you can do this
 +  # Note that you don't need to include the log4php library as that has already been done 
 +  $logger = Logger::getLogger( $category );
 +  $logger->info( 'Loggmelding' );    
 +
 +?>
 +</code>
  
 ===== Configuration ===== ===== Configuration =====
Line 52: Line 78:
  
   log4perl.logger.metamod.search=DEBUG, SEARCH_LOGGER   log4perl.logger.metamod.search=DEBUG, SEARCH_LOGGER
 +  # prevent garbage from reaching the root logger
 +  log4perl.additivity.metamod.search=0
   log4perl.appender.SEARCH_LOGGER=Log::Log4perl::Appender::File   log4perl.appender.SEARCH_LOGGER=Log::Log4perl::Appender::File
   log4perl.appender.SEARCH_LOGGER.filename = /some/file   log4perl.appender.SEARCH_LOGGER.filename = /some/file
   log4perl.appender.SEARCH_LOGGER.layout=Log::Log4perl::Layout::PatternLayout   log4perl.appender.SEARCH_LOGGER.layout=Log::Log4perl::Layout::PatternLayout
   log4perl.appender.SEARCH_LOGGER.layout.ConversionPattern=%F on line: %L msg: %m%n   log4perl.appender.SEARCH_LOGGER.layout.ConversionPattern=%F on line: %L msg: %m%n
-  # prevent garbage from reaching the root logger + 
-  log4perl.appender.SEARCH_LOGGER.additivity=0+==== Example screen appender ==== 
 + 
 +The following configuration will send all log messages to the screen. 
 + 
 +  log4perl.rootLogger=DEBUG, SCREEN 
 +  log4perl.appender.SCREEN=Log::Log4perl::Appender::Screen 
 +  log4perl.appender.SCREEN.stderr = 1 
 +  log4perl.appender.SCREEN.layout=Log::Log4perl::Layout::PatternLayout 
 +  log4perl.appender.SCREEN.layout.ConversionPattern=[%p] %c %m in %F at line %L%n
  
 ===== Levels ===== ===== Levels =====
Line 65: Line 101:
   * FATAL: requires instant human assistance (IT operations). For instance full disks, lack of connection to database servers, file servers or LDAP.   * FATAL: requires instant human assistance (IT operations). For instance full disks, lack of connection to database servers, file servers or LDAP.
   * ERROR: serious error, but isolated to current task/request. Does not affect entire METAMOD instance. IT operations should be notified.   * ERROR: serious error, but isolated to current task/request. Does not affect entire METAMOD instance. IT operations should be notified.
 +    * Exceptions, even if caught later
   * WARNING: Might be an error, but not necessarily. Should be looked at to see if it is an actual problem.   * WARNING: Might be an error, but not necessarily. Should be looked at to see if it is an actual problem.
-  * INFO: Used to track main application use in production. For instance tracking user log inuploads, metadata parsing info and other statistics+    * milder Exceptions, usually caught 
 +  * INFO: Used to track main application use in production
 +    * tracking user 
 +      * log in 
 +      * log out 
 +      * generate/update directories 
 +    * tracking of data: 
 +      * uploads (ftp/http (which user?)) 
 +      * moving 
 +      * deletion 
 +    * tracking of metadata 
 +      * source (ncdigestharvest), ownertag 
 +      * installing/changing xml-files 
 +      * changes of xmd-metadata (which user?) 
 +      * uploading to search-database(s) 
 +    *  other statistics?
   * DEBUG: Free to be used by the developers as they see fit during development. DEBUG logging should rarely be used in production.   * DEBUG: Free to be used by the developers as they see fit during development. DEBUG logging should rarely be used in production.
  
  • metamod/logging.1278490116.txt.gz
  • Last modified: 2022-05-31 09:23:19
  • (external edit)