Package warn
[hide private]
[frames] | no frames]

Package warn

source code

Classes [hide private]
  FileWriter
  SyslogWriter
  Warn
Functions [hide private]
 
logger_simple(logname, string)
A simple output to the logname log
source code
 
logger_create_by_function(logid, logsplitter, openfun=None)
Creates a logger function (a closure) With |logid| name (to the set the output filename) and a function that choose the a tuple of log names to be used by call (|logsplitter|).
source code
 
_MAIN_LOG_FUNCTION(logname, string)
A simple output to the logname log
source code
 
set_main_log_directory(dirname)
The main log directory.
source code
 
set_main_log_function(logger)
Initialices the global logger, this is the core of the warn module And it can be used to perform fancy splitted logs, like log by session, user, module, spyro objects, by network address, by time, by day, etc.
source code
 
debug(*args)
Shows the args on the stderr
source code
 
log(*args)
Shows the args on a log
source code
 
warn(*args)
Shows |args| as warning, and print the last exception catched
source code
 
stack(*args)
Shows |args| as warning, and print the stack of current caller
source code
 
halt(*args)
Displays |args|, print the last_exception and exits with code 127
source code
 
write(string)
Output for loggin, append the current time, the name of the log, and the pid
source code
 
_write(string)
Direct write to the output
source code
Variables [hide private]
  output = {'PID 22635': <epydoc.docintrospecter._DevNull instan...
  _MAIN_LOG_DIRECTORY = '.'
  _name = 'PID 22635'
  _w = Warn(_name, outfile= sys.stderr)
Function Details [hide private]

logger_create_by_function(logid, logsplitter, openfun=None)

source code 
Creates a logger function (a closure)
With |logid| name (to the set the output filename) and a function that choose the
a tuple of log names to be used by call (|logsplitter|). The output files will be opened
using the function |openfun|(logid, logname) and must return a file like object
(only write method is needed)
if |openfun| is None every file is opened in append and binary mode and
    output filenames are ${main-log-directory}/log.${logid}.${logname}
    Where ${main-log-directory} can be set with the function set_main_log_directory
       ${logid} It the logid gived to this function
       ${logname} It's the returned value of the logsplitter function

------------------------
For example:
    logger = logger_create_by_function("by-date", lambda x,y: (time.strftime("%y-%m"),))
    logger = logger_create_by_function("spyro-user", lambda x,y: (spyro.getrequest()['auth'][0],)) # Using the SPyRO's Module
    logger = logger_create_by_function("spyro-obj", lambda x,y: (spyro.getrequest()['objname'],))# Using the SPyRO's Module
    logger = logger_create_by_function("log-ip", lambda x,y: (shttp.http.getrequest()['HTTP_REMOTE_ADDR'],)) # Using the SPyRO's shttp Module
    set_main_log_function(logger)

The exact prototype of |logsplitter|
iterableobject logsplitter(str logid, str logname)

Note: The opened files are never closed, if you need to close them, use the
dictionary warn.Warn.outputs

key: logname (not logid), value: output file

------------------------------
If  logsplitter raises an exception (like KeyError for unknown logs or a failed log name resolution)
the default log is used (logger_simple)

set_main_log_directory(dirname)

source code 
The main log directory. For default loggers

set_main_log_function(logger)

source code 
Initialices the global logger, this is the core of the warn module
And it can be used to perform fancy splitted logs, like log by session,
user, module, spyro objects, by network address, by time, by day, etc.

|logger| The function logger. It can be any object that can be called.
The prototype must be:

void logger(logname, logdata)

    Where logname is the name of the log
          logdata is the data to be logged


Variables Details [hide private]

output

Value:
{}