jina.logging.logger module#

class jina.logging.logger.RichHandler(*args, **kwargs)[source]#

Bases: RichHandler

Override the original rich handler for more compact layout.

Initializes the instance - basically setting the formatter to None and the filter list to empty.

HIGHLIGHTER_CLASS#

alias of ReprHighlighter

KEYWORDS: ClassVar[Optional[List[str]]] = ['GET', 'POST', 'HEAD', 'PUT', 'DELETE', 'OPTIONS', 'TRACE', 'PATCH']#
acquire()#

Acquire the I/O thread lock.

addFilter(filter)#

Add the specified filter to this handler.

close()#

Tidy up any resources used by the handler.

This version removes the handler from an internal map of handlers, _handlers, which is used for handler lookup by name. Subclasses should ensure that this gets called from overridden close() methods.

createLock()#

Acquire a thread lock for serializing access to the underlying I/O.

emit(record)[source]#

Invoked by logging.

Return type:

None

filter(record)#

Determine if a record is loggable by consulting all the filters.

The default is to allow the record to be logged; any filter can veto this and the record is then dropped. Returns a zero value if a record is to be dropped, else non-zero.

Changed in version 3.2: Allow filters to be just callables.

flush()#

Ensure all logging output has been flushed.

This version does nothing and is intended to be implemented by subclasses.

format(record)#

Format the specified record.

If a formatter is set, use it. Otherwise, use the default formatter for the module.

get_level_text(record)[source]#

Get the level name from the record.

Args:

record (LogRecord): LogRecord instance.

Returns:

Text: A tuple of the style and level name.

Return type:

Text

get_name()#
handle(record)#

Conditionally emit the specified logging record.

Emission depends on filters which may have been added to the handler. Wrap the actual emission of the record with acquisition/release of the I/O thread lock. Returns whether the filter passed the record for emission.

handleError(record)#

Handle errors which occur during an emit() call.

This method should be called from handlers when an exception is encountered during an emit() call. If raiseExceptions is false, exceptions get silently ignored. This is what is mostly wanted for a logging system - most users will not care about errors in the logging system, they are more interested in application errors. You could, however, replace this with a custom handler if you wish. The record which was being processed is passed in to this method.

property name#
release()#

Release the I/O thread lock.

removeFilter(filter)#

Remove the specified filter from this handler.

render(*, record, traceback, message_renderable)[source]#

Render log for display.

Args:

record (LogRecord): logging Record. traceback (Optional[Traceback]): Traceback instance or None for no Traceback. message_renderable (ConsoleRenderable): Renderable (typically Text) containing log message contents.

Returns:

ConsoleRenderable: Renderable to display log.

Return type:

ConsoleRenderable

render_message(record, message)[source]#

Render message text in to Text.

Args:

record (LogRecord): logging Record. message (str): String containing log message.

Returns:

ConsoleRenderable: Renderable to display log message.

Return type:

ConsoleRenderable

setFormatter(fmt)#

Set the formatter for this handler.

setLevel(level)#

Set the logging level of this handler. level must be an int or a str.

set_name(name)#
class jina.logging.logger.SysLogHandlerWrapper(address=('localhost', 514), facility=1, socktype=None)[source]#

Bases: SysLogHandler

Override the priority_map SysLogHandler.

Warning

This messages at DEBUG and INFO are therefore not stored by ASL, (ASL = Apple System Log) which in turn means they can’t be printed by syslog after the fact. You can confirm it via syslog or tail -f /var/log/system.log.

Initialize a handler.

If address is specified as a string, a UNIX socket is used. To log to a local syslogd, “SysLogHandler(address=”/dev/log”)” can be used. If facility is not specified, LOG_USER is used. If socktype is specified as socket.SOCK_DGRAM or socket.SOCK_STREAM, that specific socket type will be used. For Unix sockets, you can also specify a socktype of None, in which case socket.SOCK_DGRAM will be used, falling back to socket.SOCK_STREAM.

priority_map = {'CRITICAL': 'critical', 'DEBUG': 'debug', 'ERROR': 'error', 'INFO': 'info', 'WARNING': 'warning'}#
LOG_ALERT = 1#
LOG_AUTH = 4#
LOG_AUTHPRIV = 10#
LOG_CRIT = 2#
LOG_CRON = 9#
LOG_DAEMON = 3#
LOG_DEBUG = 7#
LOG_EMERG = 0#
LOG_ERR = 3#
LOG_FTP = 11#
LOG_INFO = 6#
LOG_KERN = 0#
LOG_LOCAL0 = 16#
LOG_LOCAL1 = 17#
LOG_LOCAL2 = 18#
LOG_LOCAL3 = 19#
LOG_LOCAL4 = 20#
LOG_LOCAL5 = 21#
LOG_LOCAL6 = 22#
LOG_LOCAL7 = 23#
LOG_LPR = 6#
LOG_MAIL = 2#
LOG_NEWS = 7#
LOG_NOTICE = 5#
LOG_SYSLOG = 5#
LOG_USER = 1#
LOG_UUCP = 8#
LOG_WARNING = 4#
acquire()#

Acquire the I/O thread lock.

addFilter(filter)#

Add the specified filter to this handler.

append_nul = True#
close()#

Closes the socket.

createLock()#

Acquire a thread lock for serializing access to the underlying I/O.

emit(record)#

Emit a record.

The record is formatted, and then sent to the syslog server. If exception information is present, it is NOT sent to the server.

encodePriority(facility, priority)#

Encode the facility and priority. You can pass in strings or integers - if strings are passed, the facility_names and priority_names mapping dictionaries are used to convert them to integers.

facility_names = {'auth': 4, 'authpriv': 10, 'cron': 9, 'daemon': 3, 'ftp': 11, 'kern': 0, 'local0': 16, 'local1': 17, 'local2': 18, 'local3': 19, 'local4': 20, 'local5': 21, 'local6': 22, 'local7': 23, 'lpr': 6, 'mail': 2, 'news': 7, 'security': 4, 'syslog': 5, 'user': 1, 'uucp': 8}#
filter(record)#

Determine if a record is loggable by consulting all the filters.

The default is to allow the record to be logged; any filter can veto this and the record is then dropped. Returns a zero value if a record is to be dropped, else non-zero.

Changed in version 3.2: Allow filters to be just callables.

flush()#

Ensure all logging output has been flushed.

This version does nothing and is intended to be implemented by subclasses.

format(record)#

Format the specified record.

If a formatter is set, use it. Otherwise, use the default formatter for the module.

get_name()#
handle(record)#

Conditionally emit the specified logging record.

Emission depends on filters which may have been added to the handler. Wrap the actual emission of the record with acquisition/release of the I/O thread lock. Returns whether the filter passed the record for emission.

handleError(record)#

Handle errors which occur during an emit() call.

This method should be called from handlers when an exception is encountered during an emit() call. If raiseExceptions is false, exceptions get silently ignored. This is what is mostly wanted for a logging system - most users will not care about errors in the logging system, they are more interested in application errors. You could, however, replace this with a custom handler if you wish. The record which was being processed is passed in to this method.

ident = ''#
mapPriority(levelName)#

Map a logging level name to a key in the priority_names map. This is useful in two scenarios: when custom levels are being used, and in the case where you can’t do a straightforward mapping by lowercasing the logging level name because of locale- specific issues (see SF #1524081).

property name#
priority_names = {'alert': 1, 'crit': 2, 'critical': 2, 'debug': 7, 'emerg': 0, 'err': 3, 'error': 3, 'info': 6, 'notice': 5, 'panic': 0, 'warn': 4, 'warning': 4}#
release()#

Release the I/O thread lock.

removeFilter(filter)#

Remove the specified filter from this handler.

setFormatter(fmt)#

Set the formatter for this handler.

setLevel(level)#

Set the logging level of this handler. level must be an int or a str.

set_name(name)#
class jina.logging.logger.JinaLogger(context, name=None, log_config=None, quiet=False, **kwargs)[source]#

Bases: object

Build a logger for a context.

Parameters:
  • context (str) – The context identifier of the class, module or method.

  • log_config (Optional[str]) – The configuration file for the logger.

configuration to group logs by deployment. :return:: an executor object.

supported = {'FileHandler', 'RichHandler', 'StreamHandler', 'SysLogHandler'}#
success(*args)[source]#

Provides an API to print success messages

Parameters:

args – the args to be forwarded to the log

property handlers#

Get the handlers of the logger.

Return::

Handlers of logger.

close()[source]#

Close all the handlers.

add_handlers(config_path=None, **kwargs)[source]#

Add handlers from config file.

Parameters:
  • config_path (Optional[str]) – Path of config file.

  • kwargs – Extra parameters.