pyra.logger#

Responsible for logging related functions.

class pyra.logger.BlacklistFilter[source]#

Bases: Filter

Filter logs for blacklisted words.

Log filter for blacklisted tokens and passwords.

Examples

>>> BlacklistFilter()
<pyra.logger.BlacklistFilter object at 0x...>

Methods

filter:

Filter the given record.

filter(record) bool[source]#

Filter the given record.

Todo

This documentation needs to be improved.

Parameters:
recordBlacklistFilter

The record to filter.

Returns:
bool

True in all cases.

Examples

>>> BlacklistFilter().filter(record=BlacklistFilter())
True
class pyra.logger.EmailFilter[source]#

Bases: RegexFilter

Log filter for email addresses.

Class responsible for filtering email addresses.

Examples

>>> EmailFilter()
<pyra.logger.EmailFilter object at 0x...>
Attributes:
regexre.compile

The compiled regex pattern.

Methods

replace:

Filter that replaces a string within another string.

replace(text: str, email: str) str[source]#

Filter an email address.

Filter the given email address out of the given text.

Parameters:
textstr

The text to replace the email address within.

emailstr

The email address to replace with asterisks.

Returns:
str

The original text with the email address replaced.

Examples

>>> EmailFilter().replace(text='Testing example@example.com', email='example@example.com')
'Testing ****************@********'
class pyra.logger.NoThreadFilter(threadName)[source]#

Bases: Filter

Log filter for the current thread.

Todo

This documentation needs to be improved.

Parameters:
threadNamestr

The name of the thread.

Examples

>>> NoThreadFilter('main')
<pyra.logger.NoThreadFilter object at 0x...>

Methods

filter:

Filter the given record.

filter(record) bool[source]#

Filter the given record.

Todo

This documentation needs to be improved.

Parameters:
recordNoThreadFilter

The record to filter.

Returns:
bool

True if record.threadName is not equal to self.threadName, otherwise False.

Examples

>>> NoThreadFilter('main').filter(record=NoThreadFilter('test'))
True
>>> NoThreadFilter('main').filter(record=NoThreadFilter('main'))
False
class pyra.logger.PlexTokenFilter[source]#

Bases: RegexFilter

Log filter for X-Plex-Token.

Class responsible for filtering Plex tokens.

Examples

>>> PlexTokenFilter()
<pyra.logger.PlexTokenFilter object at 0x...>
Attributes:
regexre.compile

The compiled regex pattern.

Methods

replace:

Filter that replaces a string within another string.

replace(text: str, token: str) str[source]#

Filter a token.

Filter the given token out of the given text.

Parameters:
textstr

The text to replace the token within.

tokenstr

The token to replace with asterisks.

Returns:
str

The original text with the token replaced.

Examples

>>> PlexTokenFilter().replace(text='x-plex-token=5FBCvHo9vFf9erz8ssLQ', token='5FBCvHo9vFf9erz8ssLQ')
'x-plex-token=****************'
class pyra.logger.PublicIPFilter[source]#

Bases: RegexFilter

Log filter for public IP addresses.

Class responsible for filtering public IP addresses.

Examples

>>> PublicIPFilter()
<pyra.logger.PublicIPFilter object at 0x...>
Attributes:
regexre.compile

The compiled regex pattern.

Methods

replace:

Filter that replaces a string within another string.

replace(text: str, ip: str) str[source]#

Filter a public address.

Filter the given ip address out of the given text. The ip address will only be filter if it is public.

Parameters:
textstr

The text to replace the ip address within.

ipstr

The ip address to replace with asterisks.

Returns:
str

The original text with the ip address replaced.

Examples

>>> PublicIPFilter().replace(text='Testing 172.1.7.5', ip='172.1.7.5')
'Testing ***.***.***.***'
class pyra.logger.RegexFilter[source]#

Bases: Filter

Base class for regex log filter.

Log filter for regex.

Examples

>>> RegexFilter()
<pyra.logger.RegexFilter object at 0x...>
Attributes:
regexre.compile

The compiled regex pattern.

Methods

filter:

Filter the given record.

filter(record) bool[source]#

Filter the given record.

Todo

This documentation needs to be improved.

Parameters:
recordRegexFilter

The record to filter.

Returns:
bool

True in all cases.

Examples

>>> RegexFilter().filter(record=RegexFilter())
True
pyra.logger.blacklist_config(config: ConfigObj)[source]#

Update blacklist words.

In order to filter words out of the logs, it is required to call this function.

Values in the config for keys containing the following terms will be removed.

  • HOOK

  • APIKEY

  • KEY

  • PASSWORD

  • TOKEN

Parameters:
configConfigObj

Config to parse.

Examples

>>> config_object = pyra.config.create_config(config_file='config.ini')
>>> blacklist_config(config=config_object)
pyra.logger.get_logger(name: str) Logger[source]#

Get a logger.

Return the logging.Logger object for a given name. Additionally, replaces logger.warn with logger.warning.

Parameters:
namestr

The name of the logger to get.

Returns:
logging.Logger

The logging.Logger object.

Examples

>>> get_logger(name='retroarcher')
<Logger retroarcher (WARNING)>
pyra.logger.init_logger(log_name: str) Logger[source]#

Create a logger.

Creates a logging.Logger object from the given log name.

Parameters:
log_namestr

The name of the log to create.

Returns:
logging.Logger

The logging.Logger object.

Examples

>>> init_logger(log_name='retroarcher')
<Logger retroarcher (INFO)>
pyra.logger.init_multiprocessing(logger: Logger)[source]#

Remove all handlers and add QueueHandler on top.

This should only be called inside a multiprocessing worker process, since it changes the logger completely.

Parameters:
loggerlogging.Logger

The logger to initialize for multiprocessing.

Examples

>>> logger = get_logger(name='retroarcher')
>>> init_multiprocessing(logger=logger)
pyra.logger.listener(logger: Logger)[source]#

Create a QueueListener.

Wrapper that create a QueueListener, starts it and automatically stops it. To be used in a with statement in the main process, for multiprocessing.

Parameters:
loggerlogging.Logger

The logger object.

Examples

>>> logger = get_logger(name='retroarcher')
>>> listener(logger=logger)
pyra.logger.setup_loggers()[source]#

Setup all loggers.

Setup all the available loggers.

Examples

>>> setup_loggers()
pyra.logger.shutdown()[source]#

Stop logging.

Shutdown logging.

Examples

>>> shutdown()