fluidattacks_utils_logger 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fluidattacks_utils_logger/__init__.py +45 -0
- fluidattacks_utils_logger/env.py +37 -0
- fluidattacks_utils_logger/handlers.py +67 -0
- fluidattacks_utils_logger/levels.py +12 -0
- fluidattacks_utils_logger/logger.py +54 -0
- fluidattacks_utils_logger/py.typed +0 -0
- fluidattacks_utils_logger-1.0.0.dist-info/METADATA +9 -0
- fluidattacks_utils_logger-1.0.0.dist-info/RECORD +9 -0
- fluidattacks_utils_logger-1.0.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
|
|
3
|
+
import bugsnag
|
|
4
|
+
from fa_purity import (
|
|
5
|
+
Cmd,
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
from . import (
|
|
9
|
+
handlers,
|
|
10
|
+
logger,
|
|
11
|
+
)
|
|
12
|
+
from .env import (
|
|
13
|
+
current_app_env,
|
|
14
|
+
)
|
|
15
|
+
from .levels import (
|
|
16
|
+
LoggingLvl,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
__version__ = "1.0.0"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def set_main_log(
|
|
23
|
+
name: str,
|
|
24
|
+
conf: handlers.LoggingConf,
|
|
25
|
+
debug: bool,
|
|
26
|
+
show_time: bool,
|
|
27
|
+
) -> Cmd[None]:
|
|
28
|
+
_bug_handler = handlers.bug_handler(conf, LoggingLvl.ERROR)
|
|
29
|
+
_log_handler = handlers.logger_handler(debug, show_time, sys.stderr)
|
|
30
|
+
_handlers = (_log_handler, _bug_handler)
|
|
31
|
+
env = current_app_env()
|
|
32
|
+
display_env = logger.get_logger(name).bind(
|
|
33
|
+
lambda log: env.bind(lambda e: log.info("%s@%s", (name, e.value))), # noqa: PLE1206
|
|
34
|
+
)
|
|
35
|
+
return (
|
|
36
|
+
logger.set_logger(name, LoggingLvl.DEBUG if debug else LoggingLvl.INFO, _handlers)
|
|
37
|
+
+ display_env
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def start_session() -> Cmd[None]:
|
|
42
|
+
def _action() -> None:
|
|
43
|
+
bugsnag.start_session() # type: ignore[no-untyped-call]
|
|
44
|
+
|
|
45
|
+
return Cmd.wrap_impure(_action)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from enum import (
|
|
2
|
+
Enum,
|
|
3
|
+
)
|
|
4
|
+
from os import (
|
|
5
|
+
environ,
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
from fa_purity import (
|
|
9
|
+
Cmd,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Envs(Enum):
|
|
14
|
+
PROD = "production"
|
|
15
|
+
DEV = "development"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def current_app_env() -> Cmd[Envs]:
|
|
19
|
+
def _action() -> Envs:
|
|
20
|
+
return Envs(environ.get("OBSERVES_ENV", "production"))
|
|
21
|
+
|
|
22
|
+
return Cmd.wrap_impure(_action)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def observes_debug() -> Cmd[bool]:
|
|
26
|
+
def _action() -> bool:
|
|
27
|
+
_debug = environ.get("OBSERVES_DEBUG", "")
|
|
28
|
+
return _debug.lower() == "true"
|
|
29
|
+
|
|
30
|
+
return Cmd.wrap_impure(_action)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def notifier_key() -> Cmd[str]:
|
|
34
|
+
def _action() -> str:
|
|
35
|
+
return environ.get("bugsnag_notifier_key", "") # noqa: SIM112
|
|
36
|
+
|
|
37
|
+
return Cmd.wrap_impure(_action)
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from dataclasses import (
|
|
3
|
+
dataclass,
|
|
4
|
+
)
|
|
5
|
+
from logging import (
|
|
6
|
+
Formatter,
|
|
7
|
+
Handler,
|
|
8
|
+
)
|
|
9
|
+
from typing import (
|
|
10
|
+
IO,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
import bugsnag
|
|
14
|
+
from bugsnag.handlers import (
|
|
15
|
+
BugsnagHandler,
|
|
16
|
+
)
|
|
17
|
+
from fa_purity import (
|
|
18
|
+
Cmd,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
from fluidattacks_utils_logger.env import (
|
|
22
|
+
Envs,
|
|
23
|
+
)
|
|
24
|
+
from fluidattacks_utils_logger.levels import (
|
|
25
|
+
LoggingLvl,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass(frozen=True)
|
|
30
|
+
class LoggingConf:
|
|
31
|
+
app_type: str
|
|
32
|
+
app_version: str
|
|
33
|
+
project_root: str
|
|
34
|
+
auto_capture_sessions: bool
|
|
35
|
+
api_key: str
|
|
36
|
+
release_stage: Envs
|
|
37
|
+
app_name: str
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def bug_handler(conf: LoggingConf, min_lvl: LoggingLvl) -> Cmd[Handler]:
|
|
41
|
+
def _action() -> Handler:
|
|
42
|
+
bugsnag.configure( # type: ignore[no-untyped-call]
|
|
43
|
+
app_type=conf.app_type,
|
|
44
|
+
app_version=conf.app_version,
|
|
45
|
+
project_root=conf.project_root,
|
|
46
|
+
auto_capture_sessions=conf.auto_capture_sessions,
|
|
47
|
+
api_key=conf.api_key,
|
|
48
|
+
release_stage=conf.release_stage.value,
|
|
49
|
+
)
|
|
50
|
+
handler = BugsnagHandler() # type: ignore[no-untyped-call]
|
|
51
|
+
handler.setLevel(min_lvl.value)
|
|
52
|
+
return handler
|
|
53
|
+
|
|
54
|
+
return Cmd.wrap_impure(_action)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def logger_handler(debug: bool, show_time: bool, target: IO[str]) -> Cmd[Handler]:
|
|
58
|
+
def _action() -> Handler:
|
|
59
|
+
prefix = "%(name)s> " if debug else ""
|
|
60
|
+
_time = "%(asctime)s " if show_time else ""
|
|
61
|
+
_format = _time + prefix + "[%(levelname)s] %(message)s"
|
|
62
|
+
formatter = Formatter(_format)
|
|
63
|
+
handler = logging.StreamHandler(target)
|
|
64
|
+
handler.setFormatter(formatter)
|
|
65
|
+
return handler
|
|
66
|
+
|
|
67
|
+
return Cmd.wrap_impure(_action)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from dataclasses import (
|
|
3
|
+
dataclass,
|
|
4
|
+
)
|
|
5
|
+
|
|
6
|
+
from fa_purity import (
|
|
7
|
+
Cmd,
|
|
8
|
+
CmdUnwrapper,
|
|
9
|
+
FrozenList,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
from fluidattacks_utils_logger.levels import (
|
|
13
|
+
LoggingLvl,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass(frozen=True)
|
|
18
|
+
class _Logger:
|
|
19
|
+
logger: logging.Logger
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass(frozen=True)
|
|
23
|
+
class Logger:
|
|
24
|
+
_inner: _Logger
|
|
25
|
+
|
|
26
|
+
def critical(self, formatted_msg: str, values: FrozenList[str]) -> Cmd[None]:
|
|
27
|
+
return Cmd.wrap_impure(lambda: self._inner.logger.critical(formatted_msg, *values))
|
|
28
|
+
|
|
29
|
+
def debug(self, formatted_msg: str, values: FrozenList[str]) -> Cmd[None]:
|
|
30
|
+
return Cmd.wrap_impure(lambda: self._inner.logger.debug(formatted_msg, *values))
|
|
31
|
+
|
|
32
|
+
def info(self, formatted_msg: str, values: FrozenList[str]) -> Cmd[None]:
|
|
33
|
+
return Cmd.wrap_impure(lambda: self._inner.logger.info(formatted_msg, *values))
|
|
34
|
+
|
|
35
|
+
def warning(self, formatted_msg: str, values: FrozenList[str]) -> Cmd[None]:
|
|
36
|
+
return Cmd.wrap_impure(lambda: self._inner.logger.warning(formatted_msg, *values))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def get_logger(name: str) -> Cmd[Logger]:
|
|
40
|
+
def _action() -> Logger:
|
|
41
|
+
log = _Logger(logging.getLogger(name))
|
|
42
|
+
return Logger(log)
|
|
43
|
+
|
|
44
|
+
return Cmd.wrap_impure(_action)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def set_logger(name: str, lvl: LoggingLvl, handlers: FrozenList[Cmd[logging.Handler]]) -> Cmd[None]:
|
|
48
|
+
def _action(unwrapper: CmdUnwrapper) -> None:
|
|
49
|
+
log = logging.getLogger(name)
|
|
50
|
+
log.setLevel(lvl.value)
|
|
51
|
+
for item in handlers:
|
|
52
|
+
log.addHandler(unwrapper.act(item))
|
|
53
|
+
|
|
54
|
+
return Cmd.new_cmd(_action)
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fluidattacks_utils_logger
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Common logger handlers
|
|
5
|
+
Author-email: Product Team <development@fluidattacks.com>
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Requires-Dist: bugsnag >=4.7.0, <5.0.0
|
|
9
|
+
Requires-Dist: fa-purity >=2.1.0, <3.0.0
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
fluidattacks_utils_logger/__init__.py,sha256=pWxowwy3CXOoRx8YBtPSIluCi1MWEVVLjNreTEF_LPw,987
|
|
2
|
+
fluidattacks_utils_logger/env.py,sha256=g2SkTq-YhI9qdSOT4VGTZlLH1VGbBzPoR4YUvTkilVc,692
|
|
3
|
+
fluidattacks_utils_logger/handlers.py,sha256=Gzn-9Bv7UYOD2Ph0-2r1T86rlj2RlEEzhOCPHT-PqTk,1643
|
|
4
|
+
fluidattacks_utils_logger/levels.py,sha256=hjNMTVY-0669xOWHq6G3jV6dqYZigktalfH7OuqlTGU,210
|
|
5
|
+
fluidattacks_utils_logger/logger.py,sha256=YYCkoIosRXQXVDBoNuV_HFy0Ma_JOil3bd6CchYZ_Xc,1524
|
|
6
|
+
fluidattacks_utils_logger/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
fluidattacks_utils_logger-1.0.0.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
|
|
8
|
+
fluidattacks_utils_logger-1.0.0.dist-info/METADATA,sha256=x5LZkuMhAXuWlF8UF_4Pxb03JDjTtP-u23z4BEJH0Y8,314
|
|
9
|
+
fluidattacks_utils_logger-1.0.0.dist-info/RECORD,,
|