fluidattacks_utils_logger 1.0.0__tar.gz
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-1.0.0/.envrc +2 -0
- fluidattacks_utils_logger-1.0.0/PKG-INFO +9 -0
- fluidattacks_utils_logger-1.0.0/build/default.nix +22 -0
- fluidattacks_utils_logger-1.0.0/build/deps/arch_lint.nix +17 -0
- fluidattacks_utils_logger-1.0.0/build/deps/default.nix +18 -0
- fluidattacks_utils_logger-1.0.0/build/deps/fa_purity.nix +19 -0
- fluidattacks_utils_logger-1.0.0/build/filter.nix +11 -0
- fluidattacks_utils_logger-1.0.0/flake.lock +172 -0
- fluidattacks_utils_logger-1.0.0/flake.nix +19 -0
- fluidattacks_utils_logger-1.0.0/fluidattacks_utils_logger/__init__.py +45 -0
- fluidattacks_utils_logger-1.0.0/fluidattacks_utils_logger/env.py +37 -0
- fluidattacks_utils_logger-1.0.0/fluidattacks_utils_logger/handlers.py +67 -0
- fluidattacks_utils_logger-1.0.0/fluidattacks_utils_logger/levels.py +12 -0
- fluidattacks_utils_logger-1.0.0/fluidattacks_utils_logger/logger.py +54 -0
- fluidattacks_utils_logger-1.0.0/fluidattacks_utils_logger/py.typed +0 -0
- fluidattacks_utils_logger-1.0.0/mypy.ini +30 -0
- fluidattacks_utils_logger-1.0.0/pyproject.toml +15 -0
- fluidattacks_utils_logger-1.0.0/ruff.toml +37 -0
- fluidattacks_utils_logger-1.0.0/tests/__init__.py +0 -0
- fluidattacks_utils_logger-1.0.0/tests/arch/__init__.py +0 -0
- fluidattacks_utils_logger-1.0.0/tests/arch/arch.py +39 -0
- fluidattacks_utils_logger-1.0.0/tests/arch/test_arch.py +43 -0
- fluidattacks_utils_logger-1.0.0/tests/py.typed +0 -0
- fluidattacks_utils_logger-1.0.0/uv.lock +43 -0
|
@@ -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,22 @@
|
|
|
1
|
+
{ nixpkgs, pynix, src, }:
|
|
2
|
+
let
|
|
3
|
+
deps = import ./deps { inherit nixpkgs pynix; };
|
|
4
|
+
requirements = python_pkgs: {
|
|
5
|
+
runtime_deps = with deps.python_pkgs; [ bugsnag fa-purity ];
|
|
6
|
+
build_deps = with deps.python_pkgs; [ flit-core ];
|
|
7
|
+
test_deps = with deps.python_pkgs; [
|
|
8
|
+
arch-lint
|
|
9
|
+
mypy
|
|
10
|
+
pytest
|
|
11
|
+
pytest-cov
|
|
12
|
+
ruff
|
|
13
|
+
];
|
|
14
|
+
};
|
|
15
|
+
in {
|
|
16
|
+
inherit src requirements;
|
|
17
|
+
root_path = "observes/common/utils-logger";
|
|
18
|
+
module_name = "fluidattacks_utils_logger";
|
|
19
|
+
pypi_token_var = "UTILS_LOGGER_TOKEN";
|
|
20
|
+
defaultDeps = deps.python_pkgs;
|
|
21
|
+
override = b: b;
|
|
22
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{ nixpkgs, pynix, python_pkgs }:
|
|
2
|
+
let
|
|
3
|
+
commit = "43aa33ef4cfa12c37148f4653dd89233c585c368"; # v4.0.4
|
|
4
|
+
sha256 = "06r2xfj50rn9m87i3vwa9bilhnrz3njhmfd992vzp4a5x937rfq2";
|
|
5
|
+
bundle = let
|
|
6
|
+
src = builtins.fetchTarball {
|
|
7
|
+
inherit sha256;
|
|
8
|
+
url =
|
|
9
|
+
"https://gitlab.com/dmurciaatfluid/arch_lint/-/archive/${commit}/arch_lint-${commit}.tar";
|
|
10
|
+
};
|
|
11
|
+
in import "${src}/build" {
|
|
12
|
+
inherit src;
|
|
13
|
+
inherit nixpkgs pynix;
|
|
14
|
+
};
|
|
15
|
+
extended_python_pkgs = python_pkgs // { inherit (bundle.deps) grimp; };
|
|
16
|
+
in bundle.builders.pkgBuilder
|
|
17
|
+
(bundle.builders.requirements extended_python_pkgs)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{ nixpkgs, pynix, }:
|
|
2
|
+
let
|
|
3
|
+
python_overlay = final: prev: {
|
|
4
|
+
arch-lint = import ./arch_lint.nix {
|
|
5
|
+
inherit nixpkgs pynix;
|
|
6
|
+
python_pkgs = prev;
|
|
7
|
+
};
|
|
8
|
+
fa-purity = import ./fa_purity.nix {
|
|
9
|
+
inherit nixpkgs pynix;
|
|
10
|
+
python_pkgs = final;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
python = pynix.lib.python.override {
|
|
14
|
+
packageOverrides = python_overlay;
|
|
15
|
+
self = python;
|
|
16
|
+
};
|
|
17
|
+
python_pkgs = python.pkgs;
|
|
18
|
+
in { inherit python_pkgs; }
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{ nixpkgs, pynix, python_pkgs }:
|
|
2
|
+
let
|
|
3
|
+
commit = "e669114103b334e532aec34dc5b2ec06dfd24247"; # v2.5.0+1
|
|
4
|
+
sha256 = "1x0ipsklpsxyrzy8j6agkqppj4n2x67kaz7zsi3mkycan9z9z3f8";
|
|
5
|
+
bundle = let
|
|
6
|
+
src = builtins.fetchTarball {
|
|
7
|
+
inherit sha256;
|
|
8
|
+
url =
|
|
9
|
+
"https://gitlab.com/dmurciaatfluid/purity/-/archive/${commit}/purity-${commit}.tar";
|
|
10
|
+
};
|
|
11
|
+
in import "${src}/build" {
|
|
12
|
+
inherit src;
|
|
13
|
+
inherit nixpkgs pynix;
|
|
14
|
+
};
|
|
15
|
+
extended_python_pkgs = python_pkgs // {
|
|
16
|
+
inherit (bundle.deps) types-simplejson;
|
|
17
|
+
};
|
|
18
|
+
in bundle.builders.pkgBuilder
|
|
19
|
+
(bundle.builders.requirements extended_python_pkgs)
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
{
|
|
2
|
+
"nodes": {
|
|
3
|
+
"flake-parts": {
|
|
4
|
+
"inputs": {
|
|
5
|
+
"nixpkgs-lib": "nixpkgs-lib"
|
|
6
|
+
},
|
|
7
|
+
"locked": {
|
|
8
|
+
"lastModified": 1754487366,
|
|
9
|
+
"narHash": "sha256-pHYj8gUBapuUzKV/kN/tR3Zvqc7o6gdFB9XKXIp1SQ8=",
|
|
10
|
+
"owner": "hercules-ci",
|
|
11
|
+
"repo": "flake-parts",
|
|
12
|
+
"rev": "af66ad14b28a127c5c0f3bbb298218fc63528a18",
|
|
13
|
+
"type": "github"
|
|
14
|
+
},
|
|
15
|
+
"original": {
|
|
16
|
+
"owner": "hercules-ci",
|
|
17
|
+
"repo": "flake-parts",
|
|
18
|
+
"type": "github"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"nix_filter": {
|
|
22
|
+
"locked": {
|
|
23
|
+
"lastModified": 1731533336,
|
|
24
|
+
"narHash": "sha256-oRam5PS1vcrr5UPgALW0eo1m/5/pls27Z/pabHNy2Ms=",
|
|
25
|
+
"owner": "numtide",
|
|
26
|
+
"repo": "nix-filter",
|
|
27
|
+
"rev": "f7653272fd234696ae94229839a99b73c9ab7de0",
|
|
28
|
+
"type": "github"
|
|
29
|
+
},
|
|
30
|
+
"original": {
|
|
31
|
+
"owner": "numtide",
|
|
32
|
+
"repo": "nix-filter",
|
|
33
|
+
"type": "github"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"nix_filter_2": {
|
|
37
|
+
"locked": {
|
|
38
|
+
"lastModified": 1731533336,
|
|
39
|
+
"narHash": "sha256-oRam5PS1vcrr5UPgALW0eo1m/5/pls27Z/pabHNy2Ms=",
|
|
40
|
+
"owner": "numtide",
|
|
41
|
+
"repo": "nix-filter",
|
|
42
|
+
"rev": "f7653272fd234696ae94229839a99b73c9ab7de0",
|
|
43
|
+
"type": "github"
|
|
44
|
+
},
|
|
45
|
+
"original": {
|
|
46
|
+
"owner": "numtide",
|
|
47
|
+
"repo": "nix-filter",
|
|
48
|
+
"type": "github"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"nixpkgs": {
|
|
52
|
+
"locked": {
|
|
53
|
+
"lastModified": 1736441877,
|
|
54
|
+
"narHash": "sha256-m3+PhBFkDwqo9lBplG4AyMW8P4/KcioJRS1UG8N7okM=",
|
|
55
|
+
"owner": "nixos",
|
|
56
|
+
"repo": "nixpkgs",
|
|
57
|
+
"rev": "ce3899414dab3297cf025bfa356dc2da426feefd",
|
|
58
|
+
"type": "github"
|
|
59
|
+
},
|
|
60
|
+
"original": {
|
|
61
|
+
"owner": "nixos",
|
|
62
|
+
"repo": "nixpkgs",
|
|
63
|
+
"type": "github"
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"nixpkgs-lib": {
|
|
67
|
+
"locked": {
|
|
68
|
+
"lastModified": 1753579242,
|
|
69
|
+
"narHash": "sha256-zvaMGVn14/Zz8hnp4VWT9xVnhc8vuL3TStRqwk22biA=",
|
|
70
|
+
"owner": "nix-community",
|
|
71
|
+
"repo": "nixpkgs.lib",
|
|
72
|
+
"rev": "0f36c44e01a6129be94e3ade315a5883f0228a6e",
|
|
73
|
+
"type": "github"
|
|
74
|
+
},
|
|
75
|
+
"original": {
|
|
76
|
+
"owner": "nix-community",
|
|
77
|
+
"repo": "nixpkgs.lib",
|
|
78
|
+
"type": "github"
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"nixpkgs_flake": {
|
|
82
|
+
"locked": {
|
|
83
|
+
"lastModified": 1756313514,
|
|
84
|
+
"narHash": "sha256-3Xbak0pXR8ziNv1ghHyJ5a5Ti2kt/LWq6hKZVJTvjBs=",
|
|
85
|
+
"owner": "nixos",
|
|
86
|
+
"repo": "nixpkgs",
|
|
87
|
+
"rev": "181464235b2daff8725773fef43ffc9d6b02e1c2",
|
|
88
|
+
"type": "github"
|
|
89
|
+
},
|
|
90
|
+
"original": {
|
|
91
|
+
"owner": "nixos",
|
|
92
|
+
"repo": "nixpkgs",
|
|
93
|
+
"type": "github"
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
"observes_flake_builder": {
|
|
97
|
+
"inputs": {
|
|
98
|
+
"nix_filter": "nix_filter",
|
|
99
|
+
"nixpkgs_flake": "nixpkgs_flake",
|
|
100
|
+
"pynix_flake": "pynix_flake",
|
|
101
|
+
"shell-helpers": "shell-helpers"
|
|
102
|
+
},
|
|
103
|
+
"locked": {
|
|
104
|
+
"dir": "observes/common/std_flake",
|
|
105
|
+
"lastModified": 1761069772,
|
|
106
|
+
"narHash": "sha256-7usoyA5DPHs1H0yI6goVDInqy1lUChLHHKt2u1t6GFk=",
|
|
107
|
+
"owner": "fluidattacks",
|
|
108
|
+
"repo": "universe",
|
|
109
|
+
"rev": "eff07528e7f89f6ea1a626c74dfeb14d86244dfe",
|
|
110
|
+
"type": "github"
|
|
111
|
+
},
|
|
112
|
+
"original": {
|
|
113
|
+
"dir": "observes/common/std_flake",
|
|
114
|
+
"owner": "fluidattacks",
|
|
115
|
+
"repo": "universe",
|
|
116
|
+
"rev": "eff07528e7f89f6ea1a626c74dfeb14d86244dfe",
|
|
117
|
+
"type": "github"
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
"pynix_flake": {
|
|
121
|
+
"inputs": {
|
|
122
|
+
"nix_filter": "nix_filter_2",
|
|
123
|
+
"nixpkgs": "nixpkgs"
|
|
124
|
+
},
|
|
125
|
+
"locked": {
|
|
126
|
+
"lastModified": 1758642502,
|
|
127
|
+
"narHash": "sha256-PD/bQMz2dqZSkydHyvRh+jS/0qoV8SdcIVs6sassteQ=",
|
|
128
|
+
"owner": "dmurciaatfluid",
|
|
129
|
+
"repo": "python_nix_builder",
|
|
130
|
+
"rev": "809aafe2e1995e72c15378d099bf251b78f04a20",
|
|
131
|
+
"type": "gitlab"
|
|
132
|
+
},
|
|
133
|
+
"original": {
|
|
134
|
+
"owner": "dmurciaatfluid",
|
|
135
|
+
"repo": "python_nix_builder",
|
|
136
|
+
"type": "gitlab"
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
"root": {
|
|
140
|
+
"inputs": {
|
|
141
|
+
"observes_flake_builder": "observes_flake_builder"
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
"shell-helpers": {
|
|
145
|
+
"inputs": {
|
|
146
|
+
"flake-parts": "flake-parts",
|
|
147
|
+
"nixpkgs": [
|
|
148
|
+
"observes_flake_builder",
|
|
149
|
+
"nixpkgs_flake"
|
|
150
|
+
]
|
|
151
|
+
},
|
|
152
|
+
"locked": {
|
|
153
|
+
"dir": "common/utils/shell-helpers",
|
|
154
|
+
"lastModified": 1752896460,
|
|
155
|
+
"narHash": "sha256-AsyTatXMx839cGsF6knwTrDZHk3Eue2QD3eSP7bkmpg=",
|
|
156
|
+
"owner": "fluidattacks",
|
|
157
|
+
"repo": "universe",
|
|
158
|
+
"rev": "27749d2c3a2b018eb010a322e5e1352f993c9e86",
|
|
159
|
+
"type": "github"
|
|
160
|
+
},
|
|
161
|
+
"original": {
|
|
162
|
+
"dir": "common/utils/shell-helpers",
|
|
163
|
+
"owner": "fluidattacks",
|
|
164
|
+
"repo": "universe",
|
|
165
|
+
"rev": "27749d2c3a2b018eb010a322e5e1352f993c9e86",
|
|
166
|
+
"type": "github"
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
"root": "root",
|
|
171
|
+
"version": 7
|
|
172
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
description = "Log utils for observes packages";
|
|
3
|
+
|
|
4
|
+
inputs = {
|
|
5
|
+
observes_flake_builder = {
|
|
6
|
+
url =
|
|
7
|
+
"github:fluidattacks/universe/eff07528e7f89f6ea1a626c74dfeb14d86244dfe?shallow=1&dir=observes/common/std_flake";
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
outputs = { self, ... }@inputs:
|
|
12
|
+
let
|
|
13
|
+
build_args = { system, python_version, nixpkgs, pynix }:
|
|
14
|
+
import ./build {
|
|
15
|
+
inherit nixpkgs pynix;
|
|
16
|
+
src = import ./build/filter.nix nixpkgs.nix-filter self;
|
|
17
|
+
};
|
|
18
|
+
in { packages = inputs.observes_flake_builder.outputs.build build_args; };
|
|
19
|
+
}
|
|
@@ -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,30 @@
|
|
|
1
|
+
[mypy]
|
|
2
|
+
disallow_any_decorated = True
|
|
3
|
+
disallow_any_expr = True
|
|
4
|
+
disallow_any_explicit = True
|
|
5
|
+
disallow_any_generics = True
|
|
6
|
+
disallow_any_unimported = True
|
|
7
|
+
disallow_incomplete_defs = True
|
|
8
|
+
disallow_subclassing_any = True
|
|
9
|
+
disallow_untyped_calls = True
|
|
10
|
+
disallow_untyped_decorators = True
|
|
11
|
+
disallow_untyped_defs = True
|
|
12
|
+
|
|
13
|
+
check_untyped_defs = True
|
|
14
|
+
no_implicit_optional = True
|
|
15
|
+
strict = True
|
|
16
|
+
strict_equality = True
|
|
17
|
+
strict_optional = True
|
|
18
|
+
|
|
19
|
+
warn_redundant_casts = True
|
|
20
|
+
warn_unused_ignores = True
|
|
21
|
+
warn_no_return = True
|
|
22
|
+
warn_return_any = True
|
|
23
|
+
warn_unreachable = True
|
|
24
|
+
|
|
25
|
+
ignore_errors = False
|
|
26
|
+
ignore_missing_imports = False
|
|
27
|
+
allow_untyped_globals = False
|
|
28
|
+
allow_redefinition = False
|
|
29
|
+
local_partial_types = False
|
|
30
|
+
implicit_reexport = False
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "fluidattacks_utils_logger"
|
|
3
|
+
authors = [{ name = "Product Team", email = "development@fluidattacks.com" }]
|
|
4
|
+
classifiers = ["License :: OSI Approved :: MIT License"]
|
|
5
|
+
requires-python = ">=3.11"
|
|
6
|
+
dependencies = [
|
|
7
|
+
"bugsnag >=4.7.0, <5.0.0",
|
|
8
|
+
"fa-purity >=2.1.0, <3.0.0",
|
|
9
|
+
]
|
|
10
|
+
description = "Common logger handlers"
|
|
11
|
+
dynamic = ["version"]
|
|
12
|
+
|
|
13
|
+
[build-system]
|
|
14
|
+
requires = ["flit_core >=3.2,<4"]
|
|
15
|
+
build-backend = "flit_core.buildapi"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
cache-dir = ".ruff_cache"
|
|
2
|
+
line-length = 100
|
|
3
|
+
indent-width = 4
|
|
4
|
+
target-version = "py311"
|
|
5
|
+
|
|
6
|
+
[lint]
|
|
7
|
+
select = ["ALL"]
|
|
8
|
+
ignore = [
|
|
9
|
+
"FBT001", # debatable
|
|
10
|
+
"FBT003", # conflict with the convention of denying kwargs
|
|
11
|
+
"RET503", # raises false positives
|
|
12
|
+
"N818", # semantics on names, the type already has the semantics
|
|
13
|
+
"TC001", # import cycles can be hidden
|
|
14
|
+
"TC002", # import cycles can be hidden
|
|
15
|
+
"TC003", # technical debt!
|
|
16
|
+
"FLY002", # f-string is not type safe: implicit str conversion can hide codification issues
|
|
17
|
+
"D203", # conflict with D211 one must be ignored
|
|
18
|
+
"D212", # conflict with D213 one must be ignored
|
|
19
|
+
"D104", # missing docs; technical debt!
|
|
20
|
+
"D103", # missing docs; technical debt!
|
|
21
|
+
"D102", # missing docs; technical debt!
|
|
22
|
+
"D101", # missing docs; technical debt!
|
|
23
|
+
"D100", # missing docs; technical debt!
|
|
24
|
+
]
|
|
25
|
+
fixable = ["ALL"]
|
|
26
|
+
unfixable = []
|
|
27
|
+
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
|
|
28
|
+
|
|
29
|
+
[lint.per-file-ignores]
|
|
30
|
+
"tests/**/*" = ["S101", "D100", "D103", "D104"]
|
|
31
|
+
"tests_fx/**/*" = ["S101", "D100", "D103", "D104"]
|
|
32
|
+
|
|
33
|
+
[format]
|
|
34
|
+
quote-style = "double"
|
|
35
|
+
indent-style = "space"
|
|
36
|
+
skip-magic-trailing-comma = false
|
|
37
|
+
line-ending = "lf"
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from typing import (
|
|
2
|
+
TypeVar,
|
|
3
|
+
)
|
|
4
|
+
|
|
5
|
+
from arch_lint.dag import (
|
|
6
|
+
DagMap,
|
|
7
|
+
)
|
|
8
|
+
from arch_lint.graph import (
|
|
9
|
+
FullPathModule,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
_T = TypeVar("_T")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def raise_or_return(item: _T | Exception) -> _T:
|
|
16
|
+
if isinstance(item, Exception):
|
|
17
|
+
raise item
|
|
18
|
+
return item
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _module(path: str) -> FullPathModule:
|
|
22
|
+
return raise_or_return(FullPathModule.from_raw(path))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
_dag: dict[str, tuple[tuple[str, ...] | str, ...]] = {
|
|
26
|
+
"fluidattacks_utils_logger": (
|
|
27
|
+
("logger", "handlers"),
|
|
28
|
+
("levels", "env"),
|
|
29
|
+
),
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def project_dag() -> DagMap:
|
|
34
|
+
return raise_or_return(DagMap.new(_dag))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def forbidden_allowlist() -> dict[FullPathModule, frozenset[FullPathModule]]:
|
|
38
|
+
_raw: dict[str, frozenset[str]] = {}
|
|
39
|
+
return {_module(k): frozenset(_module(i) for i in v) for k, v in _raw.items()}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from arch_lint.dag.check import (
|
|
2
|
+
dag_map_completeness,
|
|
3
|
+
)
|
|
4
|
+
from arch_lint.forbidden import (
|
|
5
|
+
check_forbidden,
|
|
6
|
+
)
|
|
7
|
+
from arch_lint.graph import (
|
|
8
|
+
ImportGraph,
|
|
9
|
+
)
|
|
10
|
+
from arch_lint.private import (
|
|
11
|
+
check_private,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
from .arch import (
|
|
15
|
+
forbidden_allowlist,
|
|
16
|
+
project_dag,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
root = "fluidattacks_utils_logger"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_dag_creation() -> None:
|
|
23
|
+
project_dag()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_dag_completeness() -> None:
|
|
27
|
+
graph = ImportGraph.build_graph(root, True)
|
|
28
|
+
dag_map_completeness(project_dag(), graph, next(iter(graph.roots)))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_forbidden_creation() -> None:
|
|
32
|
+
forbidden_allowlist()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_forbidden() -> None:
|
|
36
|
+
graph = ImportGraph.build_graph(root, True)
|
|
37
|
+
allowlist_map = forbidden_allowlist()
|
|
38
|
+
check_forbidden(allowlist_map, graph)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_private() -> None:
|
|
42
|
+
graph = ImportGraph.build_graph(root, False)
|
|
43
|
+
check_private(graph, next(iter(graph.roots)))
|
|
File without changes
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[[package]]
|
|
2
|
+
name = "python3"
|
|
3
|
+
version = "3.11.13"
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "bugsnag"
|
|
7
|
+
version = "4.8.0"
|
|
8
|
+
|
|
9
|
+
[[package]]
|
|
10
|
+
name = "deprecated"
|
|
11
|
+
version = "1.2.18"
|
|
12
|
+
|
|
13
|
+
[[package]]
|
|
14
|
+
name = "fa_purity"
|
|
15
|
+
version = "2.5.0"
|
|
16
|
+
|
|
17
|
+
[[package]]
|
|
18
|
+
name = "more-itertools"
|
|
19
|
+
version = "10.7.0"
|
|
20
|
+
|
|
21
|
+
[[package]]
|
|
22
|
+
name = "simplejson"
|
|
23
|
+
version = "3.20.1"
|
|
24
|
+
|
|
25
|
+
[[package]]
|
|
26
|
+
name = "six"
|
|
27
|
+
version = "1.17.0"
|
|
28
|
+
|
|
29
|
+
[[package]]
|
|
30
|
+
name = "types-deprecated"
|
|
31
|
+
version = "1.2.15.20250304"
|
|
32
|
+
|
|
33
|
+
[[package]]
|
|
34
|
+
name = "types-simplejson"
|
|
35
|
+
version = "3.17.3"
|
|
36
|
+
|
|
37
|
+
[[package]]
|
|
38
|
+
name = "webob"
|
|
39
|
+
version = "1.8.9"
|
|
40
|
+
|
|
41
|
+
[[package]]
|
|
42
|
+
name = "wrapt"
|
|
43
|
+
version = "1.17.2"
|