Logs¶
logging, colors, terminal width and pretty-print
-
waflib.Logs.get_term_cols()[source]¶ Get the console width in characters.
Returns: the number of characters per line Return type: int
-
class
waflib.Logs.color_dict[source]¶ Bases:
objectattribute-based color access, eg: colors.PINK
-
__doc__= 'attribute-based color access, eg: colors.PINK'¶
-
__module__= 'waflib.Logs'¶
-
-
class
waflib.Logs.log_filter(name=None)[source]¶ Bases:
logging.FilterThe 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]¶ filter a record, adding the colors automatically
- error: red
- warning: yellow
Parameters: rec – message to record
-
__doc__= "\n\tThe waf logs are of the form 'name: message', and can be filtered by 'waf --zones=name'.\n\tFor example, the following::\n\n\t\tfrom waflib import Logs\n\t\tLogs.debug('test: here is a message')\n\n\tWill be displayed only when executing::\n\n\t\t$ waf --zones=test\n\t"¶
-
__module__= 'waflib.Logs'¶
-
-
class
waflib.Logs.log_handler(stream=None)[source]¶ Bases:
logging.StreamHandlerDispatches messages to stderr/stdout depending on the severity level
-
__doc__= 'Dispatches messages to stderr/stdout depending on the severity level'¶
-
__module__= 'waflib.Logs'¶
-
-
class
waflib.Logs.formatter[source]¶ Bases:
logging.FormatterSimple log formatter which handles colors
-
__doc__= 'Simple log formatter which handles colors'¶
-
__module__= 'waflib.Logs'¶
-
-
waflib.Logs.log= None¶ global logger for Logs.debug, Logs.error, etc
-
waflib.Logs.debug(*k, **kw)[source]¶ Wrap logging.debug, the output is filtered for performance reasons
-
waflib.Logs.error(*k, **kw)[source]¶ Wrap logging.errors, display the origin of the message when ‘-vv’ is set
-
waflib.Logs.make_logger(path, name)[source]¶ Create 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]¶ Create a memory logger to avoid writing concurrently to the main logger
-
waflib.Logs.free_logger(logger)[source]¶ Free 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]¶ Print 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