def Log(self, **kwargs): """Log a message. Receive the attributes of a LogRecord, rebuild and handle it. The given keyword arguments will contain: msg (string): the message to log. levelname (string): the name of the level, one of "DEBUG", "INFO", "WARNING", "ERROR" and "CRITICAL". levelno (int): a numeric value denoting the level, one of the constants defined by the logging module. In fact, `levelno == getattr(logging, levelname)` (yes, it is redundant). created (float): when the log message was emitted (as an UNIX timestamp, seconds from epoch). And they may contain: service_name (string) and service_shard (int): the coords of the service where this message was generated. operation (string): a high-level description of the long-term operation that is going on in the service. exc_text (string): the text of the logged exception. """ record = logging.makeLogRecord(kwargs) # Show in stdout, together with the messages we produce # ourselves. shell_handler.handle(record) # Write on the global log file. self.file_handler.handle(record) if record.levelno >= logging.WARNING: if hasattr(record, "service_name") and \ hasattr(record, "service_shard"): coord = "%s,%s" % (record.service_name, record.service_shard) else: coord = "" self._last_messages.append({ "message": record.msg, "coord": coord, "operation": getattr(record, "operation", ""), "severity": record.levelname, "timestamp": record.created, "exc_text": getattr(record, "exc_text", None) })
def Log(self, **kwargs): """Log a message. Receive the attributes of a LogRecord, rebuild and handle it. The given keyword arguments will contain: msg (string): the message to log. levelname (string): the name of the level, one of "DEBUG", "INFO", "WARNING", "ERROR" and "CRITICAL". levelno (int): a numeric value denoting the level, one of the constants defined by the logging module. In fact, `levelno == getattr(logging, levelname)` (yes, it is redundant). created (float): when the log message was emitted (as an UNIX timestamp, seconds from epoch). And they may contain: service_name (string) and service_shard (int): the coords of the service where this message was generated. operation (string): a high-level description of the long-term operation that is going on in the service. exc_text (string): the text of the logged exception. """ record = logging.makeLogRecord(kwargs) # Show in stdout, together with the messages we produce # ourselves. shell_handler.handle(record) # Write on the global log file. self.file_handler.handle(record) if record.levelno >= logging.WARNING: if hasattr(record, "service_name") and hasattr(record, "service_shard"): coord = "%s,%s" % (record.service_name, record.service_shard) else: coord = "" self._last_messages.append( { "message": record.msg, "coord": coord, "operation": getattr(record, "operation", ""), "severity": record.levelname, "timestamp": record.created, "exc_text": getattr(record, "exc_text", None), } )