The GlobalLogger class provides a flexible logging system for the SupplyNetPy simulations. It allows logging messages to both the console and a file, and can be easily enabled or disabled during runtime.
SupplyNetPy.Components.logger
GlobalLogger
GlobalLogger(logger_name=_LIBRARY_LOGGER_NAME, log_to_file=False, log_file='simulation_trace.log', log_to_screen=False)
Bases: LoggerAdapter
Library-wide :class:logging.LoggerAdapter with on/off file and screen handlers.
Subclasses :class:logging.LoggerAdapter so callers can write
node.logger.info(...) (and debug / warning / error /
critical) directly — no more node.logger.logger.info(...) double-hop.
The underlying :class:logging.Logger is still reachable as
self.logger (the standard adapter attribute), so older code that
reaches through that attribute keeps working.
The wrapper is inert by default. GlobalLogger() attaches only a
:class:logging.NullHandler and does not open any file — output is opt-in.
Call :meth:enable_logging (or pass log_to_file=True /
log_to_screen=True to the constructor) to attach real handlers. This is
the documented Python-library logging pattern; see
https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library
The library exports a module-level global_logger = GlobalLogger() from
core.py whose underlying :class:logging.Logger is named
"sim_trace". Every per-node logger created by :class:Node lives at
"sim_trace.<node.ID>" and propagates up to "sim_trace" — so all
log routing is configured in one place by calling
scm.global_logger.enable_logging(...). simulate_sc_net(logging=True)
does this automatically; users who drive env.run(...) themselves and
want a log file must call it explicitly.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
debug/info/warning/error/critical/log/exception |
Inherited from
:class: |
set_log_file |
Set the destination file and re-attach handlers. |
get_log_file |
Return the current log file path. |
set_logger |
Rebind |
configure_logger |
Re-build handlers from current flags. Always
attaches :class: |
enable_logging |
Opt-in: attach handlers and unmute the logger. |
disable_logging |
Mute the logger and drop handlers (NullHandler stays). |
Source code in src/SupplyNetPy/Components/logger.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
set_log_file
set_log_file(filename)
Set the destination log file and re-attach handlers.
Source code in src/SupplyNetPy/Components/logger.py
115 116 117 118 | |
get_log_file
get_log_file()
Return the current log file path.
Source code in src/SupplyNetPy/Components/logger.py
120 121 122 | |
set_logger
set_logger(logger_name)
Rebind the underlying logger to a different name.
Source code in src/SupplyNetPy/Components/logger.py
124 125 126 | |
configure_logger
configure_logger()
Replace this logger's handlers based on current log_to_file /
log_to_screen flags. A :class:logging.NullHandler is always
attached so the logger never triggers Python's "No handlers could be
found" stderr fallback — the recommended default for library loggers.
Source code in src/SupplyNetPy/Components/logger.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
enable_logging
enable_logging(log_to_file=True, log_to_screen=True)
Opt-in. Unmute the logger and (re)attach screen and/or file handlers
according to the arguments. Defaults are True for both so a bare
enable_logging() call gives the user the historical "noisy"
behavior on demand.
Source code in src/SupplyNetPy/Components/logger.py
151 152 153 154 155 156 157 158 159 | |
disable_logging
disable_logging()
Mute the logger. Sets self.logger.disabled = True and drops all
handlers (a :class:logging.NullHandler is re-attached so the logger
remains well-formed). Note: this only affects self.logger — it
does not touch the global logging.disable switch, which would
suppress the host application's own logging.
Source code in src/SupplyNetPy/Components/logger.py
161 162 163 164 165 166 167 168 169 170 | |