Table Of Contents

Next topic

Examples for rrlog

This Page

Manual for rrlog

A Remote Rotating Log for Python that works instantly


Download from Sourceforge | Change History

Overview

rrlog is a pure Python logging tool. It is for both debugging and production, and logs on a website with reasonable traffic for some years now. It supports:

  • logging into ASCII text files
  • Log Rotation
  • Remote Logging (one or more client applications with one log server)
  • logging into a database, both remote or locally (with any database supported by SqlAlchemy)
  • Stacktrace logging (debug feature)
  • EMail notification - for important message categories
  • Quick integration with the python standard logging (as a Handler)

Most battery types included

Everything works instantly except database logging (that needs the SqlAlchemy package in your python path).

Where it sucks

There are at least the following caveats:

  • It is designed and tested with a multi-process but not multithreaded application. Notice that nobody did care for a threaded environment yet. It may work threaded if you use the remote logging way. See Multiprocess & Multithread
  • As the low version number suggests, the API may still receive backwards-incompatible changes.
  • The integration into standard logging is incomplete. See Use Pythons standard logging
  • rrlog still lives in the grey-bearded Python 2 world. There is an experimental Python 3 version (see Requirements) but that wasn’t in productive use yet.

Major improvements likely to come next are:

Basic usage

Create and use a log object

  1. call a “create...()” function to get a log object

    Various create() functions are available. These make different log configurations, e.g. for local or remote logging, into a file or a database etc. For the create...() functions available, look into the Basic Examples

  2. That log object is callable. Call it with these arguments:

    • the log message (str)
    • an optional “category”, which is a single character. That “category” rawly corresponds with the “info”,”debug”,”warn”... levels of the standard logging.

Example:

log("Uuups!","E")

That log object can be used as it is. Alternatively, you may want to Use Pythons standard logging. The log can be simply integrated as a handler there.

There are more arguments for the log() call, as well as customizations. See Basic Examples, More features, or the rrlog.Log.__call__() docstring.

The category

The meaning of the optional category (here: “E”) is up to you, i.e. application specific. By recommended convention, “E” indicates an Error, “W” a warning.

Custom categories can fit our specific needs. For example, “S” may report security relevant messages, like someone trying strange URLs on your website. “U” may mark significant user actions that track the way your application is used. “M” might say “a user wrote a message in your contact formular”. By default, these category characters appear leftmost in each logged line (which is configurable).

We can later use that category to extract a log file summary, e.g. for the specific purpose “watch the user behaviour”. rrlog can also Send mails for selected categories. For example, we may want emails for security relevant messages. Or, with every text a user typed into the contact formular, we log an “M” message. The rrlog can immediately send an email with that text content.

Now for something completely different ...

Requirements

When using database logging, the SQLAlchemy library is required. File logging needs no additional library.

Tested environment:

  • Python 2.7 on 64Bit Linux
  • SQLAlchemy 0.7.8

Only this environment is tested. But we aim to minimize dependency trouble by supporting a wide range of Python and SQLAlchemy versions. There’s a wide version range expected to work:

  • SQLAlchemy: all >= 0.3.2
  • Python: all from 2.4 to 2.7.

(Anyway, with database logging, a newer SQLAlchemy may require a newer Python.)

If some of these “supported versions” don’t work, it is considered a bug. Please tell (Contact)

Python 3 You may already try the experimental lib3k/ directory (instead of lib/). This is made by the 2to3 tool of Python.

Contact

Bug reports, improvements ...

Mail to rrlog at reifenberg.de

Or see http://www.reifenberg.de/rrlog/ or the sourceforge site Sourceforge

License (FreeBSD, MIT)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1. LICENSE FOR THIS SOFTWARE EXCEPT FOR BUNDLED SOFTWARE
The following license (FreeBSD) applies to all of this software, 
 except for the bundled "simplejson" software package.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


Copyright (c) 2007 Ruben Reifenberg.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: 

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
   
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution. 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2. LICENSE FOR BUNDLED SOFTWARE
The following license applies to the "simplejson" package 
 which is located in the "fbsimplejson" subdirectory.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


Copyright (c) 2006 Bob Ippolito

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Indices and tables