Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from sqlalchemy.exc import ResourceClosedError
from tohu import *
import argparse
import datetime
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
import structlog
import json
structlog.configure(
processors=[
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.TimeStamper(fmt="iso"),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.processors.JSONRenderer(serializer=json.dumps),
]
)
logger = structlog.get_logger(__name__)
parser = argparse.ArgumentParser(description="Flowminder Synthetic CDR Generator\n")
parser.add_argument(
"--n-subscribers", type=int, default=4000, help="Number of subscribers to generate."
)
parser.add_argument(
"--n-cells", type=int, default=1000, help="Number of cells to generate."
)
parser.add_argument(
"--n-calls", type=int, default=200_000, help="Number of calls to generate per day."
)
parser.add_argument(
"--subscribers-seed",
def test_bind_request_id_on_message_receive(mocker):
wrapped = Mock()
instance = Mock()
wrapped.__call__ = mocked_function.__call__
args0 = {}
kwargs = {}
args = [args0]
mocker.patch("uuid.uuid4", return_value="12345")
structlog.configure(
processors=[
structlog.processors.TimeStamper(fmt="ISO"),
structlog.processors.JSONRenderer(),
],
context_class=structlog.threadlocal.wrap_dict(dict),
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)
_bind_request_id_on_message_receive(wrapped, instance, args, kwargs)
request_id = structlog.get_config()["context_class"]._tl.dict_["request_id"]
assert request_id == '12345'
structlog.stdlib._FixedFindCallerLogger.aimetrics = ( # pylint: disable=protected-access
aimetrics
)
structlog.stdlib.BoundLogger.aimetrics = aimetrics
structlog.configure(
processors=[
structlog.stdlib.add_log_level,
structlog.stdlib.ProcessorFormatter.wrap_for_formatter,
],
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)
formatter = structlog.stdlib.ProcessorFormatter(
processor=structlog.processors.JSONRenderer(indent=2, sort_keys=True)
)
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger = logging.getLogger(name)
logger.addHandler(handler)
logger.setLevel(level)
return structlog.wrap_logger(logger)
rename_level_to_severity,
timestamper,
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
add_func_name,
add_message,
order_keys(key_order),
structlog.stdlib.ProcessorFormatter.wrap_for_formatter,
]
if for_humans:
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,
]
def configure_logging(debug=False, syslog=False, silenced_loggers=None,
level_overrides=None):
if silenced_loggers is None:
silenced_loggers = []
if level_overrides is None:
level_overrides = {}
level = 'DEBUG' if debug else 'INFO'
renderers = [
dev.ConsoleRenderer(),
] if debug else [
logstash_processor,
processors.JSONRenderer(separators=(',', ':')),
add_syslog_program(syslog),
]
structlog_processors = [
stdlib.filter_by_level,
stdlib.add_logger_name,
stdlib.add_log_level,
fix_logger_name,
format_request,
ensure_event,
stdlib.PositionalArgumentsFormatter(),
processors.TimeStamper(fmt="ISO", key='@timestamp'),
processors.StackInfoRenderer(),
processors.format_exc_info,
] + renderers
configure(
def config_logging():
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(sort_keys=True)
],
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M:%S.%f"),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.dev.ConsoleRenderer()
]
else:
chain = [
LogEntryProcessor.add_app_info,
LogEntryProcessor.add_logger_name,
LogEntryProcessor.add_timestamp,
LogEntryProcessor.censor_password,
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
LogEntryProcessor.cleanup_keynames,
structlog.processors.JSONRenderer()
]
structlog.configure_once(
processors=chain,
context_class=dict,
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)
def __config_logger__(self):
logging.basicConfig(
level=logging.INFO, format=self.log_format, stream=sys.stdout,
)
structlog.configure(
processors=[
structlog.stdlib.filter_by_level,
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.processors.JSONRenderer(),
],
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
)
return structlog.get_logger("Startup")
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