Package rrlog :: Package server :: Class LogServer
[hide private]
[frames] | no frames]

Class LogServer

source code

object --+
         |
        LogServer

This can (but must not be) in the application process.

Instance Methods [hide private]
 
__init__(self, writer, filters=None, observers=None, cfnMode=1, tsFormat=None, initMsg=False, jobhistSize=100, oie=True)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
addObserver(self, observer)
appends the observer at the end of the observers list
source code
 
format_fname(self, name)
file name in the configured format (cfnMode).
source code
str
pathAsStr(self, path, imin=0)
Returns: call path, formatted as str, Empty str if path is empty
source code
 
addClient(self)
Not thread safe
source code
str
_timeStr(self, dt)
Returns: readable time info, based on my _tsFormat
source code
 
log(self, pid, clientid, msgid, msg, special, cat, path, tblen, cfunc) source code
 
logJob(self, job, oie) source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Variables [hide private]
  CLIENTID_MAX = 32767
  CFN_SHORT = 1
  CFN_FULL = 2
  CAT_INTERNALERROR = 'I'
Default "I".
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, writer, filters=None, observers=None, cfnMode=1, tsFormat=None, initMsg=False, jobhistSize=100, oie=True)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Parameters:
  • cfnMode - One of the MODE...constants. CFN_SHORT: Caller File Names minimal,i.e.file name without directory path(=Default) CFN_FULL: Caller File Names with full file path) Default is CFN_SHORT
  • tsFormat - strftime-format string with an extension: use %3N for milliseconds. [Year..second are: %Y/%y,%m,%d,%H,%M,%S] None for no timestamps. For convenience: The String "std1" is interpreted as "%H:%M.%S;%3N". The String "std2" is interpreted as "%m/%d %H:%M.%S".
  • observers - list of callables, called with args: jobhist, writer. Called each time after(!) a message was written. writer is the specific writer (depends on DB/file/Stdout modus.) jobhist are the N last message-jobs, with the latests at [-1]. The size N of the jobhist is limited by jobhistSize. Increase jobhistSize if your observer needs to see a large job history. The observers are processed in the given order. You can modify job content for following observers, without affecting the log (since the observers are called after the line is written.) For compatibility: An observer can also have an observe() method. If available, this is used (instead of __call__)
  • filters - list of callable objects, analogous to observers. But filters are called before logging. When they modify the message, the change gets visible in the log.
  • initMsg - if True, write a short and witless initial message to test the LogWriter
  • jobhistSize - The count of recent messages that are available as a list (these may be read by observers). Default=100
  • oie - Observe Internal Error; defines how to handle errors occurring in the observers and filters. If True, in case of an internal error in an observer/filter, all observers/filters receive an additional message describing the error. If False, the observers/filters are not notified about the internal error (but the internal error still appears in the main log.)
Raises:
  • AssertionError - if an observer is >1 times in the list
  • AssertionError - if a filter is >1 times in the list
Overrides: object.__init__

Attention: The logged time stamps can be significantly later than the log() call of your application, because time is taken by the LogServer which may be remote connected.

format_fname(self, name)

source code 

file name in the configured format (cfnMode).

Parameters:
  • name - File file name incl. path, or None
Returns:
String,men-Readable Callers File Name (None is name was None)

pathAsStr(self, path, imin=0)

source code 
Parameters:
  • path - iterable
  • imin - min.index of path to use.
Returns: str
call path, formatted as str, Empty str if path is empty

addClient(self)

source code 

Not thread safe

Returns:
unique client id, >=1. Numbers start with 1 again if CLIENTID_MAX is exceeded.

_timeStr(self, dt)

source code 
Returns: str
readable time info, based on my _tsFormat

log(self, pid, clientid, msgid, msg, special, cat, path, tblen, cfunc)

source code 
Parameters:
  • msg - ASCII, the log message
  • cat - An application-specific category string of length 1. Suggesting convention is "E" for error,"W" for Warning, "I" for internal error... None for no category.
  • pid - clients os - process id
  • clientid - int, the id that the calling client obtained with registration.
  • msgid - int, recommended to be unique for this client (I do not check if unique.)
  • path - list, len>=0, each item = (int cfn,str cln)
  • cfunc - str,callers function name (additionally to cfn,cln) or None

Class Variable Details [hide private]

CAT_INTERNALERROR

Default "I". This is used as "cat" when I write a log message about a logging failure (if possible)
Value:
'I'