common.log package

Submodules

common.log.Comment module

Persistent Comment class

class common.log.Comment.Comment(**kwargs)

Bases: common.database.DBMain.DBObject

Class for storing comments related to a DBObject

Example, showing how to couple a comment to a RegriddedFrame

awe> from common.log.Comment import Comment awe> q = RegriddedFrame.instrument.name == ‘WFI’ awe> regrid = q[567] awe> c = Comment() awe> c.make(‘A comment text’, regrid) awe> c.commit()

content

This is the comment [None]

creation_date

Date this object was created [None]

db_object_id

The object_id of the commented object [None]

db_object_type

The type of the commented object [None]

exists_in_database()

Check whether a comment already exists with the same content, that points to the same object

classmethod getCommentsObject(a_object)

get all the comments for the object

classmethod getCommentsObjectId(objectid)

get all the comments for the objectid

classmethod getCommentsUser()

return all comments from the current user

make(content, db_object)

set dependencies

object_id

The object identifier

The object identifier is an attribute shared by all persistent instances. It is the prime key, by which object identity is established

username

The username [None]

common.log.Error module

Implements ‘Error’, a class that sends the error message to the log provided by Message.py.

Errors can be raised as any other exception:

>>> raise Error, 'my error message' or
>>> raise Error('my error message')
exception common.log.Error.Error(message)

Bases: Exception

If an Error is raised, it will be written to log.

common.log.Log module

Logging

class common.log.Log.Log(log_dir='.', prefix='')

Bases: object

This class provides general logging facilities.

__init__(log_dir=’.’, prefix=’‘) – Construct a Log object. write(text) – Write a message to the standard or error logfile.

The class can be instantiated with two optional parameters. The first parameter is the name of the directory where the logfiles will be written. It defaults to the current directory. The second paramater is a prefix that will be attached to the logfilenames. The prefix defaults to the empty string.

get_filepath()

return the filepath of the log file

write(text)

Write a text to the Log object.

text – Message to be written to the Log.

If “text” contains the string “ERROR” it is written to the error logfile, otherwise it is written to the standard logfile. Only when a Log object is being written to, the standard or error logfile is created.

common.log.Mail module

common.log.Mail.mail(address, subject, text, address_from=None)

Send a mail to address - can be a list of addresses with subject and text

common.log.Message module

Messages

common.log.Message.Message(text, loglevel=1)

Log the given text uring Env[‘log’] (default) or use the python logging facility

common.log.PythonLogging module

python logging facility initialization

class common.log.PythonLogging.StoreLogHandler(*arg, **kwargs)

Bases: logging.Handler

emit(record)

log the record

flush()

flush is not needed, but must be defined

class common.log.PythonLogging.ThreadedLogHandler(level=0)

Bases: logging.Handler

python logging handler forwarding all logging to the ThreadedLog used in web services

emit(record)

log the record

flush()

the ThreadedLog class does not support flushing so pass for the moment

common.log.PythonLogging.get_default_logging_formatter()

return the default logging formatter

common.log.PythonLogging.get_loglevel()

return the log level

common.log.PythonLogging.init_python_logging()

initialize the python logging facility

common.log.PythonLogging.init_python_logging_console(loglevel=20, replace=True)

initialize a console log handler for the python logging facility, if replace is True then a previous console handler will be removed

common.log.PythonLogging.init_python_logging_logfile(filename, loglevel=20, delay=True, replace=True)

initialize a log file handler for the python logging facility delay=True will prevent creating empty log files

common.log.PythonLogging.init_python_logging_store(loglevel=30, replace=True)

this log handler can be used to collect all WARNINGS and more severe messages

common.log.PythonLogging.init_threaded_logging()

initialize the the python logging so it uses the ThreadedLog class for writing log

common.log.ThreadedLog module

ThreadedLog module

class common.log.ThreadedLog.ThreadedLog

Bases: object

thread safe logging using profiles profiles provide an unique id for identifying the log writer to use in multithreaded environments like webservers

default_filename = 'ThreadedLog.log'
dummy = 1

dummy mode, do not create file, do not write anything is used for unit tests

fd = {140270400288576: './MainThread.log'}
generate_filename(prefix, log_per_user, log_per_day)

generate the filename

get_filename()

get the filename of the log file for the current thread

get_filepath()

return the filepath of the log file same as get_filename, that also includes the full path

level = 0

this is the base level, any write call with a higher level is not logged the base level should be set by the application

start(log_dir='.', prefix='', filename=None, log_per_user=False, log_per_day=False)

start logging for this thread in file with filename: - the given filename - or generate the filename using the log_per_X switches (when set) - or generate the filename starting with prefix and current datetime

stop()

stop the log file for the current thread

to_file = True

write all the logging to a file True -> yes False -> no (in case of for example the cluster) print to screen

to_screen = False

print all logging to the screen

write(text, level=0, date=True)

write a log line for the current thread

common.log.ThreadedLog.strClass(Class)

get the class name from a class

common.log.ThreadedLog.strObject(Obj)

get the class name from an object

Module contents

Text