Logs

logging, colors, terminal width and pretty-print

waflib.Logs.zones = []

See waflib.Logs.log_filter

waflib.Logs.verbose = 0

Global verbosity level, see waflib.Logs.debug() and waflib.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.color_dict[source]

attribute-based color access, eg: colors.PINK

class waflib.Logs.log_filter(name='')[source]

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
filter(rec)[source]

Filters log records by zone and by logging level

Parameters

rec – log entry

class waflib.Logs.log_handler(stream=None)[source]

Dispatches messages to stderr/stdout depending on the severity level

emit(record)[source]

Delegates the functionality to waflib.Log.log_handler.emit_override()

emit_override(record, **kw)[source]

Writes the log record to the desired stream (stderr/stdout)

class waflib.Logs.formatter[source]

Simple log formatter which handles colors

format(rec)[source]

Formats records and adds colors as needed. The records do not get a leading hour format if the logging level is above INFO.

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.warn(*k, **kw)[source]

Wraps logging.warning

waflib.Logs.info(*k, **kw)[source]

Wraps logging.info

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)