LogNode API reference¶
Parameters¶
Defined when creating a new LogNode.
name¶
Type:
stringdefault: REQUIRED
Description: The name of the log node.
Example:
'my log node'Note: There are no restrictions on the name, you can add any spaces, special characters, etc.
log_file¶
Type:
string,Nonedefault:
NoneDescription: The path to the log file
Example:
'my_log_file.log'Note: Supports relative and absolute paths. If
None, no log file will be created.
print_to_console¶
Type:
booldefault:
FalseDescription: Whether to print the log to the console.
Example:
True
print_filter¶
Type:
list[LogMessage],Nonedefault:
NoneDescription: A filter for which types of messages to print to the console.
Example:
[Error, Warn]Note: If
None, all messages will be printed.
max_messages_in_memory¶
Type:
intdefault:
500Description: The maximum number of messages to keep in memory. Used to prevent memory leaks.
Example:
1000Note: If the number of messages in memory exceeds this number, the oldest messages will be removed.
max_log_messages¶
Type:
intdefault:
1000Description: The maximum number of messages to keep in the log file. Used to prevent log files from growing too large.
Example:
10000Note: If the number of messages in the log file exceeds this number, the oldest messages will be removed.
log_when_closed¶
Type:
booldefault:
TrueDescription: Whether to log a message indicating that the log node was closed.
Example:
False
wipe_log_file_on_init¶
Type:
booldefault:
FalseDescription: Whether to wipe the log file when the log node is initialized.
Example:
TrueNote: If
False, the log file will be appended to, if true, the log file will be overwritten, than appended to.
Methods¶
log¶
Description: Logs a message to the log node.
Returns:
NoneParameters:
messageType:
LogMessage, Exception, BaseExceptionDefault: REQUIRED
Description: The message to log.
Example: `’Info(“Hello, world!”)’
override_log_fileType:
string,NoneDefault:
NoneDescription: The path to the log file to use for this message. If
None, the log file defined in the log node will be used.Example:
'my_log_file.log'Note: Supports relative and absolute paths.
force_printType:
tuple(bool, bool)Default:
(False, False)Description: A tuple of two booleans. The first boolean is whether to force print to the console, the second boolean is the to print or not.
Example:
(True, False)(force don’t print to console)preserve_message_in_memoryType:
boolDefault:
TrueDescription: Whether to preserve the message in memory. If
False, the message will not be stored in memory.Example:
FalseNote: Mostly used for internal purposes. If you are not sure, leave it as
True.
set_output_file¶
Description: Sets the log file for the entire log node.
Returns:
NoneParameters:
fileType:
string,NoneDefault: REQUIRED
Description: The path to the log file to use for this message. If
None, the log file is removed.Example:
'my_log_file.log'Note: Supports relative and absolute paths.
preserve_old_messagesType:
boolDefault:
FalseDescription: Whether to bring previously logged messages to the new log file.
Example:
FalseNote: If
False, any messages logged before this method is called will not be in the new log file.
dump_messages¶
Description: Dumps all messages in memory to a file.
Returns:
NoneParameters:
fileType:
stringDefault: REQUIRED
Description: The path to the file to dump the messages to.
Example:
'my_log_file.log'Note: Supports relative and absolute paths.
elementfilterType:
list[LogMessage/Exception/BaseException],NoneDefault:
NoneDescription: A filter for which types of messages to dump to the file.
Example:
[Error, Warn]Note: If
None, all messages will be dumped.
wipe_messages_from_memoryType:
boolDefault:
FalseDescription: Whether to remove the messages from memory after dumping them to the file.
Example:
TrueNote: If
True, the messages will be removed from memory after dumping them to the file.
filter¶
Description: Filters the messages within the log node to specific types.
Returns:
NoneParameters:
typefilterType:
list[LogMessage/Exception/BaseException],NoneDefault: REQUIRED
Description: A function to filter the messages within the log node, it will keep only the messages that are in the list.
Example:
[Error, Warn, ImportError]
filter_logfilesType:
boolDefault:
FalseDescription: Whether to filter the log file after filtering the messages in memory.
Example:
True
dump_messages_to_console¶
Description: Dumps all messages in memory to the console.
Returns:
NoneParameters:
elementfilterType:
LogMessage(s)/Exception(s)/BaseException(s),NoneDefault:
NoneDescription: A filter for which types of messages to dump to the console.
Example:
Error, Warn, ImportErrorNote: If the only element received is
None, all messages will be dumped.
wipe_messages¶
Description: Wipes all messages from memory.
Returns:
NoneParameters:
wipe_logfilesType:
boolDefault:
FalseDescription: Whether to wipe the log file as well.
Example:
TrueNote: If
True, the log file will be wiped as well.
clear_log¶
Description: Clears the log file.
Returns:
None
set_max_messages_in_log¶
Description: Sets the maximum number of messages to keep in the log file.
Returns:
NoneParameters:
max_file_sizeType:
intDefault: REQUIRED
Description: The maximum number of messages to keep in the log file.
Example:
10000
get¶
Description: Gets the messages in memory.
Returns:
list[LogMessage]Parameters:
*elementfilterType:
Union[LogMessage, Exception, BaseException],NoneDefault:
NoneDescription: Retrieve only the messages that passed in.
Example:
Error, Warn, ImportErrorNote: If
None, all messages will be returned. If more than one argument is passed, if a message matches at least one of the arguments, it will be returned. Also if you use get() to get a python exception, you will receive a PythonExceptionMessage object, to access the exception, use theexceptionattribute like this:get(ImportError)[0].exception.
combine¶
Description: Combines two or more log nodes into one.
Returns:
NoneParameters:
otherType:
LogNodeDefault: REQUIRED
Description: The log node to merge into the current one.
Example:
LogNode("my epic log node")
merge_log_filesType:
boolDefault:
TrueDescription: Whether to merge the log files of the log nodes.
Example:
TrueNote: If
True, the log files will be merged into one, the other log file will stay.
Note: The log node that is being combined into the current one will not be affected, however the current log node will get all the messages from the other log node at that time, they will not be linked afterwards.
squash¶
Description: Squashes a LogNode into a single message.
Returns:
NoneParameters:
messageType:
strDefault: REQUIRED
Description: The message to squash the log node into.
Example:
This is a squashed message
squash_logfileType:
boolDefault:
TrueDescription: Whether to wipe the log file after squashing the log node.
Example:
FalseNote: If
True, the log file will be wiped after squashing the log node and the squashed message will be the only message in the log file.
has¶
Description: Checks if the log node has a specific type of message.
Returns:
boolParameters:
*messageType:
Union[LogMessage, Exception, BaseException]Default: REQUIRED
Description: The message(s) to check for.
Example:
Error, Warn, ImportErrorNote: If more than one argument is passed, if a message matches at least one of the arguments, it will return
True.
has_errors¶
Description: Checks if the log node has any errors.
Returns:
boolParameters:
NoneNote: This is a shorthand for
has(Error, Fatal, PythonExceptionMessage).
rename¶
Description: Renames the log node.
Returns:
NoneParameters:
new_nameType:
strDefault: REQUIRED
Description: The new name of the log node.
Example:
my new log node
Note: The name of the log node can be changed at any time, but old messages in the log file will still have the old name next to them.
dunders¶
__repr__Description: Returns a string representation of the log node.
Returns:
strExample:
LogNode example at output console,LogNode example at output log.log
__len__Description: Returns the number of messages in memory.
Returns:
intExample:
10
__getitem__Description: Returns the message at the index.
Returns:
LogMessageParameters:
indexType:
intDefault: REQUIRED
Description: The index of the message to retrieve.
Example:
0
__contains__Description: Checks if the log node has a specific message.
Returns:
boolParameters:
messageType:
LogMessageDefault: REQUIRED
Description: The message to check for.
Example:
Error, Warn, InfoNote: Does not work with exceptions.
__iter__Description: Iterates through the messages in memory.
Returns:
LogMessage(per iteration)Example:
for message in lognode: print(message)