euporie.core.log

Initiate logging for euporie.core.

Functions

add_log_level(name, number)

Add a new level to the logger.

add_setting(name, default, help_, description)

Register a new config item.

create_output([stdout, always_prefer_tty])

Return an Output instance for the command line.

dict_merge(target_dict, input_dict)

Merge the second dictionary onto the first.

get_app_session()

get_style_by_name(name)

Return a style class by its short name.

handle_exception(exc_type, exc_value, ...)

Log unhandled exceptions and their tracebacks in the log.

indent(ft[, margin, style, skip_first])

Indent formatted text with a given margin.

lex(ft, lexer_name)

Format formatted text using a named pygments lexer.

merge_styles(styles)

Merge multiple Style objects.

print_formatted_text(*values[, sep, end, ...])

.

renderer_print_formatted_text(output, ...[, ...])

Print a list of (style_str, text) tuples in the given style to the output.

setup_logs([config])

Configure the logger for euporie.

style_from_pygments_cls(pygments_style_cls)

Shortcut to create a Style instance from a Pygments style class and a style dictionary.

wrap(ft, width[, style, placeholder, left, ...])

Wrap formatted text at a given width.

Classes

FormattedText([iterable])

A list of (style, text) tuples.

FormattedTextHandler(*args[, share_stream, ...])

Format log records for display on the standard output.

FtFormatter(*args, **kwargs)

Base class for formatted text logging formatter.

LogTabFormatter(*args, **kwargs)

Format log messages for display in the log view tab.

Path(*args, **kwargs)

PurePath subclass that can make system calls.

QueueHandler(*args, queue[, style])

This handler store logs events into a queue.

StdoutFormatter(*args, **kwargs)

A log formatter for formatting log entries for display on the standard output.

StringIO([initial_value, newline])

Text I/O implementation using an in-memory buffer.

Style(style_rules)

Create a Style instance from a list of style rules.

deque

deque([iterable[, maxlen]]) --> deque object

stdout_to_log(log[, output])

A decorator which captures standard output and logs it.

class euporie.core.log.FormattedTextHandler(*args: Any, share_stream: bool = True, style: BaseStyle | None = None, pygments_theme: str = 'euporie', **kwargs: Any)

Bases: logging.StreamHandler

Format log records for display on the standard output.

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: logging.LogRecord) None

Emit a formatted record.

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()

Flushes the stream.

format(record)

Format the specified record.

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

formatter: euporie.core.log.FtFormatter
ft_format(record: logging.LogRecord) prompt_toolkit.formatted_text.base.FormattedText

Format the specified record.

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.

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.

setStream(stream)

Sets the StreamHandler’s stream to the specified value, if it is different.

Returns the old stream, if the stream was changed, or None if it wasn’t.

set_name(name)
terminator = '\n'
class euporie.core.log.FtFormatter(*args: Any, **kwargs: Any)

Bases: logging.Formatter

Base class for formatted text logging formatter.

converter()
localtime([seconds]) -> (tm_year,tm_mon,tm_mday,tm_hour,tm_min,

tm_sec,tm_wday,tm_yday,tm_isdst)

Convert seconds since the Epoch to a time tuple expressing local time. When ‘seconds’ is not passed in, convert the current time instead.

default_msec_format = '%s,%03d'
default_time_format = '%Y-%m-%d %H:%M:%S'
format(record)

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

formatException(ei)

Format and return the specified exception information as a string.

This default implementation just uses traceback.print_exception()

formatMessage(record)
formatStack(stack_info)

This method is provided as an extension point for specialized formatting of stack information.

The input data is a string as returned from a call to traceback.print_stack(), but with the last trailing newline removed.

The base implementation just returns the value passed in.

formatTime(record, datefmt=None)

Return the creation time of the specified LogRecord as formatted text.

This method should be called from format() by a formatter which wants to make use of a formatted time. This method can be overridden in formatters to provide for any specific requirement, but the basic behaviour is as follows: if datefmt (a string) is specified, it is used with time.strftime() to format the creation time of the record. Otherwise, an ISO8601-like (or RFC 3339-like) format is used. The resulting string is returned. This function uses a user-configurable function to convert the creation time to a tuple. By default, time.localtime() is used; to change this for a particular formatter instance, set the ‘converter’ attribute to a function with the same signature as time.localtime() or time.gmtime(). To change it for all formatters, for example if you want all logging times to be shown in GMT, set the ‘converter’ attribute in the Formatter class.

format_traceback(tb: str) StyleAndTextTuples

Format a traceback string using pygments.

ft_format(record: logging.LogRecord, width: int | None = None) prompt_toolkit.formatted_text.base.FormattedText

Format a log record as FormattedText.

prepare(record: logging.LogRecord, width: int | None = None) logging.LogRecord

Format certain attributes on the log record.

usesTime()

Check if the format uses the creation time of the record.

class euporie.core.log.LogTabFormatter(*args: Any, **kwargs: Any)

Bases: euporie.core.log.FtFormatter

Format log messages for display in the log view tab.

converter()
localtime([seconds]) -> (tm_year,tm_mon,tm_mday,tm_hour,tm_min,

tm_sec,tm_wday,tm_yday,tm_isdst)

Convert seconds since the Epoch to a time tuple expressing local time. When ‘seconds’ is not passed in, convert the current time instead.

default_msec_format = '%s,%03d'
default_time_format = '%Y-%m-%d %H:%M:%S'
format(record)

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

formatException(ei)

Format and return the specified exception information as a string.

This default implementation just uses traceback.print_exception()

formatMessage(record)
formatStack(stack_info)

This method is provided as an extension point for specialized formatting of stack information.

The input data is a string as returned from a call to traceback.print_stack(), but with the last trailing newline removed.

The base implementation just returns the value passed in.

formatTime(record, datefmt=None)

Return the creation time of the specified LogRecord as formatted text.

This method should be called from format() by a formatter which wants to make use of a formatted time. This method can be overridden in formatters to provide for any specific requirement, but the basic behaviour is as follows: if datefmt (a string) is specified, it is used with time.strftime() to format the creation time of the record. Otherwise, an ISO8601-like (or RFC 3339-like) format is used. The resulting string is returned. This function uses a user-configurable function to convert the creation time to a tuple. By default, time.localtime() is used; to change this for a particular formatter instance, set the ‘converter’ attribute to a function with the same signature as time.localtime() or time.gmtime(). To change it for all formatters, for example if you want all logging times to be shown in GMT, set the ‘converter’ attribute in the Formatter class.

format_traceback(tb: str) StyleAndTextTuples

Format a traceback string using pygments.

ft_format(record: logging.LogRecord, width: int | None = None) prompt_toolkit.formatted_text.base.FormattedText

Format a log record as formatted text.

prepare(record: logging.LogRecord, width: int | None = None) logging.LogRecord

Format certain attributes on the log record.

usesTime()

Check if the format uses the creation time of the record.

class euporie.core.log.QueueHandler(*args: Any, queue: deque, style: Style | None = None, **kwargs: Any)

Bases: logging.Handler

This handler store logs events into a queue.

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: logging.LogRecord) None

Queue unformatted records, as they will be formatted when accessed.

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.

formatter: FtFormatter
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.

classmethod hook(hook: Callable) int

Add a hook to run after each log entry.

Parameters

hook – The hook function to add

Returns

The hook id

hook_id = 0
hooks: dict[int, Callable] = {}
property name
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)
classmethod unhook(hook_id: int) None

Remove a hook function.

Parameters

hook_id – The ID of the hook function to remove

class euporie.core.log.StdoutFormatter(*args: Any, **kwargs: Any)

Bases: euporie.core.log.FtFormatter

A log formatter for formatting log entries for display on the standard output.

converter()
localtime([seconds]) -> (tm_year,tm_mon,tm_mday,tm_hour,tm_min,

tm_sec,tm_wday,tm_yday,tm_isdst)

Convert seconds since the Epoch to a time tuple expressing local time. When ‘seconds’ is not passed in, convert the current time instead.

default_msec_format = '%s,%03d'
default_time_format = '%Y-%m-%d %H:%M:%S'
format(record)

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

formatException(ei)

Format and return the specified exception information as a string.

This default implementation just uses traceback.print_exception()

formatMessage(record)
formatStack(stack_info)

This method is provided as an extension point for specialized formatting of stack information.

The input data is a string as returned from a call to traceback.print_stack(), but with the last trailing newline removed.

The base implementation just returns the value passed in.

formatTime(record, datefmt=None)

Return the creation time of the specified LogRecord as formatted text.

This method should be called from format() by a formatter which wants to make use of a formatted time. This method can be overridden in formatters to provide for any specific requirement, but the basic behaviour is as follows: if datefmt (a string) is specified, it is used with time.strftime() to format the creation time of the record. Otherwise, an ISO8601-like (or RFC 3339-like) format is used. The resulting string is returned. This function uses a user-configurable function to convert the creation time to a tuple. By default, time.localtime() is used; to change this for a particular formatter instance, set the ‘converter’ attribute to a function with the same signature as time.localtime() or time.gmtime(). To change it for all formatters, for example if you want all logging times to be shown in GMT, set the ‘converter’ attribute in the Formatter class.

format_traceback(tb: str) StyleAndTextTuples

Format a traceback string using pygments.

ft_format(record: logging.LogRecord, width: int | None = None) prompt_toolkit.formatted_text.base.FormattedText

Format log records for display on the standard output.

prepare(record: logging.LogRecord, width: int | None = None) logging.LogRecord

Format certain attributes on the log record.

usesTime()

Check if the format uses the creation time of the record.

euporie.core.log.add_log_level(name: str, number: int) None

Add a new level to the logger.

euporie.core.log.handle_exception(exc_type: type[BaseException], exc_value: BaseException, exc_traceback: TracebackType | None) Any

Log unhandled exceptions and their tracebacks in the log.

Parameters
  • exc_type – The type of the exception

  • exc_value – The exception instance

  • exc_traceback – The associated traceback

euporie.core.log.setup_logs(config: Config | None = None) None

Configure the logger for euporie.

class euporie.core.log.stdout_to_log(log: logging.Logger, output: str = "Literal['stdout','stderr']")

Bases: object

A decorator which captures standard output and logs it.