HWRF  trunk@4391
Classes | Functions | Variables
produtil.log Namespace Reference

Configures logging. More...

Detailed Description

Configures logging.

This module configures logging for stdout, stderr and the jlogfile. It also contains the jlogger, a logger.Logger object that is used to log directly to the jlogfile, and jlogdomain: a string name of the logger domain for the jlogfile.

Classes

class  JLogFormatter
 This subclass of MasterLogFormatter does not include exception information in the log file. More...
 
class  JLogHandler
 Custom LogHandler for the jlogfile. More...
 
class  MasterLogFormatter
 This is a custom log formatter that inserts the thread or process (logthread) that generated the log message. More...
 
class  MasterLogHandler
 Custom LogHandler for the master process of a multi-process job. More...
 
class  ThreadLogger
 Custom logging.Logger that inserts thread information. More...
 

Functions

def postmsg (message)
 Sends the message to the jlogfile logging stream at level INFO. More...
 
def set_jlogfile (filename)
 Tells the jlogger to log to the specified file instead of the current jlogfile. More...
 
def stdout_is_stderr ()
 Returns True if it can determine that stdout and stderr are the same file or terminal. More...
 
def mpi_redirect
 Used to split to multiple logging streams. More...
 
def configureLogging
 Configures log output to stderr, stdout and the jlogfile. More...
 

Variables

list __all__
 Symbols epxorted by "from produtil.log import *". More...
 
string logthread = ''
 string for log messages to indicate thread number/name
 
string jlogdomain = 'jlog'
 Logging domain for the jlogfile.
 
tuple jlogger = logging.getLogger(jlogdomain)
 A logging.Logger for the jlogdomain.
 
 jloghandler = None
 A logging.LogHandler for the jlogger.
 

Function Documentation

def produtil.log.configureLogging (   jlogfile = None,
  level = logging.INFO,
  jloglevel = logging.INFO,
  japplevel = logging.ERROR,
  eloglevel = logging.WARNING,
  ologlevel = logging.NOTSET,
  thread_logger = False 
)

Configures log output to stderr, stdout and the jlogfile.

Configures log file locations and logging levels for all streams.

Note
Important notes when choosing levels:
  • level - sets the global minimum log level. Anything below this level will be discarded regardless of other settings.
  • jloglevel - this limit is applied before japplevel
Parameters
jlogfilepath to the jlogfile. Default: use os.environ('jlogfile') if set. Otherwise, stderr.
levelminimum logging level globally. Set to INFO by default. Change this to logging.DEBUG if you're debugging the program.
jloglevelminimum logging level to send to jlogfile
japplevelminimum logging level to send to jlogfile from all domains except that specified in jlogdomain. Be careful when changing this as it logs directly to the WCOSS-wide jlogfile in operations.
eloglevelminimum logging level to send to stderr from ALL logs Set to None to disable stderr logging
ologlevelminimum logging level to send to stdout from ALL logs Default: logging.NOTSET (no filtering) Set to None to disable stdout logging.
thread_loggerTrue to include the thread name in log messages.

Definition at line 310 of file log.py.

Referenced by produtil.log.mpi_redirect(), and produtil.setup.setup().

def produtil.log.mpi_redirect (   threadname,
  stderrfile,
  stdoutfile,
  masterlevel = logging.WARNING,
  openmode = None,
  logger = None 
)

Used to split to multiple logging streams.

When the Python script splits itself into multiple processes via MPI, this function is called to redirect stdout to stdoutfile, stderr to stderrfile, and produce a new logging stream to the original stderr, with a logging level set to masterlevel. That new logging stream is called the "master log" and will receive any messages at level masterlevel or higher, and any messages sent to the jlogdomain.

This can also be used to redirect ONLY stdout, in which case no master logging stream is set up. That is requested by stderrfile=None.

Parameters
threadnamethe name of this process for logging purposes
stderrfilefile to receive stderr
stdoutfilefile to receive stdout
masterlevellog level to send to master log stream
openmodeinteger mode to use when opening files
loggera logging.Logger for logging errors while splitting the log stream.

Definition at line 226 of file log.py.

Referenced by produtil.log.JLogHandler.set_jlogfile(), and scripts.exhwrf_products.slave_main().

def produtil.log.postmsg (   message)

Sends the message to the jlogfile logging stream at level INFO.

This is identical to:

1 jlogger.info(message).
Parameters
messagethe message to log.

Definition at line 46 of file log.py.

Referenced by scripts.exhwrf_forecast.doit(), hwrf.launcher.HWRFLauncher.gen_vitals(), scripts.exhwrf_ocean_init.main(), scripts.exhwrf_launch.main(), and hwrf.launcher.HWRFLauncher.tcautoseed().

def produtil.log.set_jlogfile (   filename)

Tells the jlogger to log to the specified file instead of the current jlogfile.

Also updates the jlogfile environment variable. The argument must be a filename.

Parameters
filenamethe new jlogfile

Definition at line 56 of file log.py.

def produtil.log.stdout_is_stderr ( )

Returns True if it can determine that stdout and stderr are the same file or terminal.

Returns False if it can determine they are not, or if the result is inconclusive.

Definition at line 119 of file log.py.

Referenced by produtil.log.configureLogging().

Variable Documentation

produtil.log.__all__
Initial value:
1 = [ 'configureLogging','jlogger','jlogdomain','postmsg',
2  'MasterLogFormatter','JLogFormatter','stdout_is_stderr',
3  'MasterLogHandler','JLogHandler','set_jlogfile' ]

Symbols epxorted by "from produtil.log import *".

Definition at line 10 of file log.py.