Table Of Contents

This Page

rrlog Package

rrlog Package

rrlog - a Rotating Remote LOG. @author: Ruben Reifenberg

class rrlog.__init__.Log(server, traceOffset=0, msgCountLimit=1000000, stackMax=1, errorHandler=None, catsEnable=None, catsDisable=None, seFilesExclude=None, name=None, extractStack=True)[source]

Bases: object

Instances of this are callable and represent the runtime interface for the application. @ivar stackMax: See L{__init__}, can be modified anytime. @ivar traceOffset: See L{__init__}, can be modified anytime.

__call__(message, cat='', special=None, traceDepth=1, **kwargs)[source]
Parameters:
  • message – String to be logged
  • cat – application specific category, e.g. “E”=Error,”W”=Warning. Default is “”.
  • special ({str: str|int} or None) –

    dict-like object (only the items() -> (k,v)-iter method is required) The items of the “special” dict appear in the Jobs at the server side. Custom observers, filters, writers and formatters can use these.

    Type restrictions: only {str: str|int} is allowed for the dict items (!)

  • traceDepth – Adjusts the starting point of stacktrace logging. Default=1. Typically, you may increase that if you call the log with a wrapping function which should be hidden in the stacktrace. This adjusts the current call only. See traceOffset in L{__init__} for a permanent adjustment.
  • KwargsDeprecated Use the “special” dict only. You can provide any custom kwargs you like. This is sugar for convenience, all kwargs are put into the “special” dict. kwargs items override both items of special dict and sticked items silently.
Returns:

log-client specific message number,starting with 1 (not unique at server side, if multiple log clients are used.)

__init__(server, traceOffset=0, msgCountLimit=1000000, stackMax=1, errorHandler=None, catsEnable=None, catsDisable=None, seFilesExclude=None, name=None, extractStack=True)[source]
Parameters:
  • catsEnable (iterable of str) – None or cat strings, e.g.(“E”,”W”,””). (Remember, the empty cat “” is the default.) If a list is specified, only these cats are logged, all other calls are ignored. If None, all cats are enabled.
  • catsDisable (iterable of str) – All cats in this list are ignored. Default=None. Cannot be used along with catsEnable.
  • traceOffset (int) –

    Adjusts the start point of the logged stack trace.

    Default == 0. Increase to 1 to hide the first call (e.g. if the log is called with a wrapper), and so on. Values too high are silently adjusted to the highest value possible.

  • stackMax (int) – 0==show no stacktrace, 1==log one stack line (the line where log(...) was called), 2==log two stack lines, and so on. Default: 1 (==log callers line and nothing else.) See also: extractStack parameter.
  • errorHandler – Receives any Exception that occurs while logging. (e.g.a connection failure to the log server) If handler is None: No handling, your application will receive any exception occurring inside the log() call. For convenience, you may provide one of these strings: “stderr”,”stdout”,”silent” (case-insensitive). These strings are translated into the appropriate built-in “~ErrorHandler” class.
  • seFilesExclude – filenames to exclude from Stack Extraction None (==nothing to exclude), or a callable that returns True/False when given a filename. When True, the file does NOT appear in the call path. None is acepted instead of False too, just to enable pragmatic ideas like seFilesExclude=re.compile(“foo/bar.*”).search (which exludes all foo/bar* files). Note: The first path element (callers file name - cfn) is never excluded this way. Only the rest of the trace may be “censored”.
  • name (str) – defaults to class name. For individual use (to identify the log object). The log itself does not evaluate it but use it with its __repr__/__str__ method.
  • extractStack (bool) – If False, stack extraction is disabled. This improves performance (can be more than twice), but any stack related functionality will not work (e.g.line indention to visualize call hierarchy).
_createServerData(tb, depth, message, cat, special)[source]
Returns:Tuple for the log server
Parameters:depth (int) – log-internal call depth when the traceback was taken.
_getCallPath(tb, depth)[source]
Returns:path,cfuncname where path = ( (filename,lineno), ...), len >=0 cfuncname is “” if no traceback available, None if no cfuncname exists (log call at module level)
Parameters:depth (int) – log-internal call depth when the traceback was taken.
logging23_handler()[source]

Note that, contrary to the Python logging, the rrlog is not designed/tested for threading.

Returns:Handler for the Python >=2.3 standard logging framework.
off()[source]
on()[source]
set_sticked_items(asdict)[source]

Tip: To obtain the Log instance while using standard logging module, take it from the Logger.handlers list.

Parameters:asdict

key/value pairs, that this Log object will append to every succeeding log call. Similar to the “special” dict but sticky. Previous “sticked data” are replaced.

Example: {“ip”:requests_ip_address}

Call with {} to end sticking data.

class rrlog.__init__.SilentErrorHandler[source]

Bases: object

Use this as errorHandler if you want log errors to disappear silently (e.g.in case of a Log Server Crash). Not recommended (but preferred over an exception in the log() call stopping the application).

handleException(e)[source]
class rrlog.__init__.StderrErrorHandler[source]

Bases: object

Use this as errorHandler if you want to see Errors (in case of a Log Server Crash) in standard error out.

handleException(e)[source]
class rrlog.__init__.StdoutErrorHandler[source]

Bases: object

Use this as errorHandler if you want to see Errors (in case of a Log Server Crash) in standard out. This is not good in case of a CGI web app, because the printout may appear in the web page.

handleException(e)[source]

compile Module

make .pyc files beside the rrlog .py files immediately

environment Module

constants about the environment (SQLAlchemy) available Purpose: provide compatibility with a wide SQLAlchemy version range @author: Ruben Reifenberg

globalconst Module

exception rrlog.globalconst.EnvironmentError[source]

Bases: exceptions.Exception

Something’s wrong with the runtime environment

logging23 Module

@summary: Integration into Python 2.3 logging as a Handler @author: Ruben Reifenberg @var LEVELMAP: 1:1 mapping of single characters (Like “E”) to the level constants of the standard logging module; {logging-level: Category-Character}. You may modify this.

class rrlog.logging23._Handler(log, level=0)[source]

Bases: logging.Handler

__init__(log, level=0)[source]
Parameters:
  • log – Your ready-to-use log object
  • level – One of the ordered standard logging constants (INFO, ERROR etc.)
emit(record)[source]
rrlog.logging23.handler(*args, **kwargs)[source]
rrlog.logging23.seFilesExclude(fname)[source]

callable that exludes logging.__init__ from stack extraction. :returns: True if fname is “logging/__init__.py”

rrlog.logging23.useALogger()[source]

socketclient Module

class rrlog.socketclient.LogServerProxy(host, ports)[source]

Bases: object

__init__(host, ports)[source]
addClient()[source]
log(logdata)[source]
exception rrlog.socketclient.SerializeError[source]

Bases: exceptions.Exception

class rrlog.socketclient._SocketHandler(host, port)[source]

Bases: logging.handlers.SocketHandler

makePickle(record)[source]

Pickles the record in binary format with a length prefix, and returns it ready for transmission across the socket.

ping_seems_possible()[source]

The handlers.SocketHandler should have a valid “sock” Attribute after we sent something. If not, an error occurred. :returns: True a simple method call on the server worked without error

rrlog.socketclient.createClientLog(host='localhost', ports=(9801, ), errorHandler=None, traceOffset=0, stackMax=5, extractStack=True, seFilesExclude=None)[source]
Returns:Log instance

tool Module

@summary: Tools not specific for logging purpose @author: Ruben Reifenberg

class rrlog.tool.ListRotator(list)[source]

Bases: object

Iteriert durch eine gegebene Liste, beginnend mit erstem Element. beginnt im Gegensatz zum Iterator wieder von vorn. @ivar i: index of last returned element

__init__(list)[source]
Parameters:list – len >=1

list needs to be constant (behaviour not defined for later changes)

len()[source]
next()[source]

Not threadsafe. :returns: next list element, rotating :raises IndexError: if list has length 0

class rrlog.tool.StrIndenter(token=' ', offset=0)[source]

Bases: object

Create a String consisting of “depth” identical tokens. Intended for output indention.

__call__(depth)[source]
Returns:string, consisting of the given tokens
__init__(token=' ', offset=0)[source]
Parameters:token – str. The resulting string will consist of this tokens.
tara(depth, tara=0)[source]

set string/indention lengt 0 for the current stack depth :param tara: is added to depth (depth:=depth+tara instead of explicit tara has the same result)

rrlog.tool._cutcount(l, max)[source]

How many elements to cut away from something with len l, when we want restlen+len(decimal-digit-of-cut-count) < max? :rtype: int :returns: count of chars to cut away (cutcount) (can be > l when max is too low)

rrlog.tool.lu2a(unistr, max=50, errorstr='~~~')[source]

Limited Unicode To Ascii (limited: the result length is limited) Intended for ASCII-logging of untrusted (e.g.user input) unicode strings. The length limitation is intended for storage in length-limited ASCII Database fields. :rtype: ASCII str or None :returns: The argument but with: All non-ascii chars replaced by “xhexvalue”. If N chars (of the result string) are thrown away, “[N+]” is appened at the end. :param unistr: Python Unicode or None :param max: >=3, length limit of the RESULT STRING (default 50) :param errorstr: Returned in case max is too low to return the regular result.

rrlog.tool.lu2a_de(unistr, max=50, errorstr='~~~')[source]

Note: In case of unistr containing non-ascii characters, this method gets slow (because it does a python loop over each character.) @see: lu2a Additionally, the german umlauts are replaced by AE,OE... to make it more readable (by the drawback of information loss, of course.)

rrlog.tool.mStrftime(dt, formatStr)[source]
Parameters:
  • dt – datetime.datetime
  • formatStr – strftime format string for dt with an extension: %3N is milliseconds
Returns:

str, made by dt.strftime

rrlog.tool.mail_smtp(server, serverpw, to_address, from_address, loginuser, subject, content, charset='latin-1')[source]

Send subject/content, as latin-1 by default String-Parameter; subject/content may be unicode or str.

Returns:

None

Parameters:
  • server – e.g..”mail.gmx.net”
  • serverpw – SMTP server password
rrlog.tool.tm_strftime(format, t, ms)[source]
Parameters:
  • t – 9-tuple, as returned by time.localtime()
  • format – strftime format string with an extension: %3N is milliseconds
  • ms – microseconds as int (0..999)
Returns:

str, made by time.strftime

rrlog.tool.traceToShortStr(maxLines=3, exc_info=None, use_cr=True)[source]
Parameters:
  • exc_info – as given by sys.exc_info(). If None, it is obtained by calling sys.exc_info
  • use_cr – If True, “n” is used between the path lines. Otherwise, “<” will separate the lines.
Returns:

short str describing the current ex.stacktrace (end-first), “” if there is no current exc.

xmlrpc Module

@summary: The client (i.e.application) side of an XMLRPC log connection. @author: Ruben Reifenberg

class rrlog.xmlrpc.LogServerProxy(host, ports)[source]

Bases: object

First method call must be addClient, since this establishes the server connection.

__init__(host, ports)[source]
addClient()[source]

Does the connection to the server.

log(logdata)[source]
exception rrlog.xmlrpc.XMLRPCConnectionException(txt, msgid)[source]

Bases: rrlog.xmlrpc.XMLRPCLogException

Logging went wrong because of a connection issue.

exception rrlog.xmlrpc.XMLRPCLogException(txt, msgid)[source]

Bases: exceptions.Exception

__init__(txt, msgid)[source]
Parameters:
  • txt – some ascii error explanation text
  • msgid – msgid of the log-msg that caused the problem.
exception rrlog.xmlrpc.XMLRPCServerException(txt, msgid)[source]

Bases: rrlog.xmlrpc.XMLRPCLogException

Logging went wrong because the server had a problem.

rrlog.xmlrpc.connect(host, ports)[source]

Steve Holden,http://www.velocityreviews.com/forums/t539476-xml-rpc-timeout.html: The easiest way is to use socket.setdefaulttimeout() to establish a longer timeout period for all sockets, I guess. It’s difficult to establish different timeouts for individual sockets when they aren’t opened directly by your own code (though each socket does also have a method to set its timeout period). — Sh...We must not modify sockets globally in a library like rrlog. We can’t use signal, since we usualy don’t have the main thread. We can’t rely on a specific Python version and OS which would enable more solutions. The xmlrpc lib should be more cooperative :-( => No timeout solution currently.

rrlog.xmlrpc.createClientLog(host='localhost', ports=(9804, ), errorHandler=None, traceOffset=0, stackMax=5, extractStack=True, seFilesExclude=None)[source]
Returns:Log instance
rrlog.xmlrpc.loglog(msg, cat='')[source]

Deactivated, activate for debugging only. Here does the log logging itself.