Module netsyslog :: Class Logger
[frames | no frames]

Type Logger

object --+
         |
        Logger


Send log messages to syslog servers.

The Logger class provides two different methods for sending log messages. The first approach (the log method) is suitable for creating new log messages from within a normal application. The second (the send_packet method) is designed for use in circumstances where you need full control over the contents of the syslog packet.
Method Summary
  __init__(self)
  add_host(self, hostname)
Add hostname to the list of hosts that will receive packets.
  log(self, facility, level, text, pid)
Send the message text to all registered hosts.
  remove_host(self, hostname)
Remove hostname from the list of hosts that will receive packets.
  send_packet(self, packet)
Send a Packet object to all registered hosts.
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Class Variable Summary
int PORT = 514                                                                   

Method Details

add_host(self, hostname)

Add hostname to the list of hosts that will receive packets.

Can be a hostname or an IP address. Note that if the hostname cannot be resolved calls to log or send_packet will take a long time to return.

log(self, facility, level, text, pid=False)

Send the message text to all registered hosts.

The facility and level will be used to create the packet's PRI part. The HEADER will be automatically determined from the current time and hostname. The MSG will be set from the running program's name and the text parameter.

This is the simplest way to use netsyslog, creating log messages containing the current time, hostname, program name, etc. This is how you do it:
   logger = netsyslog.Logger()
   logger.add_host("localhost")
   logger.log(syslog.LOG_USER, syslog.LOG_INFO, "Hello World")
If pid is True the process ID will be prepended to the text parameter, enclosed in square brackets and followed by a colon.

remove_host(self, hostname)

Remove hostname from the list of hosts that will receive packets.

send_packet(self, packet)

Send a Packet object to all registered hosts.

This method requires more effort than log as you need to construct your own Packet object beforehand, but it does give you full control over the contents of the packet:
   pri = netsyslog.PriPart(syslog.LOG_USER, syslog.LOG_INFO)
   header = netsyslog.HeaderPart("Jun  1 18:34:03", "myhost")
   msg = netsyslog.MsgPart("myprog", "Hello World", mypid)
   packet = netsyslog.Packet(pri, header, msg)

   logger = netsyslog.Logger()
   logger.add_host("localhost")
   logger.send_packet(packet)

Class Variable Details

PORT

Type:
int
Value:
514                                                                   

Generated by Epydoc 2.1 on Fri Jul 15 11:57:30 2005 http://epydoc.sf.net