Table Of Contents

Previous topic

Examples for rrlog

Next topic

Examples for rrlog

This Page

Examples for rrlog

A Remote Rotating Log for Python that works instantly

Remote with xmlrpc

Remote logging is intended to log on a remote machine. Or, which might be a very common use, to log from multiple processes on the same machine into one logfile/table.

This requires two create* calls. One makes the log server, one makes the client in your application. Most parameters are now found in the server create* function, e.g. the rotation configuration.

Host and Ports

By default, the connection uses “localhost” and a default port → rrlog.globalconst.DEFAULTPORT_XMLRPC You can specify 1..n ports on both sides. The server uses the first free port. The client uses the first port where a server seems available.

An XMLRPC server for stdout

# First, create a pure print server:
# (this is independent from the connection type, like XMLRPC)
from rrlog.server import printwriter
logServer = printwriter.createServer()

# Start the server as an XMLRPC server:
from rrlog.server import xmlrpc

xmlrpc.startServer(
	logServer,
	ports=(9804,9805,9806,), # try in this order, use the first port available
	)
# The server waits for requests now.

rrlog.server.xmlrpc

rrlog.server.printwriter

An XMLRPC server for files

from rrlog.server import filewriter

logServer = filewriter.createRotatingServer(
	filePathPattern = "./demo-log-%s.txt", # "pattern" because %s (or %d) is required for the rotate-number
	rotateCount=3,
	rotateLineMin=10,
	)

# Start the server as an XMLRPC server:
from rrlog.server import xmlrpc

xmlrpc.startServer(
	logServer,
	ports=(9804,9805,9806,), # try in this order, use the first port available
	)
# The server waits for requests now.

rrlog.server.xmlrpc

rrlog.server.filewriter

An XMLRPC server for database tables

# First, create a pure database-writing server:
# (this is independent from the connection type, like XMLRPC)
from rrlog.server import dbwriter_sa
engineStr = "mysql://logtester@localhost/logtest"

logServer = dbwriter_sa.createRotatingServer(
	engineStr = engineStr,
	tableNamePattern = "logtable_%s",  # "pattern" because %s (or %d) is required for the rotate-number
	rotateCount=3,
	rotateLineMin=10,
    tsFormat="std1", # Timestamp format: std1 is shorthand for the strftime-format "%H:%M.%S;%3N"
	)

# Start the server as an XMLRPC server:
from rrlog.server import xmlrpc

xmlrpc.startServer(
	logServer,
	ports=(9804,9805,9806,), # try in this order, use the first port available
	)
# The server waits for requests now.

rrlog.server.xmlrpc

rrlog.server.dbwriter_sa

An XMLRPC client in your application

from rrlog import xmlrpc

log = xmlrpc.createClientLog(
	ports = (9804,9805,9806,) # use the first port where a server is available
	)

# now, log some lines:
for i in xrange(33):
	log("Hello xmlrpc - line %s"%(i))

rrlog.xmlrpc

Care for the correct server running ! For example, a socket server erroneously waiting on that port can cause the XMLRPC Client to block stupidly and wait without any Error message.