def enqueue(self, record, message, *, resource=None, labels=None, trace=None, span_id=None): """Queues a log entry to be written by the background thread. Args: record (logging.LogRecord): Python log record that the handler was called with. message (str): The message from the ``LogRecord`` after being formatted by the associated log formatters. resource (Optional[google.cloud.logging_v2.resource.Resource]): Monitored resource of the entry labels (Optional[dict]): Mapping of labels for the entry. trace (Optional[str]): TraceID to apply to the logging entry. span_id (Optional[str]): Span_id within the trace for the log entry. Specify the trace parameter if span_id is set. """ queue_entry = { "info": { "message": message, "python_logger": record.name }, "severity": _helpers._normalize_severity(record.levelno), "resource": resource, "labels": labels, "trace": trace, "span_id": span_id, "timestamp": datetime.datetime.utcfromtimestamp(record.created), } self._queue.put_nowait(queue_entry)
def my_enqueue(self, record, message, **kwargs): queue_entry = { "info": { "message": message, "python_logger": record.name, "origin": origin }, "severity": _helpers._normalize_severity(record.levelno), "timestamp": datetime.datetime.utcfromtimestamp(record.created), } queue_entry.update(kwargs) self._queue.put_nowait(queue_entry)
def send(self, record, message, **kwargs): """Overrides transport.send(). Args: record (logging.LogRecord): Python log record that the handler was called with. message (str): The message from the ``LogRecord`` after being formatted by the associated log formatters. kwargs: Additional optional arguments for the logger """ info = {"message": message, "python_logger": record.name} self.logger.log_struct( info, severity=_helpers._normalize_severity(record.levelno), **kwargs, )
def _worker_enqueue(self, record, info, resource=None, labels=None, trace=None, span_id=None, **kwargs): queue_entry = { "info": info, "severity": _helpers._normalize_severity(record.levelno), "resource": resource, "labels": labels, "trace": trace, "span_id": span_id, "timestamp": datetime.datetime.utcfromtimestamp(record.created), } self.worker._queue.put_nowait(queue_entry)
def enqueue(self, record, message, **kwargs): """Queues a log entry to be written by the background thread. Args: record (logging.LogRecord): Python log record that the handler was called with. message (str): The message from the ``LogRecord`` after being formatted by the associated log formatters. kwargs: Additional optional arguments for the logger """ queue_entry = { "info": { "message": message, "python_logger": record.name }, "severity": _helpers._normalize_severity(record.levelno), "timestamp": datetime.datetime.utcfromtimestamp(record.created), } queue_entry.update(kwargs) self._queue.put_nowait(queue_entry)
def send(self, record, message, **kwargs): """Overrides transport.send(). Args: record (logging.LogRecord): Python log record that the handler was called with. message (str or dict): The message from the ``LogRecord`` after being formatted by the associated log formatters. kwargs: Additional optional arguments for the logger """ # set python logger name as label if missing labels = kwargs.pop("labels", {}) if record.name: labels["python_logger"] = labels.get("python_logger", record.name) # send log synchronously self.logger.log( message, severity=_helpers._normalize_severity(record.levelno), labels=labels, **kwargs, )
def my_enqueue(self, record, message, resource=None, labels=None, trace=None, span_id=None): queue_entry = { "info": { "message": message, "python_logger": record.name, "origin": origin }, "severity": _helpers._normalize_severity(record.levelno), "resource": resource, "labels": labels, "trace": trace, "span_id": span_id, "timestamp": datetime.datetime.utcfromtimestamp(record.created), } self._queue.put_nowait(queue_entry)
def enqueue(self, record, message, **kwargs): """Queues a log entry to be written by the background thread. Args: record (logging.LogRecord): Python log record that the handler was called with. message (str or dict): The message from the ``LogRecord`` after being formatted by the associated log formatters. kwargs: Additional optional arguments for the logger """ # set python logger name as label if missing labels = kwargs.pop("labels", {}) if record.name: labels["python_logger"] = labels.get("python_logger", record.name) kwargs["labels"] = labels # enqueue new entry queue_entry = { "message": message, "severity": _helpers._normalize_severity(record.levelno), "timestamp": datetime.datetime.utcfromtimestamp(record.created), } queue_entry.update(kwargs) self._queue.put_nowait(queue_entry)
def send( self, record, message, *, resource=None, labels=None, trace=None, span_id=None ): """Overrides transport.send(). Args: record (logging.LogRecord): Python log record that the handler was called with. message (str): The message from the ``LogRecord`` after being formatted by the associated log formatters. resource (Optional[~logging_v2.resource.Resource]): Monitored resource of the entry. labels (Optional[dict]): Mapping of labels for the entry. """ info = {"message": message, "python_logger": record.name} self.logger.log_struct( info, severity=_helpers._normalize_severity(record.levelno), resource=resource, labels=labels, trace=trace, span_id=span_id, )
def _normalize_severity_helper(self, stdlib_level, enum_level): from google.cloud.logging_v2._helpers import _normalize_severity self.assertEqual(_normalize_severity(stdlib_level), enum_level)