The module provides logging capabilities integrated with the qi sdk. It’s for most of the API mapped on standard logging facility for python. The module provides a lot of functionality and flexibility.
Warning
The debug log level is not available in python, because there is no debug build in python. Use verbose instead.
There are two ways to use this module:
- Use qi.Logger object with defined category
- Use static methods without defined category
Loggers have the following attributes and methods. Note that Loggers are never instantiated directly, but always through
the module-level function qi.logging.Logger(category)
.
The category
is potentially a period-separated hierarchical value, like foo.bar.baz
(though it could also be
just plain foo
, for example). This category will be the default category print by your logger inside your logs.
Logger.
fatal
(msg[, *args])¶Logs a message with level FATAL
on the logger. The msg
is the message format string, and the args
are the
arguments which are merged into msg
using the string formatting operator.
import qi.logging
logger = qi.logging.Logger("network")
logger.fatal("Protocol problem: ", "connection reset")
would print something like:
[F] 1458553342.543230 3630 network: Protocol problem: connection reset
Logger.
error
(msg[, *args])¶Logs a message with level ERROR
on the logger. The arguments are interpreted as for fatal().
Logger.
warning
(msg[, *args])¶Logs a message with level WARNING
on the logger. The arguments are interpreted as for fatal().
qi.logging.
setLevel
(lvl)¶Sets the threshold to lvl
. Logging messages which are less severe than lvl
will be ignored. When a handler is
created, the level is set to INFO
(which causes all messages to be processed except VERBOSE
).
import qi.logging
logger = qi.logging.Logger("test.logging")
qi.logging.setLevel(qi.logging.WARNING)
would only print logs more severe or equal than WARNING
(ei: FATAL
, ERROR
, WARNING
)
qi.logging.
setContext
(ctx)¶Sets differents context when printing logs. Context ctx
is a bit field (integer). All different contexts are
listed below. You can add different contexts to get multiple information.
1 | Verbosity |
2 | Short Verbosity |
4 | System Date |
8 | Thread ID |
16 | Category |
32 | File |
64 | Function |
128 | End Of Line |
256 | Date |
Here is some useful values
26 | Short Verbosity + Thread ID + Category |
30 | Short Verbosity + Thread ID + System Date + Category |
126 | Short Verbosity + Thread ID + System Date + Category + File + Function |
254 | Short Verbosity + Thread ID + System Date + Category + File + Function + EOL |
qi.logging.
setFilters
(filters)¶Sets filters
to display only logs that match filters categories rules. Rules are separated by colon. Each category
can include a ‘*’ for globbing. Each rules can be:
+CAT
: enable category CAT
-CAT
: disable category CAT
CAT=level
: set category CAT
to level
import qi.logging
logger = qi.logging.Logger("test.logging")
qi.logging.setFilters("qi.*=verbose:-qi.foo:+qi.foo.bar")
would print all qi.*
logs in INFO
and remove all qi.foo
logs except qi.foo.bar
.
qi.logging.
fatal
(cat, msg[, *args])¶Logs a message with level FATAL
and category cat
on the logger. The msg
is the message format string, and
the args
are the arguments which are merged into msg
using the string formatting operator.
import qi.logging
qi.logging.fatal("network", "Protocol problem: ", "connection reset")
would print something like:
[F] 1458553342.543230 3630 network: Protocol problem: connection reset
qi.logging.
error
(cat, msg[, *args])¶Logs a message with level ERROR
on the logger. The arguments are interpreted as for fatal().
qi.logging.
warning
(cat, msg[, *args])¶Logs a message with level WARNING
on the logger. The arguments are interpreted as for fatal().