Table Of Contents

This Page

contrib Package

contrib Package

Non-essential tools, that seem not to be core functionality.

mail Module

@summary: Sends emails with a “digest” of selected messages @author: Ruben Reifenberg

class rrlog.contrib.mail.CatBuffer(rules, format_line=None)[source]

Bases: object

__call__(jobhist, writer)[source]

The current implementation locks the current thread if a rule applies, to safely buffer it.

__init__(rules, format_line=None)[source]
Parameters:rules – list of rules which decide about the log jobs to send. Use e.g. a tuple of L{CatRule} objects.

If empty, no messages are buffered. rules are processed in the given order. If a rule applies, all subsequent rules are ignored.

_buffer(job, secs)[source]
_calc_deadline(secs_remaining)[source]
deadline_reached()[source]
iter_all_and_clear()[source]
Returns:tuples (cat, linetext)
size()[source]
class rrlog.contrib.mail.CatRule(cats, max_delay_secs=0)[source]

Bases: object

__init__(cats, max_delay_secs=0)[source]
Parameters:
  • max_delay_secs

    Maximum time that a message of that categories can be buffered before sending.

    High values result in less (but bigger) mails. 0 == send each line nearly immediately

    (Note: The worker thread pauses frequently, causing a littly delay always. As a result, multiple messages might be in a mail even with “send immediately”.)

  • cats

    tuple of cats to catch, e.g. (“E”,”S”).

    None == catch any category (could cause high email traffic)

max_delay_secs(cat)[source]
Returns:Max.remaining buffering time for that job. None if rule does not apply.
class rrlog.contrib.mail.SMTPMailer(server, serverpw, to_address, from_address, subject='Log Digest', loginuser=None, charset='latin-1')[source]

Bases: object

Provides a way to send SMTP mails with simple user:password authentication. This mailer has no advanced authentication methods like starttls.

__init__(server, serverpw, to_address, from_address, subject='Log Digest', loginuser=None, charset='latin-1')[source]
Parameters:subject – serves as a default. The mail method may dynamically create a better one.
_content_and_subject(lines)[source]
mail(lines)[source]

Override to use another mail method, e.g. for other SMTP login protocols Override to create other mail contents or subjects (for example, we want to put the cats into the subject line)

class rrlog.contrib.mail.Spooler(mailer, buffer, sleepSecs=10, autostop=False)[source]

Bases: object

__init__(mailer, buffer, sleepSecs=10, autostop=False)[source]

Starts a worker thread which reads buffered lines and sends them when their time has come. :param sleepSecs: Time to sleep between two are-there-new-lines-checks. Set to shorter time if quick reaction is required (for emails probably not needed) :param autostop: When True, the worker thread will check the number of non-daemon threads after each work interval. When only one (itself) is left, it stops automatically. But when there are more threads doing the same trick, explicit stop is required. The worker thread won’t autostop until the message buffer is completely sent (unlike a daemon thread).

_i_am_orphan()[source]
_work()[source]
is_active()[source]
run()[source]
stop()[source]

Sets my stop flag, causing the worker thread to finish after its next working interval. (All remaining buffered lines are sent before exit.)

rrlog.contrib.mail.create_observer_smtp(server, serverpw, from_address, to_address, rules, loginuser=None, format_line=None, subject='Log Digest', charset='latin-1', spooler_autostop=True)[source]

DEPRECATED Use mailnotifier() Note: When using the SMTPMailer, watch out for the different parameter order

Creates a mail notifier with a background worker thread. Convenience method which sets default values appropriate for many use cases. Appends the spooler to the modules spoolers list so that the L{stop_all} function can stop it. :param rules: see L{CatBuffer.__init__} :param spooler_autostop: see L{Spooler.__init__}. Defaults to True, so that explicit stop of the spooler threads is not necessary usually. :returns: An observer object, intended to be added into the observers list of the log.

rrlog.contrib.mail.mailnotifier(mailer, rules, format_line=None, spooler_autostop=True, spooler_sleepsecs=10)[source]

Creates a mail notifier with a background worker thread. Creates a spooler and appends it to the modules spoolers list. :param mailer: Some object with a method mail(lines) See SMTPMailer class for an example, or extend it. :param rules: see L{CatBuffer.__init__} :param spooler_autostop: see L{Spooler.__init__}. Defaults to True, so that explicit stop of the spooler threads is not necessary usually. :param spooler_sleepsecs: see L{Spooler.__init__} :returns: An observer object, intended to be added into the observers list of the log.

rrlog.contrib.mail.now()

[tz] -> new datetime with tz’s local day and time.

rrlog.contrib.mail.stop_all()[source]

Stops all running spooler threads.

richlog Module

@summary: logging classes with a richer interface for convenience. @author: Ruben Reifenberg

class rrlog.contrib.richlog.RichLog1(log)[source]

Bases: object

A wrapper for rrlog.Log. It adds functionality (convenience methods) It cannot be wrapped again (Doesn’t behave exactly like the wrapped log.) @ivar wrapped: the wrapped log object.

__call__(*args, **kwargs)[source]

only delegates to the wrapped log

__init__(log)[source]
Parameters:log – The rrlog.Log to wrap.

Increases the traceOffset of log (+1).

dict(aDict, message='')[source]

logs a dict, each item as a single log msg :param message: Optional log message e.g. to identify the dict

log(*args, **kwargs)[source]

REMOVED: The log.log() is removed. Use log().

trace(message='', use_ex=False)[source]

logs message plus a stacktrace (each stack line as a single log message.) Can use the current trace, of the trace of the last exception. :param use_ex: If False, I use the current stacktrace. If True, I use the existing sys.exc_info().

stackindent Module

@summary: Indent message texts depending on callers stack depth. @author: Ruben Reifenberg

class rrlog.contrib.stackindent.StackIndentFilter(token=' ', msgPrefix=None)[source]

Bases: object

Adjusts itself to zero indention with the first log call. You can re-adjust (tara) with later log calls.

Use log( ..., stackindent_tara=0). This will adjust the current call to be zero-indented.

Use -1 to immediately indent by 1 token etc. (Negative indention is ignored, such lines appear with indent zero.)

__call__(jobhist, writer)[source]
__init__(token=' ', msgPrefix=None)[source]
Parameters:
  • token – The string used to indent one level.
  • msgPrefix

    str. If given, indent only messages

    starting with this prefix. All other messages are ignored (they cannot even trigger a “tara”).

rrlog.contrib.stackindent.createPrintIndentLog(token=' ', format_line=<function format_line at 0x41bded8>, **kwargs)[source]

convenience function for “log to standard out and indent.” By default, the messages are formatted to contain nothing but the message string (no timestamp etc.)

Parameters:token – str, the indention token
Returns:local log
rrlog.contrib.stackindent.format_line(job, lineCount)[source]

The default formatter that removed everything except the pure message