System Logging Handler

class DIRAC.FrameworkSystem.private.standardLogging.Handler.ServerHandler.ServerHandler(sleepTime, interactive, site)

Bases: logging.Handler, threading.Thread

ServerHandler is a custom handler from logging. It has no equivalent in the standard logging library because it is highly linked to DIRAC.

It is useful to send log messages to a destination, like the StreamHandler to a stream, the FileHandler to a file. Here, this handler send log messages to a DIRAC service: SystemLogging which store log messages in a database.

This handler send only log messages superior to WARN. It works in a thread, and send messages every ‘sleepTime’. When a message must be emit, it is added to queue before sending.

__init__(sleepTime, interactive, site)

Initialization of the ServerHandler. The queue is initialized with the hostname and the start of the thread.

Params sleepTime:
 integer, representing time in seconds where the handler can send messages.
Params interactive:
 not used at the moment.
Params site:the site where the log messages come from.

Acquire the I/O thread lock.


Add the specified filter to this handler.


Tidy up any resources used by the handler.

This version removes the handler from an internal map of handlers, _handlers, which is used for handler lookup by name. Subclasses should ensure that this gets called from overridden close() methods.


Acquire a thread lock for serializing access to the underlying I/O.


A boolean value indicating whether this thread is a daemon thread (True) or not (False).

This must be set before start() is called, otherwise RuntimeError is raised. Its initial value is inherited from the creating thread; the main thread is not a daemon thread and therefore all threads created in the main thread default to daemon = False.

The entire Python program exits when no alive non-daemon threads are left.


Add the record to the queue.

Params record:log record object

Determine if a record is loggable by consulting all the filters.

The default is to allow the record to be logged; any filter can veto this and the record is then dropped. Returns a zero value if a record is to be dropped, else non-zero.


Ensure all logging output has been flushed.

This version does nothing and is intended to be implemented by subclasses.


Format the specified record.

If a formatter is set, use it. Otherwise, use the default formatter for the module.


Conditionally emit the specified logging record.

Emission depends on filters which may have been added to the handler. Wrap the actual emission of the record with acquisition/release of the I/O thread lock. Returns whether the filter passed the record for emission.


Handle errors which occur during an emit() call.

This method should be called from handlers when an exception is encountered during an emit() call. If raiseExceptions is false, exceptions get silently ignored. This is what is mostly wanted for a logging system - most users will not care about errors in the logging system, they are more interested in application errors. You could, however, replace this with a custom handler if you wish. The record which was being processed is passed in to this method.


Thread identifier of this thread or None if it has not been started.

This is a nonzero integer. See the thread.get_ident() function. Thread identifiers may be recycled when a thread exits and another thread is created. The identifier is available even after the thread has exited.


Return whether the thread is alive.

This method returns True just before the run() method starts until just after the run() method terminates. The module function enumerate() returns a list of all alive threads.


Return whether the thread is alive.

This method returns True just before the run() method starts until just after the run() method terminates. The module function enumerate() returns a list of all alive threads.


Wait until the thread terminates.

This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception or until the optional timeout occurs.

When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call isAlive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.

When the timeout argument is not present or None, the operation will block until the thread terminates.

A thread can be join()ed many times.

join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.


Release the I/O thread lock.


Remove the specified filter from this handler.


Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.


Set the formatter for this handler.


Set the logging level of this handler.


Start the thread’s activity.

It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.

This method will raise a RuntimeError if called more than once on the same thread object.