Browse Source

Update

master
ralongit 1 year ago
parent
commit
1620831da2
3 changed files with 5 additions and 2 deletions
  1. +2
    -0
      README.md
  2. +0
    -1
      logzio-failures-04072023-110807.txt
  3. +3
    -1
      logzio/handler.py

+ 2
- 0
README.md View File

@ -171,6 +171,7 @@ The following additional code example offers the same functionlites that availav
from logzio.handler import ExtraFieldsLogFilter from logzio.handler import ExtraFieldsLogFilter
def main(): def main():
logger.info("Test log") # Outputs: {"message":"Test log"} logger.info("Test log") # Outputs: {"message":"Test log"}
extra_fields = {"foo":"bar","counter":1} extra_fields = {"foo":"bar","counter":1}
@ -183,6 +184,7 @@ def main():
# If you'd like to remove filters from future logs using the logger.removeFilter option: # If you'd like to remove filters from future logs using the logger.removeFilter option:
logger.removeFilter(ExtraFieldsLogFilter(error_fields)) logger.removeFilter(ExtraFieldsLogFilter(error_fields))
logger.debug("Debug test log") # Outputs: {"message":"Debug test log","foo":"bar","counter":1} logger.debug("Debug test log") # Outputs: {"message":"Debug test log","foo":"bar","counter":1}
``` ```
## Django configuration ## Django configuration


+ 0
- 1
logzio-failures-04072023-110807.txt View File

@ -1 +0,0 @@
{"logger": "test", "line_number": 102, "path_name": "/Users/raulgurshumov/Desktop/logzio/logzio-python-handler/tests/test_logzioSender.py", "log_level": "INFO", "type": "type", "message": "Backup to local filesystem", "@timestamp": "2023-07-04T08:07:58.949Z", "key": "value"}

+ 3
- 1
logzio/handler.py View File

@ -8,6 +8,7 @@ import logging.handlers
from .sender import LogzioSender from .sender import LogzioSender
from .exceptions import LogzioException from .exceptions import LogzioException
class ExtraFieldsLogFilter(logging.Filter): class ExtraFieldsLogFilter(logging.Filter):
def __init__(self, extra: dict, *args, **kwargs): def __init__(self, extra: dict, *args, **kwargs):
@ -18,6 +19,7 @@ class ExtraFieldsLogFilter(logging.Filter):
record.__dict__.update(self.extra) record.__dict__.update(self.extra)
return True return True
class LogzioHandler(logging.Handler): class LogzioHandler(logging.Handler):
def __init__(self, def __init__(self,
@ -104,7 +106,7 @@ pip install 'logzio-python-handler[opentelemetry-logging]'""")
def format_message(self, message): def format_message(self, message):
now = datetime.datetime.utcnow() now = datetime.datetime.utcnow()
timestamp = now.strftime('%Y-%m-%dT%H:%M:%S') + \ timestamp = now.strftime('%Y-%m-%dT%H:%M:%S') + \
'.%03d' % (now.microsecond / 1000) + 'Z'
'.%03d' % (now.microsecond / 1000) + 'Z'
return_json = { return_json = {
'logger': message.name, 'logger': message.name,


Loading…
Cancel
Save