structlog_sentry_logger._config

Module Contents

Classes

SentryBreadcrumbJsonProcessor

Addresses: SentryJsonProcessor breaks logging breadcrumbs #25

Functions

add_severity_field_from_level_if_in_cloud_environment(logger, method, event_dict)

A custom processor for structlog for Cloud Logging compatibility

deduce_module(prev_stack_frame)

get_caller_name(prev_stack_frame)

get_caller_name_from_frames(stack_frames)

get_config_dict()

Convenience function to get the local logging configuration dictionary,

get_formatters(timestamper)

get_git_root()

get_handlers(module_name)

get_logger(name = None)

Convenience function that returns a logger

get_logging_config(module_name, timestamper)

get_namespaced_module_name(__file__)

get_root_dir()

is_caller_main(caller_name)

is_cloud_logging_compatibility_mode_requested()

is_probably_in_cloud_environment()

Returns True if it is likely (but not guaranteed) logging is occurring in the context of a Cloud Logging environment

serializer(*args, default = None, option = orjson.OPT_NON_STR_KEYS | orjson.OPT_SORT_KEYS)

set_logging_config(module_name, timestamper)

set_structlog_config(timestamper)

Attributes

DATETIME_FORMAT

LOG_DATA_DIR

ROOT_DIR

getLogger

CamelCase alias for structlog_sentry_logger.get_logger.

structlog_sentry_logger._config.DATETIME_FORMAT = iso
structlog_sentry_logger._config.LOG_DATA_DIR
structlog_sentry_logger._config.ROOT_DIR
structlog_sentry_logger._config.getLogger

CamelCase alias for structlog_sentry_logger.get_logger.

class structlog_sentry_logger._config.SentryBreadcrumbJsonProcessor(breadcrumb_level=logging.INFO, level=logging.WARNING, active=True, as_extra=True, tag_keys=None)[source]

Bases: structlog_sentry_logger.structlog_sentry.SentryJsonProcessor

Inheritance diagram of structlog_sentry_logger._config.SentryBreadcrumbJsonProcessor

Addresses: SentryJsonProcessor breaks logging breadcrumbs #25 (source)

Parameters
  • level (int) – events of this or higher levels will be reported to Sentry.

  • active (bool) – a flag to make this processor enabled/disabled.

  • as_extra (bool) – send event_dict as extra info to Sentry.

  • tag_keys (Union[List[str], str]) – a list of keys. If any if these keys appear in event_dict, the key and its corresponding value in event_dict will be used as Sentry event tags. use “__all__” to report all key/value pairs of event as tags.

  • ignore_loggers – a list of logger names to ignore any events from.

  • breadcrumb_level (int) –

static save_breadcrumb(logger, event_dict)[source]
Parameters
  • logger (Any) –

  • event_dict (structlog.types.EventDict) –

Return type

None

structlog_sentry_logger._config.add_severity_field_from_level_if_in_cloud_environment(logger, method, event_dict)[source]

A custom processor for structlog for Cloud Logging compatibility

Since Cloud Logging infers log levels from the severity key, simply duplicates level to the severity field in the logger’s event dictionary.

Parameters
  • logger (Any) –

  • method (str) –

  • event_dict (structlog.types.EventDict) –

Return type

structlog.types.EventDict

structlog_sentry_logger._config.deduce_module(prev_stack_frame)[source]
Parameters

prev_stack_frame (inspect.FrameInfo) –

Return type

Optional[types.ModuleType]

structlog_sentry_logger._config.get_caller_name(prev_stack_frame)[source]
Parameters

prev_stack_frame (inspect.FrameInfo) –

Return type

str

structlog_sentry_logger._config.get_caller_name_from_frames(stack_frames)[source]
Parameters

stack_frames (List[inspect.FrameInfo]) –

Return type

str

structlog_sentry_logger._config.get_config_dict()[source]

Convenience function to get the local logging configuration dictionary, e.g., to help configure loggers from other libraries.

Returns: The logging configuration dictionary that would be used to configure the Python logging library component of the logger

Return type

dict

structlog_sentry_logger._config.get_formatters(timestamper)[source]
Parameters

timestamper (structlog.processors.TimeStamper) –

Return type

dict

structlog_sentry_logger._config.get_git_root()[source]
Return type

pathlib.Path

structlog_sentry_logger._config.get_handlers(module_name)[source]
Parameters

module_name (str) –

Return type

dict

structlog_sentry_logger._config.get_logger(name=None)[source]

Convenience function that returns a logger

Returns: A proxy that creates a correctly configured logger bound to the __name__ of the calling module

Parameters

name (Optional[str]) –

Return type

Any

structlog_sentry_logger._config.get_logging_config(module_name, timestamper)[source]
Parameters
  • module_name (str) –

  • timestamper (structlog.processors.TimeStamper) –

Return type

dict

structlog_sentry_logger._config.get_namespaced_module_name(__file__)[source]
Parameters

__file__ (Union[pathlib.Path, str]) –

Return type

str

structlog_sentry_logger._config.get_root_dir()[source]
Return type

pathlib.Path

structlog_sentry_logger._config.is_caller_main(caller_name)[source]
Parameters

caller_name (str) –

Return type

bool

structlog_sentry_logger._config.is_cloud_logging_compatibility_mode_requested()[source]
Return type

bool

structlog_sentry_logger._config.is_probably_in_cloud_environment()[source]

Returns True if it is likely (but not guaranteed) logging is occurring in the context of a Cloud Logging environment

Return type

bool

structlog_sentry_logger._config.serializer(*args, default=None, option=orjson.OPT_NON_STR_KEYS | orjson.OPT_SORT_KEYS)[source]
Parameters
  • args (Any) –

  • default (Optional[Callable[[Any], Any]]) –

  • option (Optional[int]) –

Return type

str

structlog_sentry_logger._config.set_logging_config(module_name, timestamper)[source]
Parameters
  • module_name (str) –

  • timestamper (structlog.processors.TimeStamper) –

Return type

None

structlog_sentry_logger._config.set_structlog_config(timestamper)[source]
Parameters

timestamper (structlog.processors.TimeStamper) –

Return type

None