Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"class": "raven.handlers.logging.SentryHandler",
"level": "ERROR",
"release": None,
"dsn": None,
"transport": None,
},
},
"root": {"level": expected_level, "handlers": ["primary", "sentry"]},
}
)
]
assert configure.calls == [
pretend.call(
processors=[
structlog.stdlib.filter_by_level,
structlog.stdlib.add_logger_name,
structlog.stdlib.add_log_level,
mock.ANY,
mock.ANY,
structlog.processors.format_exc_info,
wlogging.RENDERER,
],
logger_factory=mock.ANY,
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)
]
assert isinstance(
configure.calls[0].kwargs["processors"][3],
structlog.stdlib.PositionalArgumentsFormatter,
)
assert isinstance(
def receiver_setup_logging(
loglevel, logfile, format, colorize, **kwargs
): # pragma: no cover
logging.config.dictConfig(settings.LOGGING)
structlog.configure(
processors=[
structlog.stdlib.filter_by_level,
structlog.processors.TimeStamper(fmt="iso"),
structlog.stdlib.add_logger_name,
structlog.stdlib.add_log_level,
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.processors.UnicodeDecoder(),
structlog.processors.ExceptionPrettyPrinter(),
# structlog.processors.KeyValueRenderer(),
structlog.stdlib.ProcessorFormatter.wrap_for_formatter,
],
context_class=structlog.threadlocal.wrap_dict(dict),
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)
'stream': sys.stdout,
},
'error': {
'class': 'logging.StreamHandler',
'stream': sys.stderr,
},
},
}
logging.config.dictConfig(logging_config)
structlog.configure(
processors=[
contextvars.merge_contextvars,
structlog.stdlib.filter_by_level,
structlog.stdlib.add_logger_name,
structlog.stdlib.add_log_level,
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.TimeStamper(fmt='iso'),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.processors.UnicodeDecoder(),
structlog.processors.KeyValueRenderer(
key_order=['timestamp', 'logger', 'level', 'event']
),
],
context_class=dict,
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)
renderer = structlog.dev.ConsoleRenderer() # <===
else:
# Make it so that 0 ⇒ None
indent = json_indent or None
renderer = structlog.processors.JSONRenderer(
indent=indent,
serializer=serialize.dumps
)
foreign_pre_chain = [
# Add the log level and a timestamp to the event_dict if the log entry
# is not from structlog.
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.stdlib.add_log_level,
structlog.stdlib.add_logger_name,
foreign_event_to_message,
rename_level_to_severity,
timestamper,
]
if level_name == 'DEBUG':
root_logger_level = 'DEBUG'
else:
root_logger_level = 'ERROR'
logging_config = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'structlog': {
'()': structlog.stdlib.ProcessorFormatter,
def getLogger(name):
return wrap_logger(
logging.getLogger(name),
processors=[
PositionalArgumentsFormatter(),
filter_by_level,
add_logger_name,
add_caller_info,
#local_var_info,
unorder_dict,
TimeStamper(fmt="ISO", utc=False),
format_exc_info,
alternate_dev_formatter()
],
wrapper_class=BoundLogger,
)
log_json: bool = False,
log_file: str = None,
disable_debug_logfile: bool = False,
debug_log_file_name: str = None,
cache_logger_on_first_use: bool = True,
_first_party_packages: FrozenSet[str] = _FIRST_PARTY_PACKAGES,
_debug_log_file_additional_level_filters: Dict[str, str] = None,
) -> None:
structlog.reset_defaults()
logger_level_config = logger_level_config or dict()
logger_level_config.setdefault("filelock", "ERROR")
logger_level_config.setdefault("", DEFAULT_LOG_LEVEL)
processors = [
structlog.stdlib.add_logger_name,
structlog.stdlib.add_log_level,
add_greenlet_name,
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M:%S.%f"),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
]
if log_json:
formatter = "json"
elif colorize and not log_file:
formatter = "colorized"
else:
formatter = "plain"
redact = redactor(LOG_BLACKLIST)
def get_processors(*extra_processors, pretty: bool = True):
processors = [
structlog.stdlib.filter_by_level,
structlog.stdlib.add_logger_name,
structlog.stdlib.add_log_level,
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.TimeStamper(fmt='iso'),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.processors.UnicodeDecoder(),
*extra_processors,
]
if pretty:
renderer = structlog.dev.ConsoleRenderer(pad_event=40)
else:
renderer = structlog.processors.JSONRenderer(rapidjson.dumps)
processors.append(renderer)
return processors
from flowmachine.core import connect
from .query_proxy import (
QueryProxy,
MissingQueryError,
QueryProxyError,
construct_query_object,
InvalidGeographyError,
)
from .zmq_interface import ZMQMultipartMessage, ZMQInterfaceError
import structlog
structlog.configure(
processors=[
structlog.stdlib.filter_by_level,
structlog.stdlib.add_logger_name,
structlog.stdlib.add_log_level,
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.TimeStamper(fmt="iso"),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.processors.JSONRenderer(),
],
context_class=dict,
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)
logger = logging.getLogger("flowmachine").getChild(__name__)
# Logger for all queries run or accessed
query_run_log = logging.getLogger("flowmachine-server")
# "formatter": "plain",
# },
},
"loggers": {
"": {
"handlers": ["default"],
# "handlers": ["default", "file"],
"level": "DEBUG",
"propagate": True,
}
},
}
)
structlog.configure(
processors=[
structlog.stdlib.add_logger_name,
structlog.stdlib.add_log_level,
structlog.stdlib.PositionalArgumentsFormatter(),
timestamper,
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.stdlib.ProcessorFormatter.wrap_for_formatter,
],
context_class=dict,
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)
'warn': 'WARNING',
'warning': 'WARNING',
'info': 'INFO',
'debug': 'DEBUG',
'notset': 'NOTSET',
}
def add_log_level(logger, method_name, event_dict):
event_dict['level'] = _METHOD_TO_NAME[method_name]
return event_dict
STRUCTLOG_PROCESSORS = [
structlog.stdlib.filter_by_level,
structlog.stdlib.add_logger_name,
add_log_level,
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.TimeStamper(fmt='iso', key='@timestamp'),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.processors.JSONRenderer(),
]