nxt.nxt_log module

Logging utilities and constants.

VERBOSE_ENV_VAR = 'NXT_VERBOSE'

Logging levels are as follows, with custom levels marked with * CRITICAL - 50 ERROR - 40 *GRAPHERROR - 39 WARNING - 30 INFO - 20 *NODEOUT - 19 *EXECINFO - 18 *COMPINFO - 17 *SOCKET - 16 DEBUG - 10 NOTSET - 0

class NXTLogger(name)[source]

Bases: logging.Logger

Implements custom logging levels for nxt.

socket(message, *args, **kwargs)[source]
execinfo(message, *args, **kwargs)[source]
grapherror(message, *args, **kwargs)[source]
compinfo(message, *args, **kwargs)[source]
nodeout(message, *args, **kwargs)[source]
track_log_file(path)[source]

Track given log at path, via meta log. Clean up old log files tracked by meta log.

initial_setup()[source]

module-wide logging boilerplate. Sets logging level. Builds and sets up default handlers.

set_verbosity(level)[source]

Set the verbosity of nxt logging. Controls what to output to stderr. 3 legal levels specified by integer. NOTE node prints are not affected.

0 - Nothing

1 - EXECINFO and higher

2 - Everything

Parameters

level (int) – level to set stderr verbosity to: 0, 1, or 2

Returns

stderr handler, if there is one

Return type

logging.StreamHandler or None

make_session_log(filename=None)[source]

Begin saving log at filename if given, otherwise track to a generated file inside default temporary directory.

Parameters

filename (str, optional) – file to log to, defaults to None

Returns

file being logged to, filename if given.

Return type

str

get_new_session_log_filename()[source]

Get a new log filename for an nxt session inside the default logs directory. Attempts to create logs directory.

Returns

filename to use for session log.

Return type

str

stop_session_log(filename)[source]

Stops outputting log to given filename.

Parameters

filename (str, required) – filename to stop outputting to.

Wrap given value in html href syntax.

Parameters

value (str) – value to wrap

class LogRecordStreamHandler(request, client_address, server)[source]

Bases: socketserver.StreamRequestHandler

Lifted from: https://docs.python.org/2.7/howto/logging-cookbook.html Handler for a streaming logging request.

This basically logs the record using whatever logging policy is configured locally.

handle()[source]

Handle multiple requests - each expected to be a 4-byte length, followed by the LogRecord in pickle format. Logs the record according to whatever policy is configured locally.

un_pickle(data)[source]
handle_log_record(record)[source]
class LogRecordSocketReceiver(host='localhost', port=9020, handler=<class 'nxt.nxt_log.LogRecordStreamHandler'>)[source]

Bases: socketserver.ThreadingTCPServer

Lifted from: https://docs.python.org/2.7/howto/logging-cookbook.html Simple TCP socket-based logging receiver suitable for testing.

allow_reuse_address = 1
serve_until_stopped()[source]
startup_log_socket(stream_handler=<class 'nxt.nxt_log.LogRecordStreamHandler'>)[source]

Starts threaded logging socket receiver, if using a visual app a thread safe stream handler should be provided.

Parameters

stream_handler – Logging stream handler default LogRecordStreamHandler

Returns

LogRecordSocketReceiver()

shutdown_log_socket()[source]