BrianLogger class

(Shortest import: from brian2 import BrianLogger)

class brian2.utils.logger.BrianLogger(name)[source]

Bases: object

Convenience object for logging. Call get_logger() to get an instance of this class.

Parameters:

name : str

The name used for logging, normally the name of the module. If the name does not start with brian2., it will be prepended automatically when interacting with the logging module. This means that from the logging’s system point of view, it will use the configuration for the logger in the brian2 hierachy. However, when displaying the name in the log messages, the brian2. prefix will be removed. This is useful for extension modules, which can use the Brian logging system, but will be displayed as myextension instead of brian2.myextension. This is also used in Brian’s test suite, which only considers log messages starting with brian2.

Attributes

_log_messages

Class attribute for remembering log messages that should only be displayed once

_pid

The pid of the process that initialized the logger – used to switch off file logging in multiprocessing contexts

console_handler

The logging.StreamHandler responsible for logging to the console

exception_occured

Class attribute to remember whether any exception occured

file_handler

The logging.FileHandler responsible for logging to the temporary log file

initialized

Global flag to know whether the logging system is in a usable state

tmp_log

The name of the temporary log file (by default deleted after the run if no exception occurred), if any

tmp_script

The name of the temporary copy of the main script file (by default deleted after the run if no exception occurred), if any

Methods

debug(msg[, name_suffix, once])

Log a debug message.

diagnostic(msg[, name_suffix, once])

Log a diagnostic message.

error(msg[, name_suffix, once])

Log an error message.

info(msg[, name_suffix, once])

Log an info message.

initialize()

Initialize Brian's logging system.

log_level_debug()

Set the log level to "debug".

log_level_diagnostic()

Set the log level to "diagnostic".

log_level_error()

Set the log level to "error".

log_level_info()

Set the log level to "info".

log_level_warn()

Set the log level to "warn".

suppress_hierarchy(name[, filter_log_file])

Suppress all log messages in a given hiearchy.

suppress_name(name[, filter_log_file])

Suppress all log messages with a given name.

warn(msg[, name_suffix, once])

Log a warn message.

warning(msg[, name_suffix, once])

Log a warn message.

Details

_log_messages

Class attribute for remembering log messages that should only be displayed once

_pid

The pid of the process that initialized the logger – used to switch off file logging in multiprocessing contexts

console_handler

The logging.StreamHandler responsible for logging to the console

exception_occured

Class attribute to remember whether any exception occured

file_handler

The logging.FileHandler responsible for logging to the temporary log file

initialized

Global flag to know whether the logging system is in a usable state

tmp_log

The name of the temporary log file (by default deleted after the run if no exception occurred), if any

tmp_script

The name of the temporary copy of the main script file (by default deleted after the run if no exception occurred), if any

debug(msg, name_suffix=None, once=False)[source]

Log a debug message.

Parameters:

msg : str

The message to log.

name_suffix : str, optional

A suffix to add to the name, e.g. a class or function name.

once : bool, optional

Whether this message should be logged only once and not repeated if sent another time.

diagnostic(msg, name_suffix=None, once=False)[source]

Log a diagnostic message.

Parameters:

msg : str

The message to log.

name_suffix : str, optional

A suffix to add to the name, e.g. a class or function name.

once : bool, optional

Whether this message should be logged only once and not repeated if sent another time.

error(msg, name_suffix=None, once=False)[source]

Log an error message.

Parameters:

msg : str

The message to log.

name_suffix : str, optional

A suffix to add to the name, e.g. a class or function name.

once : bool, optional

Whether this message should be logged only once and not repeated if sent another time.

info(msg, name_suffix=None, once=False)[source]

Log an info message.

Parameters:

msg : str

The message to log.

name_suffix : str, optional

A suffix to add to the name, e.g. a class or function name.

once : bool, optional

Whether this message should be logged only once and not repeated if sent another time.

static initialize()[source]

Initialize Brian’s logging system. This function will be called automatically when Brian is imported.

static log_level_debug()[source]

Set the log level to “debug”.

static log_level_diagnostic()[source]

Set the log level to “diagnostic”.

static log_level_error()[source]

Set the log level to “error”.

static log_level_info()[source]

Set the log level to “info”.

static log_level_warn()[source]

Set the log level to “warn”.

static suppress_hierarchy(name, filter_log_file=False)[source]

Suppress all log messages in a given hiearchy.

Parameters:

name : str

Suppress all log messages in the given name hierarchy. For example, specifying 'brian2' suppresses all messages logged by Brian, specifying 'brian2.codegen' suppresses all messages generated by the code generation modules.

filter_log_file : bool, optional

Whether to suppress the messages also in the log file. Defaults to False meaning that suppressed messages are not displayed on the console but are still saved to the log file.

static suppress_name(name, filter_log_file=False)[source]

Suppress all log messages with a given name.

Parameters:

name : str

Suppress all log messages ending in the given name. For example, specifying 'resolution_conflict' would suppress messages with names such as brian2.equations.codestrings.CodeString.resolution_conflict or brian2.equations.equations.Equations.resolution_conflict.

filter_log_file : bool, optional

Whether to suppress the messages also in the log file. Defaults to False meaning that suppressed messages are not displayed on the console but are still saved to the log file.

warn(msg, name_suffix=None, once=False)[source]

Log a warn message.

Parameters:

msg : str

The message to log.

name_suffix : str, optional

A suffix to add to the name, e.g. a class or function name.

once : bool, optional

Whether this message should be logged only once and not repeated if sent another time.

warning(msg, name_suffix=None, once=False)

Log a warn message.

Parameters:

msg : str

The message to log.

name_suffix : str, optional

A suffix to add to the name, e.g. a class or function name.

once : bool, optional

Whether this message should be logged only once and not repeated if sent another time.

Tutorials and examples using this