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)
|