lib.log

class lib.log.DateTimeRotatingFileHandler(filename, when='H', interval=1, backupCount=0, encoding=None, delay=True, utc=False)[Quellcode]

Bases: StreamHandler

Handler for logging to file using current date and time information in the filename. Either placeholders can be used or a standard pattern is used. Rotating the log file at each when beginning. If backupCount is > 0, when rollover is done, no more than backupCount files are kept - the oldest ones are deleted.

close()[Quellcode]

Closes the stream.

do_rollover()[Quellcode]

Do a rollover. In this case, the current stream will be closed and a new filename will be generated when the rollover happens. If there is a backup count, then we have to get a list of matching filenames, sort them and remove the one with the oldest suffix.

emit(record)[Quellcode]

Emit a record. Output the record to the file, catering for rollover as described in do_rollover().

get_filename()[Quellcode]
Rückgabetyp:

str

get_files_to_delete()[Quellcode]

Determine the files to delete when rolling over.

next_rollover_time()[Quellcode]

Work out the rollover time based on current time.

parseFilename(filename)[Quellcode]
Rückgabetyp:

str

class lib.log.Log(smarthome, name, mapping, maxlen=40, handler=None)[Quellcode]

Bases: deque

add(entry)[Quellcode]

Adds a log entry to the memory log. If the log already has reached the maximum length, the oldest entry is removed from the log automatically.

clean(dt)[Quellcode]

Assuming dt to be a datetime: remove all entries that are smaller or equal to this given datetime from the right side of the queue

export(number)[Quellcode]

Returns the newest entries of the log and prepares them with the mapping

Parameter:

number – Number of entries to return

Rückgabe:

List of log entries

last(number)[Quellcode]

Returns the newest entries of the log

Parameter:

number – Number of entries to return

Rückgabe:

List of log entries

class lib.log.Logs(sh)[Quellcode]

Bases: object

DBGHIGH_level = 13
DBGLOW_level = 11
DBGMED_level = 12
NOTICE_level = 29
add_all_handlers_logger(logging_config)[Quellcode]
add_log(name, log)[Quellcode]

Adds a log (object) to the list of memory logs

Parameter:
  • name – Name of log

  • log – Log object

add_logging_level(description, value)[Quellcode]

Adds a new Logging level to the standard python logging

Parameter:
  • description (string) – appearance within logs SYSINFO

  • value (int) – numeric value for the logging level

  • tocall (String, optional, if not given description will be used with lower case) – function name to call for a log with the given level

no error checking is performed here for typos, already existing levels or functions

configure_logging(config_filename='logging.yaml')[Quellcode]
get_all_handlernames()[Quellcode]
get_handler_by_name(handlername)[Quellcode]
get_shng_logging_levels()[Quellcode]

Returns a dict of the logging levels, that are defined in SmartHomeNG (key=numeric log level, value=name od loa level)

It is used e.g. by the admin module

Rückgabe:

dict

initMemLog()[Quellcode]

This function initializes all needed datastructures to use the ‚env.core.log‘ mem-logger and the (old) memlog plugin

It adds the handler log_mem (based on the custom lib.log.ShngMemLogHandler) to the root logger It logs all WARNINGS from all (old) mem-loggers to the root Logger

load_logging_config(filename='logging', ignore_notfound=False)[Quellcode]

Load config from logging.yaml to a dict

If logging.yaml does not contain a ‚shng_version‘ key, a backup is created

load_logging_config_for_edit()[Quellcode]

Load config from logging.yaml to a dict

If logging.yaml does not contain a ‚shng_version‘ key, a backup is created

logging_levels = {}
return_logs()[Quellcode]

Function to the list of memory logs

Rückgabe:

List of logs

Rückgabetyp:

list

root_handler_name = ''
save_logging_config(logging_config, create_backup=False)[Quellcode]

Save dict to logging.yaml

class lib.log.ShngMemLogHandler(logname='undefined', maxlen=35, level=0, mapping=['time', 'thread', 'level', 'message'], cache=False)[Quellcode]

Bases: StreamHandler

LogHandler used by MemLog

emit(record)[Quellcode]

Emit a record.

If a formatter is specified, it is used to format the record. The record is then written to the stream with a trailing newline. If exception information is present, it is formatted using traceback.print_exception and appended to the stream. If the stream has an ‚encoding‘ attribute, it is used to determine how to do the output to the stream.

load(logentries)[Quellcode]

Loads logentries (which were just read from cache) into the log object (see lib.log.Log())

class lib.log.ShngTimedRotatingFileHandler(filename, when='MIDNIGHT', interval=0, backupCount=0, encoding=None, delay=False, utc=False)[Quellcode]

Bases: TimedRotatingFileHandler

TimedRotatingFilehandler with a different naming scheme for rotated files

doRollover()[Quellcode]

do a rollover; in this case, a date/time stamp is appended to the filename when the rollover happens. However, you want the file to be named for the start of the interval, not the current time. If there is a backup count, then we have to get a list of matching filenames, sort them and remove the one with the oldest suffix.

getFilesToDelete()[Quellcode]

Determine the files to delete when rolling over.

More specific than the earlier method, which just used glob.glob().