Logs¶
logging, colors, terminal width and pretty-print
-
waflib.Logs.
zones
= []¶
-
waflib.Logs.
verbose
= 0¶ Global verbosity level, see
waflib.Logs.debug()
andwaflib.Logs.error()
-
waflib.Logs.
enable_colors
(use)[source]¶ If 1 is given, then the system will perform a few verifications before enabling colors, such as checking whether the interpreter is running in a terminal. A value of zero will disable colors, and a value above 1 will force colors.
Parameters: use (integer) – whether to enable colors or not
-
waflib.Logs.
get_term_cols
()[source]¶ Returns the console width in characters.
Returns: the number of characters per line Return type: int
-
waflib.Logs.
get_color
(cl)[source]¶ Returns the ansi sequence corresponding to the given color name. An empty string is returned when coloring is globally disabled.
Parameters: cl (string) – color name in capital letters
-
class
waflib.Logs.
log_filter
(name='')[source]¶ Bases:
logging.Filter
Waf logs are of the form ‘name: message’, and can be filtered by ‘waf –zones=name’. For example, the following:
from waflib import Logs Logs.debug('test: here is a message')
Will be displayed only when executing:
$ waf --zones=test
-
class
waflib.Logs.
log_handler
(stream=None)[source]¶ Bases:
logging.StreamHandler
Dispatches messages to stderr/stdout depending on the severity level
-
class
waflib.Logs.
formatter
[source]¶ Bases:
logging.Formatter
Simple log formatter which handles colors
-
waflib.Logs.
log
= None¶ global logger for Logs.debug, Logs.error, etc
-
waflib.Logs.
debug
(*k, **kw)[source]¶ Wraps logging.debug and discards messages if the verbosity level
waflib.Logs.verbose
≤ 0
-
waflib.Logs.
error
(*k, **kw)[source]¶ Wrap logging.errors, adds the stack trace when the verbosity level
waflib.Logs.verbose
≥ 2
-
waflib.Logs.
init_log
()[source]¶ Initializes the logger
waflib.Logs.log
-
waflib.Logs.
make_logger
(path, name)[source]¶ Creates a simple logger, which is often used to redirect the context command output:
from waflib import Logs bld.logger = Logs.make_logger('test.log', 'build') bld.check(header_name='sadlib.h', features='cxx cprogram', mandatory=False) # have the file closed immediately Logs.free_logger(bld.logger) # stop logging bld.logger = None
The method finalize() of the command will try to free the logger, if any
Parameters: - path (string) – file name to write the log output to
- name (string) – logger name (loggers are reused)
-
waflib.Logs.
make_mem_logger
(name, to_log, size=8192)[source]¶ Creates a memory logger to avoid writing concurrently to the main logger
-
waflib.Logs.
free_logger
(logger)[source]¶ Frees the resources held by the loggers created through make_logger or make_mem_logger. This is used for file cleanup and for handler removal (logger objects are re-used).
-
waflib.Logs.
pprint
(col, msg, label='', sep='\n')[source]¶ Prints messages in color immediately on stderr:
from waflib import Logs Logs.pprint('RED', 'Something bad just happened')
Parameters: - col (string) – color name to use in
Logs.colors_lst
- msg (string or a value that can be printed by %s) – message to display
- label (string) – a message to add after the colored output
- sep (string) – a string to append at the end (line separator)
- col (string) – color name to use in