1
1
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
2
2
# If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
3
+ from enum import Enum
3
4
4
5
import structlog
5
6
import logging .config
6
7
from asgi_correlation_id import correlation_id
7
8
from flowkit_ui_backend .util .structlog .dev import ConsoleRenderer
8
9
from typing import Tuple , Any
9
10
11
+ from flowkit_ui_backend .util .structlog .types import Processor
12
+
13
+
14
+ class LogLevel (str , Enum ):
15
+ TRACE = "TRACE"
16
+ DEBUG = "DEBUG"
17
+ INFO = "INFO"
18
+ WARNING = "WARNING"
19
+ ERROR = "ERROR"
20
+ FATAL = "FATAL"
21
+
10
22
11
23
def add_correlation (
12
24
logger : logging .Logger , method_name : str , event_dict : dict [str , Any ]
@@ -17,19 +29,19 @@ def add_correlation(
17
29
return event_dict
18
30
19
31
20
- def setup_logging (log_level : str = " INFO" , dev_mode : bool = False ) -> None :
32
+ def setup_logging (log_level : LogLevel = LogLevel . INFO , dev_mode : bool = False ) -> None :
21
33
"""
22
34
Configure structured logging
23
35
24
36
Parameters
25
37
----------
26
- log_level : str , default 'INFO'
38
+ log_level : LogLevel , default 'INFO'
27
39
dev_mode : bool, default False
28
40
Set to true to use coloured logs and enhanced exception formatting, disables json formatting
29
41
"""
30
42
31
43
if dev_mode :
32
- processors : Tuple [flowkit_ui_backend . util . structlog . types . Processor , ...] = (
44
+ processors : Tuple [Processor , ...] = (
33
45
add_correlation ,
34
46
structlog .processors .TimeStamper (fmt = "%H:%M:%S.%f" ),
35
47
structlog .stdlib .add_log_level ,
@@ -43,7 +55,7 @@ def setup_logging(log_level: str = "INFO", dev_mode: bool = False) -> None:
43
55
)
44
56
45
57
else :
46
- processors : Tuple [flowkit_ui_backend . util . structlog . types . Processor , ...] = (
58
+ processors : Tuple [Processor , ...] = (
47
59
add_correlation ,
48
60
structlog .contextvars .merge_contextvars ,
49
61
structlog .processors .TimeStamper (fmt = "iso" ),
0 commit comments