本文整理汇总了Python中logging.LoggerAdapter方法的典型用法代码示例。如果您正苦于以下问题:Python logging.LoggerAdapter方法的具体用法?Python logging.LoggerAdapter怎么用?Python logging.LoggerAdapter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logging
的用法示例。
在下文中一共展示了logging.LoggerAdapter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LoggerAdapter [as 别名]
def setUp(self):
super(LoggerAdapterTest, self).setUp()
old_handler_list = logging._handlerList[:]
self.recording = RecordingHandler()
self.logger = logging.root
self.logger.addHandler(self.recording)
self.addCleanup(self.logger.removeHandler, self.recording)
self.addCleanup(self.recording.close)
def cleanup():
logging._handlerList[:] = old_handler_list
self.addCleanup(cleanup)
self.addCleanup(logging.shutdown)
self.adapter = logging.LoggerAdapter(logger=self.logger, extra=None)
示例2: __init__
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LoggerAdapter [as 别名]
def __init__(self, client: ClipboardLayer, server: ClipboardLayer, log: LoggerAdapter, recorder: Recorder,
statCounter: StatCounter):
"""
:param client: clipboard layer for the client side
:param server: clipboard layer for the server side
:param log: logger for this component
:param recorder: recorder for clipboard data
"""
self.statCounter = statCounter
self.client = client
self.server = server
self.log = log
self.recorder = recorder
self.forwardNextDataResponse = True
self.client.createObserver(
onPDUReceived = self.onClientPDUReceived,
)
self.server.createObserver(
onPDUReceived = self.onServerPDUReceived,
)
示例3: __init__
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LoggerAdapter [as 别名]
def __init__(self, viewer: QRemoteDesktop, text: QTextEdit, log: LoggerAdapter, fileSystem: FileSystem, layer: PlayerLayer, tabInstance: LiveTab):
super().__init__(viewer, text)
self.log = log
self.fileSystem = fileSystem
self.layer = layer
self.drives: Dict[int, Drive] = {}
self.downloadDirectories: Dict[str, Directory] = {}
self.downloadFiles: Dict[str, BinaryIO] = {}
self.downloadDialogs: Dict[str, FileDownloadDialog] = {}
self.tabInstance = tabInstance
# Clicking on an item and "downloading" is a job. Only one job at a time.
# We need to process each job independently to keep the dialog reliable
self.jobsQueue = set()
self.directoryDownloadQueue = set()
self.fileDownloadQueue = set()
self.currentDownload = None
self.handlers[PlayerPDUType.DIRECTORY_LISTING_RESPONSE] = self.handleDirectoryListingResponse
self.handlers[PlayerPDUType.FILE_DOWNLOAD_RESPONSE] = self.handleDownloadResponse
self.handlers[PlayerPDUType.FILE_DOWNLOAD_COMPLETE] = self.handleDownloadComplete
self.handlers[PlayerPDUType.CLIENT_DATA] = self.onClientData
self.handlers[PlayerPDUType.CONNECTION_CLOSE] = self.onConnectionClose
示例4: __init__
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LoggerAdapter [as 别名]
def __init__(self):
self.todo_queue = queue.PriorityQueue()
self.done_queues = {}
self.done_tasks_time = dict()
self.done_tasks_time_max = (60.0 * 20)
self.broadcast_todo_queue = {}
self.start_calc = {}
self.out_tasks = {}
self.proj_alive_time = {}
self.proj_alive_time_max = (60 * 5)
self.worker_alive_time = {}
self.worker_alive_time_max = (60 * 30)
self.pub_logger = logging.getLogger()
self.pub_logger.setLevel(logging.WARN)
if False:
h = logging.handlers.RotatingFileHandler(filename='./server.log', mode='a', maxBytes=1000000, backupCount=10)
else:
h = logging.handlers.RotatingFileHandler(filename='./server.log', mode='a')
f = logging.Formatter('%(asctime)s %(host)-16s %(job_id)-16s %(source_type)-8s %(levelname)-8s %(message)s')
h.setFormatter(f)
self.pub_logger.addHandler(h)
self.logger = logging.LoggerAdapter(logging.getLogger(), {'host': os.environ.get('HOSTNAME', 'unknown'), 'job_id': os.environ.get('PBS_JOBID', 'N/A').split('.')[0], 'source_type': 'queue_server', })
self.process = psutil.Process(os.getpid())
_thread.start_new_thread(QueueServer.remove_dead_projects_daemon, (self,))
示例5: log_config
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LoggerAdapter [as 别名]
def log_config(event, loglevel=None, botolevel=None):
if 'ResourceProperties' in event.keys():
if 'loglevel' in event['ResourceProperties'] and not loglevel:
loglevel = event['ResourceProperties']['loglevel']
if 'botolevel' in event['ResourceProperties'] and not botolevel:
loglevel = event['ResourceProperties']['botolevel']
if not loglevel:
loglevel = 'WARNING'
if not botolevel:
botolevel = 'ERROR'
# Set log verbosity levels
loglevel = getattr(logging, loglevel.upper(), 20)
botolevel = getattr(logging, botolevel.upper(), 40)
mainlogger = logging.getLogger()
mainlogger.setLevel(loglevel)
logging.getLogger('boto3').setLevel(botolevel)
logging.getLogger('botocore').setLevel(botolevel)
# Set log message format
logfmt = '[%(requestid)s][%(asctime)s][%(levelname)s] %(message)s \n'
mainlogger.handlers[0].setFormatter(logging.Formatter(logfmt))
return logging.LoggerAdapter(mainlogger, {'requestid': event['RequestId']})
示例6: log_config
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LoggerAdapter [as 别名]
def log_config(event, loglevel=None, botolevel=None):
if 'ResourceProperties' in event.keys():
if 'loglevel' in event['ResourceProperties'] and not loglevel:
loglevel = event['ResourceProperties']['loglevel']
if 'botolevel' in event['ResourceProperties'] and not botolevel:
loglevel = event['ResourceProperties']['botolevel']
if not loglevel:
loglevel = 'warning'
if not botolevel:
botolevel = 'error'
# Set log verbosity levels
loglevel = getattr(logging, loglevel.upper(), 20)
botolevel = getattr(logging, botolevel.upper(), 40)
mainlogger = logging.getLogger()
mainlogger.setLevel(loglevel)
logging.getLogger('boto3').setLevel(botolevel)
logging.getLogger('botocore').setLevel(botolevel)
# Set log message format
logfmt = '[%(requestid)s][%(asctime)s][%(levelname)s] %(message)s \n'
mainlogger.handlers[0].setFormatter(logging.Formatter(logfmt))
return logging.LoggerAdapter(mainlogger, {'requestid': event['RequestId']})
示例7: get_event_log
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LoggerAdapter [as 别名]
def get_event_log(pipeline_context: PipelineContext = None) \
-> logging.Logger:
"""Get an instance of pipeline event logger.
:Parameters:
----------
pipe_context : PipelineContext
:Returns:
-------
type
Implementation of logging.Logger that handles pipeline events
"""
pipeline_event_log = logging.getLogger(TIMELINE_EVENT_LOGGER_NAME)
# wrap logger in an adapter that carries pipeline context
# such as pipeline name and current pipe element.
pipeline_event_log = logging.LoggerAdapter(
pipeline_event_log,
{PIPELINE_CONTEXT_KEY: pipeline_context})
return pipeline_event_log
示例8: __call__
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LoggerAdapter [as 别名]
def __call__( # lgtm[py/similar-function]
self,
*args: Any,
type: str,
event: bodies.RawEvent,
body: bodies.Body,
meta: bodies.Meta,
spec: bodies.Spec,
status: bodies.Status,
uid: str,
name: str,
namespace: Optional[str],
patch: patches.Patch,
logger: Union[logging.Logger, logging.LoggerAdapter],
**kwargs: Any,
) -> _SyncOrAsyncResult: ...
示例9: run
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LoggerAdapter [as 别名]
def run(self, logger=None, **kwargs):
# type: (Union[logging.Logger, logging.LoggerAdapter], **Any) -> Iterator[Metric]
if logger is None:
logger = null_logger # For convenience in unit tests and example scripts.
logger.debug('document_query %s', self.name)
for document, tags in self.source(**kwargs):
logger.debug('%s %r', self.name, document)
for spec in self.metrics:
yield self._make_metric_from_spec(document, spec, tags=tags)
for enumeration in self.enumerations:
for metric in self._make_metrics_from_enumeration(document, enumeration, tags=tags):
yield metric
for group in self.groups:
for metric in self._make_metrics_from_group(document, group, tags=tags):
yield metric
示例10: send_safe_iter
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LoggerAdapter [as 别名]
def send_safe_iter(signal, logger, sender, **kwargs):
utilities.assert_arg_type(signal, str, 1)
utilities.assert_arg_type(logger, (logging.Logger, logging.LoggerAdapter), 2)
signal = blinker.signal(signal)
for receiver in signal.receivers_for(sender):
try:
result = receiver(sender, **kwargs)
except Exception:
calling_frame = inspect.stack()[1]
logger.error("an error occurred while emitting signal '{0}' from {1}:{2}".format(signal, calling_frame[1], calling_frame[2]), exc_info=True)
else:
yield (receiver, result)
return
示例11: upload_scratch_metadata
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LoggerAdapter [as 别名]
def upload_scratch_metadata(self, koji_metadata, koji_upload_dir, koji_session):
metadata_file = NamedTemporaryFile(prefix="metadata", suffix=".json", mode='wb')
metadata_file.write(json.dumps(koji_metadata, indent=2).encode('utf-8'))
metadata_file.flush()
filename = "metadata.json"
meta_output = Output(file=metadata_file, metadata={'filename': filename})
try:
self.upload_file(koji_session, meta_output, koji_upload_dir)
path = os.path.join(koji_upload_dir, filename)
log = logging.LoggerAdapter(self.log, {'arch': METADATA_TAG})
log.info(path)
finally:
meta_output.file.close()
示例12: __init__
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LoggerAdapter [as 别名]
def __init__(self, build, cluster_info, logger):
self.build = build
self.cluster = cluster_info.cluster
self.osbs = cluster_info.osbs
self.platform = cluster_info.platform
self.log = logging.LoggerAdapter(logger, {'arch': self.platform})
self.monitor_exception = None
示例13: config
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LoggerAdapter [as 别名]
def config(self, loglevel='warning'):
loglevel = logging.getLevelName(loglevel.upper())
mainlogger = logging.getLogger()
mainlogger.setLevel(loglevel)
logfmt = '{"time_stamp": "%(asctime)s", "log_level": "%(levelname)s", "log_message": %(message)s}\n'
if len(mainlogger.handlers) == 0:
mainlogger.addHandler(logging.StreamHandler())
mainlogger.handlers[0].setFormatter(logging.Formatter(logfmt))
self.log = logging.LoggerAdapter(mainlogger, {})
示例14: logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LoggerAdapter [as 别名]
def logger(self):
# Copy that to log
extra = {"channelid" : self.channel.id, "userid": self.author.id}
logger = logging.LoggerAdapter(self.bot.base_logger, extra)
return logger
示例15: logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LoggerAdapter [as 别名]
def logger(self):
if not self._logger:
extra = {"channelid": self.channel.id, "userid": 0}
self._logger = logging.LoggerAdapter(self.bot.base_logger, extra)
return self._logger