JSONFormatter.format()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 17
rs 9.4285
1
import json
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
import logging
3
import uuid
4
import time
5
from datetime import datetime
6
7
from foil.serializers import json_serializer
8
9
10
class JSONFormatter(logging.Formatter):
11
12
    converter = time.gmtime
13
14
    def format(self, record):
15
16
        event_dict = {
17
            'timestamp': datetime.utcfromtimestamp(record.created),
18
            'event_id': uuid.uuid4(),
19
            "name": record.name,
20
            "level": record.levelname,
21
            "message": record.msg,
22
            'pid': record.process,
23
            'thread': record.thread,
24
            'sourceFilePath': record.pathname,
25
            'module': record.module,
26
            'functionName': record.funcName,
27
            'lineNumber': record.lineno
28
        }
29
30
        return json.dumps(event_dict, default=json_serializer)
31