loggers
Data:
List of instantiated loggers, used in |
|
//github.com/r1chardj0n3s/parse>`_ |
|
Additional parsing patterns for logged messages |
Functions:
|
Initialize a logger |
Exceptions:
Error parsing a logfile |
Classes:
|
|
|
Single entry in a log |
|
Representation of a logfile in memory |
- _LOGGERS: list = [ 'data.interfaces.tables', 'data.interfaces.tables.H5F_Group', 'data.models.subject', 'data.models.subject._Hash_Table', 'data.models.subject._History_Table', 'data.models.subject._Weight_Table']
List of instantiated loggers, used in
init_logger()to return existing loggers without modification
- init_logger(instance=None, module_name=None, class_name=None, object_name=None) logging.Logger[source]
Initialize a logger
Loggers are created such that…
There is one logger per module (eg. all gpio objects will log to hardware.gpio)
If the passed object has a
nameattribute, that name will be prefixed to its log messages in the fileThe loglevel for the file handler and the stdout is determined by
prefs.get('LOGLEVEL'), and if none is providedWARNINGis used by defaultlogs are rotated according to
prefs.get('LOGSIZE')(in bytes) andprefs.get('LOGNUM')(number of backups ofprefs.get('LOGSIZE')to cycle through)
Logs are stored in
prefs.get('LOGDIR'), and are formatted like:"%(asctime)s - %(name)s - %(levelname)s : %(message)s"
Loggers can be initialized either by passing an object to the first
instanceargument, or by specifying any ofmodule_name,class_name, orobject_name(at least one must be specified) which are combined with periods likemodule.class_name.object_name- Parameters
instance – The object that we are creating a logger for! if None, at least one of
module, class_name, or object_namemust be passedmodule_name (None, str) – If no
instancepassed, the module name to create a logger forclass_name (None, str) – If no
instancepassed, the class name to create a logger forobject_name (None, str) – If no
instancepassed, the object name/id to create a logger for
- Returns
logging.logger
- exception ParseError[source]
Bases:
RuntimeErrorError parsing a logfile
- class Log_Format(format: str, example: str, conversions: Union[Dict[str, Callable], NoneType] = None)[source]
Bases:
objectAttributes:
A format string parseable by
parseAn example string (that allows for testing)
A dictionary matching keys in the
formatstring to callables for post-parsing coercionMethods:
parse(log_entry)
- LOG_FORMATS = ( Log_Format(format='{timestamp:Timestamp} - {name} - {level} : {message}', example="2022-03-07 16:56:48,954 - networking.node.Net_Node._T - DEBUG : RECEIVED: ID: _testpi_9879; TO: T; SENDER: _testpi; KEY: DATA; FLAGS: {'NOREPEAT': True}; VALUE: {'trial_num': 1197, 'timestamp': '2022-03-01T23:52:16.995387', 'frequency': 45255.0, 'amplitude': 0.1, 'ramp': 5.0, 'pilot': 'testpi', 'subject': '0895'}", conversions={'Timestamp': <function _convert_asc_timestamp at 0x7f46ce1144c0>}), Log_Format(format='[{timestamp:Timestamp}] {level} [{name}]: {message}', example='[2022-03-09 16:13:43,224] INFO [networking.node]: parent, module-level logger created: networking.node', conversions={'Timestamp': <function _convert_asc_timestamp at 0x7f46ce1144c0>}))
//github.com/r1chardj0n3s/parse>`_
- Type
Possible formats of logging messages (to allow change over versions) as a `parse string <https
- MESSAGE_FORMATS = { 'node_msg_recv': '{action}: ID: {message_id}; TO: {to}; SENDER: {sender}; ' 'KEY: {key}; FLAGS: {flags}; VALUE: {value}', 'node_msg_sent': '{action} - ID: {message_id}; TO: {to}; SENDER: {sender}; ' 'KEY: {key}; FLAGS: {flags}; VALUE: {value}'}
Additional parsing patterns for logged messages
node_msg: Logging messages fromnetworking.node.Net_Node
- class LogEntry(*, timestamp: datetime.datetime, name: str, level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR'], message: Union[str, dict])[source]
Bases:
autopilot.root.Autopilot_TypeSingle entry in a log
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
Attributes:
Methods:
parse_message(format)Parse the message using a format string specified as a key in the
MESSAGE_FORMATSdictionary (or a format string itself)from_string(entry[, parse_message])Create a LogEntry by parsing a string.
- timestamp: datetime.datetime
- level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR']
- parse_message(format: List[str])[source]
Parse the message using a format string specified as a key in the
MESSAGE_FORMATSdictionary (or a format string itself)replaces the
messageattribute.If parsing unsuccessful, no exception is raised because there are often messages that are not parseable in the logs!
- Parameters
format (typing.List[str]) – List of format strings to try!
Returns:
- classmethod from_string(entry: str, parse_message: Optional[List[str]] = None) autopilot.core.loggers.LogEntry[source]
Create a LogEntry by parsing a string.
Try to parse using any of the possible .LOG_FORMATS, raising a
ParseErrorif none are successful- Parameters
entry (str) – single line of a logging file
parse_message (Optional[str]) – Parse messages with the
MESSAGE_FORMATSkey or format string
- Returns
- Raises
.ParseError –
- class Log(*, entries: List[autopilot.core.loggers.LogEntry])[source]
Bases:
autopilot.root.Autopilot_TypeRepresentation of a logfile in memory
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
Attributes:
Methods:
from_logfile(file[, include_backups, ...])Load a logfile (and maybe its backups) from a logfile location
- entries: List[autopilot.core.loggers.LogEntry]
- classmethod from_logfile(file: Union[pathlib.Path, str], include_backups: bool = True, parse_messages: Optional[List[str]] = None)[source]
Load a logfile (and maybe its backups) from a logfile location
- Parameters
file (
pathlib.Path, str) – If string, converted to Path. If relative (and relative file is not found), then attempts to find relative toprefs.LOGDIRinclude_backups (bool) – if
True(default), try and load all of the backup logfiles (that have .1, .2, etc appended)parse_messages (Optional[str]) – Parse messages with the
MESSAGE_FORMATSkey or format string
- Returns