arin-log 0.2.0__tar.gz → 0.2.2__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.
- {arin_log-0.2.0 → arin_log-0.2.2}/PKG-INFO +69 -6
- {arin_log-0.2.0 → arin_log-0.2.2}/README.md +68 -5
- {arin_log-0.2.0 → arin_log-0.2.2}/arin_log/__init__.py +13 -5
- {arin_log-0.2.0 → arin_log-0.2.2}/arin_log/console.py +6 -11
- arin_log-0.2.2/arin_log/log_cnfg.json +1 -0
- {arin_log-0.2.0 → arin_log-0.2.2}/arin_log/logger.py +76 -30
- {arin_log-0.2.0 → arin_log-0.2.2}/arin_log.egg-info/PKG-INFO +69 -6
- {arin_log-0.2.0 → arin_log-0.2.2}/pyproject.toml +1 -1
- arin_log-0.2.0/arin_log/log_cnfg.json +0 -63
- {arin_log-0.2.0 → arin_log-0.2.2}/LICENSE +0 -0
- {arin_log-0.2.0 → arin_log-0.2.2}/arin_log/demo_log.py +0 -0
- {arin_log-0.2.0 → arin_log-0.2.2}/arin_log/folder.py +0 -0
- {arin_log-0.2.0 → arin_log-0.2.2}/arin_log/utils.py +0 -0
- {arin_log-0.2.0 → arin_log-0.2.2}/arin_log.egg-info/SOURCES.txt +0 -0
- {arin_log-0.2.0 → arin_log-0.2.2}/arin_log.egg-info/dependency_links.txt +0 -0
- {arin_log-0.2.0 → arin_log-0.2.2}/arin_log.egg-info/top_level.txt +0 -0
- {arin_log-0.2.0 → arin_log-0.2.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: arin-log
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: A lightweight logging package for long-running pipelines: a virtual assistant for the user, a clean archive for the developer.
|
|
5
5
|
Author-email: Marcus Aurelius <marcus.aurelius.hu@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -115,6 +115,66 @@ my_pipeline ; 14:32:11 ; completed
|
|
|
115
115
|
|
|
116
116
|
---
|
|
117
117
|
|
|
118
|
+
## Public API
|
|
119
|
+
|
|
120
|
+
All functions and helpers below are available directly from the
|
|
121
|
+
package:
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from arin_log import (
|
|
125
|
+
# Logger
|
|
126
|
+
log_start, log_notes, log_except, log_exit,
|
|
127
|
+
config_logs, file_exist,
|
|
128
|
+
# Helpers
|
|
129
|
+
tijd, tas, cls,
|
|
130
|
+
load_json, save_json,
|
|
131
|
+
# Folder
|
|
132
|
+
change_folder, get_folder,
|
|
133
|
+
# Console
|
|
134
|
+
cons_menu,
|
|
135
|
+
)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
| Name | Purpose |
|
|
139
|
+
|------|---------|
|
|
140
|
+
| `log_start` | Mark the start of a run and refresh the daily log date |
|
|
141
|
+
| `log_notes` | Write notes to the console and/or the log file |
|
|
142
|
+
| `log_except` | Log an exception with `module.function.line` info |
|
|
143
|
+
| `log_exit` | Mark the end of a run (and optionally exit the process) |
|
|
144
|
+
| `config_logs` | Load the colors from `config_log.json` |
|
|
145
|
+
| `file_exist` | Check if a file exists, with an optional wait time |
|
|
146
|
+
| `tijd` | Return the current time as `HH:MM:SS` |
|
|
147
|
+
| `tas` | Today as string (`YYYY-MM-DD`), set at import |
|
|
148
|
+
| `cls` | Clear the console (Windows: `cls`, otherwise `clear`) |
|
|
149
|
+
| `load_json` | Read a JSON file, return `{}` if missing or corrupt |
|
|
150
|
+
| `save_json` | Write data as JSON, return `True` or `False` |
|
|
151
|
+
| `change_folder` | Open the folder dialog and update the config |
|
|
152
|
+
| `get_folder` | Return the current log folder |
|
|
153
|
+
| `cons_menu` | Show a console menu and return the chosen command |
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## JSON helpers
|
|
158
|
+
|
|
159
|
+
`arin_log` ships with two JSON helpers, available directly from the
|
|
160
|
+
package:
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
from arin_log import load_json, save_json
|
|
164
|
+
|
|
165
|
+
data = load_json("myfile.json")
|
|
166
|
+
save_json("myfile.json", data, indent=4)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
`load_json` returns `{}` if the file is missing or corrupt.
|
|
170
|
+
`save_json` returns `True` on success, `False` on failure.
|
|
171
|
+
|
|
172
|
+
These helpers come with `arin_log` because most modules already
|
|
173
|
+
import the package — so they are available wherever you need them,
|
|
174
|
+
without an extra dependency.
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
118
178
|
## What makes `arin_log` different?
|
|
119
179
|
|
|
120
180
|
| Aspect | `arin_log` | Loguru / stdlib / structlog |
|
|
@@ -132,13 +192,16 @@ console and archive + Arin.
|
|
|
132
192
|
|
|
133
193
|
## How it works
|
|
134
194
|
|
|
135
|
-
The package consists of
|
|
195
|
+
The package consists of three modules, each with a clear task:
|
|
136
196
|
|
|
137
197
|
- **`logger.py`** — the heart: `log_start`, `log_notes`, `log_except`,
|
|
138
|
-
`log_exit`,
|
|
198
|
+
`log_exit`, plus the helpers `tijd`, `tas`, `cls`, `load_json`,
|
|
199
|
+
`save_json`, and `config_logs`.
|
|
139
200
|
- **`folder.py`** — manages the config folder and the log folder.
|
|
140
|
-
- **`console.py`** — console interaction:
|
|
141
|
-
|
|
201
|
+
- **`console.py`** — console interaction: menus.
|
|
202
|
+
|
|
203
|
+
**`utils.py`** remains as an internal helper for `folder.py` only.
|
|
204
|
+
It is not part of the public API.
|
|
142
205
|
|
|
143
206
|
### Configuration
|
|
144
207
|
|
|
@@ -182,4 +245,4 @@ MIT — see [LICENSE](LICENSE).
|
|
|
182
245
|
|
|
183
246
|
## Status
|
|
184
247
|
|
|
185
|
-
**Alpha (0.2.
|
|
248
|
+
**Alpha (0.2.2).** The core works. Tests are still in development.
|
|
@@ -90,6 +90,66 @@ my_pipeline ; 14:32:11 ; completed
|
|
|
90
90
|
|
|
91
91
|
---
|
|
92
92
|
|
|
93
|
+
## Public API
|
|
94
|
+
|
|
95
|
+
All functions and helpers below are available directly from the
|
|
96
|
+
package:
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from arin_log import (
|
|
100
|
+
# Logger
|
|
101
|
+
log_start, log_notes, log_except, log_exit,
|
|
102
|
+
config_logs, file_exist,
|
|
103
|
+
# Helpers
|
|
104
|
+
tijd, tas, cls,
|
|
105
|
+
load_json, save_json,
|
|
106
|
+
# Folder
|
|
107
|
+
change_folder, get_folder,
|
|
108
|
+
# Console
|
|
109
|
+
cons_menu,
|
|
110
|
+
)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
| Name | Purpose |
|
|
114
|
+
|------|---------|
|
|
115
|
+
| `log_start` | Mark the start of a run and refresh the daily log date |
|
|
116
|
+
| `log_notes` | Write notes to the console and/or the log file |
|
|
117
|
+
| `log_except` | Log an exception with `module.function.line` info |
|
|
118
|
+
| `log_exit` | Mark the end of a run (and optionally exit the process) |
|
|
119
|
+
| `config_logs` | Load the colors from `config_log.json` |
|
|
120
|
+
| `file_exist` | Check if a file exists, with an optional wait time |
|
|
121
|
+
| `tijd` | Return the current time as `HH:MM:SS` |
|
|
122
|
+
| `tas` | Today as string (`YYYY-MM-DD`), set at import |
|
|
123
|
+
| `cls` | Clear the console (Windows: `cls`, otherwise `clear`) |
|
|
124
|
+
| `load_json` | Read a JSON file, return `{}` if missing or corrupt |
|
|
125
|
+
| `save_json` | Write data as JSON, return `True` or `False` |
|
|
126
|
+
| `change_folder` | Open the folder dialog and update the config |
|
|
127
|
+
| `get_folder` | Return the current log folder |
|
|
128
|
+
| `cons_menu` | Show a console menu and return the chosen command |
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## JSON helpers
|
|
133
|
+
|
|
134
|
+
`arin_log` ships with two JSON helpers, available directly from the
|
|
135
|
+
package:
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
from arin_log import load_json, save_json
|
|
139
|
+
|
|
140
|
+
data = load_json("myfile.json")
|
|
141
|
+
save_json("myfile.json", data, indent=4)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
`load_json` returns `{}` if the file is missing or corrupt.
|
|
145
|
+
`save_json` returns `True` on success, `False` on failure.
|
|
146
|
+
|
|
147
|
+
These helpers come with `arin_log` because most modules already
|
|
148
|
+
import the package — so they are available wherever you need them,
|
|
149
|
+
without an extra dependency.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
93
153
|
## What makes `arin_log` different?
|
|
94
154
|
|
|
95
155
|
| Aspect | `arin_log` | Loguru / stdlib / structlog |
|
|
@@ -107,13 +167,16 @@ console and archive + Arin.
|
|
|
107
167
|
|
|
108
168
|
## How it works
|
|
109
169
|
|
|
110
|
-
The package consists of
|
|
170
|
+
The package consists of three modules, each with a clear task:
|
|
111
171
|
|
|
112
172
|
- **`logger.py`** — the heart: `log_start`, `log_notes`, `log_except`,
|
|
113
|
-
`log_exit`,
|
|
173
|
+
`log_exit`, plus the helpers `tijd`, `tas`, `cls`, `load_json`,
|
|
174
|
+
`save_json`, and `config_logs`.
|
|
114
175
|
- **`folder.py`** — manages the config folder and the log folder.
|
|
115
|
-
- **`console.py`** — console interaction:
|
|
116
|
-
|
|
176
|
+
- **`console.py`** — console interaction: menus.
|
|
177
|
+
|
|
178
|
+
**`utils.py`** remains as an internal helper for `folder.py` only.
|
|
179
|
+
It is not part of the public API.
|
|
117
180
|
|
|
118
181
|
### Configuration
|
|
119
182
|
|
|
@@ -157,4 +220,4 @@ MIT — see [LICENSE](LICENSE).
|
|
|
157
220
|
|
|
158
221
|
## Status
|
|
159
222
|
|
|
160
|
-
**Alpha (0.2.
|
|
223
|
+
**Alpha (0.2.2).** The core works. Tests are still in development.
|
|
@@ -18,7 +18,8 @@ Publieke API
|
|
|
18
18
|
------------
|
|
19
19
|
Vanuit de logger:
|
|
20
20
|
log_start, log_notes, log_except, log_exit,
|
|
21
|
-
config_logs, file_exist, tijd
|
|
21
|
+
config_logs, file_exist, tijd, tas,
|
|
22
|
+
load_json, save_json, cls
|
|
22
23
|
|
|
23
24
|
Vanuit de folder:
|
|
24
25
|
change_folder, get_folder
|
|
@@ -27,13 +28,12 @@ Vanuit de console:
|
|
|
27
28
|
cons_menu
|
|
28
29
|
|
|
29
30
|
Interne functies blijven bereikbaar via hun eigen module, bijvoorbeeld:
|
|
30
|
-
from arin_log.logger import not_set
|
|
31
|
+
from arin_log.logger import not_set, last_record
|
|
31
32
|
from arin_log.folder import get_config
|
|
32
|
-
from arin_log.
|
|
33
|
-
from arin_log.console import cls, menu_dict
|
|
33
|
+
from arin_log.console import menu_dict
|
|
34
34
|
"""
|
|
35
35
|
|
|
36
|
-
__version__ = "0.2.
|
|
36
|
+
__version__ = "0.2.2"
|
|
37
37
|
|
|
38
38
|
from arin_log.logger import (
|
|
39
39
|
log_start,
|
|
@@ -43,6 +43,10 @@ from arin_log.logger import (
|
|
|
43
43
|
config_logs,
|
|
44
44
|
file_exist,
|
|
45
45
|
tijd,
|
|
46
|
+
tas,
|
|
47
|
+
load_json,
|
|
48
|
+
save_json,
|
|
49
|
+
cls,
|
|
46
50
|
)
|
|
47
51
|
|
|
48
52
|
from arin_log.folder import (
|
|
@@ -62,6 +66,10 @@ __all__ = [
|
|
|
62
66
|
"config_logs",
|
|
63
67
|
"file_exist",
|
|
64
68
|
"tijd",
|
|
69
|
+
"tas",
|
|
70
|
+
"load_json",
|
|
71
|
+
"save_json",
|
|
72
|
+
"cls",
|
|
65
73
|
"change_folder",
|
|
66
74
|
"get_folder",
|
|
67
75
|
"cons_menu",
|
|
@@ -4,26 +4,20 @@ console.py
|
|
|
4
4
|
Console-interactie voor arin_log.
|
|
5
5
|
|
|
6
6
|
Bevat:
|
|
7
|
-
cls() - wist het scherm (Windows: cls, anders clear)
|
|
8
7
|
menu_dict(optlst) - bouwt een dict van genummerde menu-opties
|
|
9
8
|
cons_menu(optlst, ...) - toont een console-menu en retourneert
|
|
10
9
|
de gekozen functie als commando-string.
|
|
11
10
|
|
|
11
|
+
`cls()` woont in logger.py en is daar publiek.
|
|
12
|
+
|
|
12
13
|
Dit is een aparte module omdat console-interactie (menu, scherm wissen)
|
|
13
14
|
niets met loggen te maken heeft. De logger logt; de console toont.
|
|
14
15
|
"""
|
|
15
16
|
|
|
16
|
-
from os import
|
|
17
|
-
from arin_log.logger import log_notes
|
|
17
|
+
from os import path
|
|
18
|
+
from arin_log.logger import log_notes, cls
|
|
18
19
|
|
|
19
20
|
br = chr(10)
|
|
20
|
-
prgnm = path.basename(__file__).split('.')[0]
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def cls():
|
|
24
|
-
"""Wist het scherm. Op Windows met 'cls', anders met 'clear'."""
|
|
25
|
-
system('cls' if name == 'nt' else 'clear')
|
|
26
|
-
return
|
|
27
21
|
|
|
28
22
|
|
|
29
23
|
def menu_dict(optlst):
|
|
@@ -88,4 +82,5 @@ def cons_menu(optlst, logloc=None):
|
|
|
88
82
|
com = 'exit(0)'
|
|
89
83
|
else:
|
|
90
84
|
com = f'{com}()'
|
|
91
|
-
return com
|
|
85
|
+
return com
|
|
86
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"color_codes":{"black":"30m","blue":"34m","cyan":"36m","darkgrey":"90m","green":"32m","lightblue":"94m","lightcyan":"96m","lightgreen":"92m","lightgrey":"37m","lightred":"91m","orange":"33m","pink":"95m","purple":"35m","red":"31m","yellow":"93m"},"color_words":{"Arin":"cyan","completed":"cyan","modification":"cyan","pending":"cyan","terminated":"cyan","satisfied":"cyan","shutdown":"cyan","startup":"cyan","rebooted":"cyan","recovery":"cyan","running":"cyan","updated":"cyan","added":"green","succes":"green","success":"green","present":"green","restored":"green","saved":"green","corrupt":"lightred","error":"lightred","empty":"lightred","fail":"lightred","false":"lightred","inexistent":"lightred","invalid":"lightred","not exist":"lightred","not valid":"lightred","rude":"lightred","broken":"lightred","unrecoverable":"lightred","exception":"pink","changed":"orange","deleted":"orange","interrupted":"orange","interruption":"orange","fault":"orange","fault(s)":"orange","none":"orange","removed":"orange","timeout":"orange","unaltered":"orange","unfit":"orange"}}
|
|
@@ -5,21 +5,20 @@ Centrale logging-module van arin_log.
|
|
|
5
5
|
|
|
6
6
|
Ondersteunende modules:
|
|
7
7
|
folder.py - beheert de config en de log folder.
|
|
8
|
-
utils.py - algemene helpers (load_json, save_json).
|
|
9
8
|
console.py - console-interactie (menu, scherm wissen).
|
|
10
9
|
|
|
11
10
|
Publieke functies:
|
|
12
11
|
log_start, log_notes, log_except, log_exit, config_logs,
|
|
13
|
-
file_exist, tijd,
|
|
12
|
+
file_exist, tijd, cls, load_json, save_json, tas.
|
|
14
13
|
"""
|
|
15
14
|
|
|
16
|
-
from
|
|
17
|
-
from
|
|
15
|
+
from json import load as jload, dump as jdump
|
|
16
|
+
from os import makedirs, name, path, system
|
|
17
|
+
from sys import _getframe, stderr
|
|
18
|
+
from time import sleep, strftime
|
|
19
|
+
from arin_log import folder
|
|
18
20
|
from gc import collect
|
|
19
21
|
from re import sub
|
|
20
|
-
import time
|
|
21
|
-
|
|
22
|
-
from arin_log import folder
|
|
23
22
|
|
|
24
23
|
color_words = {}
|
|
25
24
|
color_codes = {}
|
|
@@ -37,7 +36,13 @@ def not_set():
|
|
|
37
36
|
|
|
38
37
|
|
|
39
38
|
def tijd():
|
|
40
|
-
return
|
|
39
|
+
return strftime("%H:%M:%S")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def cls():
|
|
43
|
+
"""Wist het scherm. Op Windows met 'cls', anders met 'clear'."""
|
|
44
|
+
system('cls' if name == 'nt' else 'clear')
|
|
45
|
+
return
|
|
41
46
|
|
|
42
47
|
|
|
43
48
|
def last_record(logloc):
|
|
@@ -104,7 +109,6 @@ def to_file(data, logloc=None):
|
|
|
104
109
|
lijn = '_' * (lng - 1) + br
|
|
105
110
|
txtFile.write(lijn)
|
|
106
111
|
recs_dic[logloc] = 'ne'
|
|
107
|
-
txtFile.close()
|
|
108
112
|
except Exception:
|
|
109
113
|
st = ' ; '.join(['logging', fnm, 'fail'])
|
|
110
114
|
log_except(frm, st, mod=prgnm, logloc=logloc)
|
|
@@ -121,7 +125,6 @@ def log_notes(notes, cons=None, logloc=None, end=False, ar_on=True):
|
|
|
121
125
|
end=True -> gebruik 'Arin' als prefix (voor afsluitende berichten).
|
|
122
126
|
end=False -> gebruik 'Arin :' als prefix (of geen prefix als ar_on=False).
|
|
123
127
|
"""
|
|
124
|
-
global br, prgnm
|
|
125
128
|
cons = True if cons is None else cons
|
|
126
129
|
st = False if logloc is None else True
|
|
127
130
|
if isinstance(notes, str):
|
|
@@ -153,7 +156,7 @@ def log_start(pnm, imp=None, cons=None, logloc=None):
|
|
|
153
156
|
imp = False if imp is None else imp
|
|
154
157
|
typ = 'pending' if imp else 'running'
|
|
155
158
|
cons = True if cons is None else cons
|
|
156
|
-
tas2 =
|
|
159
|
+
tas2 = strftime('%y-%m-%d')
|
|
157
160
|
lijn = ' ; '.join([pnm, tijd(), typ])
|
|
158
161
|
if last_record(logloc) != br:
|
|
159
162
|
lijn = [br, lijn]
|
|
@@ -164,7 +167,6 @@ def log_start(pnm, imp=None, cons=None, logloc=None):
|
|
|
164
167
|
|
|
165
168
|
|
|
166
169
|
def log_except(frm, note, mod=None, cons=None, logloc=None):
|
|
167
|
-
global br
|
|
168
170
|
logloc = 'error' if logloc is None else logloc
|
|
169
171
|
cons = True if cons is None else cons
|
|
170
172
|
if last_record(logloc) == br:
|
|
@@ -185,7 +187,6 @@ def log_except(frm, note, mod=None, cons=None, logloc=None):
|
|
|
185
187
|
|
|
186
188
|
|
|
187
189
|
def log_exit(prginf, imp=None, cons=None, logloc=None):
|
|
188
|
-
global br
|
|
189
190
|
imp = False if imp is None else imp
|
|
190
191
|
cons = True if cons is None else cons
|
|
191
192
|
notes = [prginf] if isinstance(prginf, str) else prginf
|
|
@@ -197,8 +198,8 @@ def log_exit(prginf, imp=None, cons=None, logloc=None):
|
|
|
197
198
|
notes[-1] = ' ; '.join([notes[-1], tijd(), 'terminated'])
|
|
198
199
|
notes.append(br)
|
|
199
200
|
log_notes(notes, logloc=logloc, cons=cons)
|
|
200
|
-
collect()
|
|
201
201
|
if imp:
|
|
202
|
+
collect()
|
|
202
203
|
return
|
|
203
204
|
else:
|
|
204
205
|
import sys
|
|
@@ -221,21 +222,24 @@ def config_logs():
|
|
|
221
222
|
|
|
222
223
|
|
|
223
224
|
def file_exist(pf, timeout=None):
|
|
224
|
-
|
|
225
|
+
"""
|
|
226
|
+
Controleert of een bestand bestaat, met een maximum wachttijd.
|
|
227
|
+
Retourneert True zodra het bestand bestaat.
|
|
228
|
+
Retourneert False als het bestand na 'timeout' seconden nog
|
|
229
|
+
niet bestaat, of als 'pf' None is.
|
|
230
|
+
"""
|
|
231
|
+
|
|
225
232
|
timeout = 0.24 if timeout is None else timeout
|
|
226
233
|
if pf is None:
|
|
227
234
|
return False
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
break
|
|
237
|
-
sleep(slt)
|
|
238
|
-
return st
|
|
235
|
+
slt = 0.08
|
|
236
|
+
tt = 0
|
|
237
|
+
while not path.isfile(pf):
|
|
238
|
+
sleep(slt)
|
|
239
|
+
tt += slt
|
|
240
|
+
if tt >= timeout:
|
|
241
|
+
return False
|
|
242
|
+
return True
|
|
239
243
|
|
|
240
244
|
|
|
241
245
|
def _ensure_log_folder():
|
|
@@ -246,14 +250,56 @@ def _ensure_log_folder():
|
|
|
246
250
|
makedirs(folder.log_folder, exist_ok=True)
|
|
247
251
|
except Exception:
|
|
248
252
|
stderr.write(f"log ; folder ; inexistent{br}administrator ; adjustments ; required")
|
|
249
|
-
exit(
|
|
253
|
+
exit(0)
|
|
250
254
|
return
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def load_json(pf, logloc=None):
|
|
258
|
+
"""Leest een JSON-bestand. Retourneert {} bij ontbreken of corruptie."""
|
|
259
|
+
logloc = prgnm if logloc is None else logloc
|
|
260
|
+
jsnd = {}
|
|
261
|
+
fnm = path.basename(pf)
|
|
262
|
+
if path.isfile(pf):
|
|
263
|
+
try:
|
|
264
|
+
with open(pf, encoding='utf-8') as fil:
|
|
265
|
+
jsnd = jload(fil)
|
|
266
|
+
except Exception:
|
|
267
|
+
fcnm = _getframe().f_code.co_name
|
|
268
|
+
tmp = f"data ; {fnm} ; corrupt"
|
|
269
|
+
log_notes(tmp)
|
|
270
|
+
log_notes(f"⚠️ {tmp}", cons=False, logloc=logloc)
|
|
271
|
+
log_notes(f"⚠️ {prgnm} ; {fcnm} ; {tijd()}", cons=False, logloc=logloc)
|
|
272
|
+
else:
|
|
273
|
+
fcnm = _getframe().f_code.co_name
|
|
274
|
+
tmp = f"file ; {fnm} ; inexistent"
|
|
275
|
+
log_notes(tmp)
|
|
276
|
+
log_notes(f"⚠️ {tmp}", cons=False, logloc=logloc)
|
|
277
|
+
log_notes(f"⚠️ {prgnm} ; {fcnm} ; {tijd()}", cons=False, logloc=logloc)
|
|
278
|
+
return jsnd
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def save_json(pf, data, indent=None, logloc=None):
|
|
282
|
+
"""Schrijft data als JSON. Retourneert True bij succes, anders False."""
|
|
283
|
+
logloc = prgnm if logloc is None else logloc
|
|
284
|
+
indent = indent if isinstance(indent, int) and indent >= 0 else None
|
|
285
|
+
fnm = path.basename(pf)
|
|
286
|
+
try:
|
|
287
|
+
with open(pf, 'w', encoding='utf-8') as fil:
|
|
288
|
+
jdump(data, fil, ensure_ascii=False, indent=indent)
|
|
289
|
+
return True
|
|
290
|
+
except Exception:
|
|
291
|
+
fcnm = _getframe().f_code.co_name
|
|
292
|
+
tmp = f"save ; {fnm} ; fail"
|
|
293
|
+
log_notes(tmp)
|
|
294
|
+
log_notes(f"⚠️ {tmp}", cons=False, logloc=logloc)
|
|
295
|
+
log_notes(f"⚠️ {prgnm} ; {fcnm} ; {tijd()}", cons=False, logloc=logloc)
|
|
296
|
+
return False
|
|
251
297
|
|
|
252
298
|
|
|
253
299
|
if not_set():
|
|
254
300
|
prgnm = path.basename(__file__).split('.')[0]
|
|
255
|
-
tas2 =
|
|
256
|
-
tas =
|
|
301
|
+
tas2 = strftime('%y-%m-%d')
|
|
302
|
+
tas = strftime('%Y-%m-%d')
|
|
257
303
|
_ensure_log_folder()
|
|
258
304
|
config_logs()
|
|
259
305
|
|
|
@@ -262,4 +308,4 @@ if __name__ == "__main__":
|
|
|
262
308
|
from arin_log.demo_log import demo
|
|
263
309
|
demo()
|
|
264
310
|
exit(0)
|
|
265
|
-
|
|
311
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: arin-log
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: A lightweight logging package for long-running pipelines: a virtual assistant for the user, a clean archive for the developer.
|
|
5
5
|
Author-email: Marcus Aurelius <marcus.aurelius.hu@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -115,6 +115,66 @@ my_pipeline ; 14:32:11 ; completed
|
|
|
115
115
|
|
|
116
116
|
---
|
|
117
117
|
|
|
118
|
+
## Public API
|
|
119
|
+
|
|
120
|
+
All functions and helpers below are available directly from the
|
|
121
|
+
package:
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from arin_log import (
|
|
125
|
+
# Logger
|
|
126
|
+
log_start, log_notes, log_except, log_exit,
|
|
127
|
+
config_logs, file_exist,
|
|
128
|
+
# Helpers
|
|
129
|
+
tijd, tas, cls,
|
|
130
|
+
load_json, save_json,
|
|
131
|
+
# Folder
|
|
132
|
+
change_folder, get_folder,
|
|
133
|
+
# Console
|
|
134
|
+
cons_menu,
|
|
135
|
+
)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
| Name | Purpose |
|
|
139
|
+
|------|---------|
|
|
140
|
+
| `log_start` | Mark the start of a run and refresh the daily log date |
|
|
141
|
+
| `log_notes` | Write notes to the console and/or the log file |
|
|
142
|
+
| `log_except` | Log an exception with `module.function.line` info |
|
|
143
|
+
| `log_exit` | Mark the end of a run (and optionally exit the process) |
|
|
144
|
+
| `config_logs` | Load the colors from `config_log.json` |
|
|
145
|
+
| `file_exist` | Check if a file exists, with an optional wait time |
|
|
146
|
+
| `tijd` | Return the current time as `HH:MM:SS` |
|
|
147
|
+
| `tas` | Today as string (`YYYY-MM-DD`), set at import |
|
|
148
|
+
| `cls` | Clear the console (Windows: `cls`, otherwise `clear`) |
|
|
149
|
+
| `load_json` | Read a JSON file, return `{}` if missing or corrupt |
|
|
150
|
+
| `save_json` | Write data as JSON, return `True` or `False` |
|
|
151
|
+
| `change_folder` | Open the folder dialog and update the config |
|
|
152
|
+
| `get_folder` | Return the current log folder |
|
|
153
|
+
| `cons_menu` | Show a console menu and return the chosen command |
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## JSON helpers
|
|
158
|
+
|
|
159
|
+
`arin_log` ships with two JSON helpers, available directly from the
|
|
160
|
+
package:
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
from arin_log import load_json, save_json
|
|
164
|
+
|
|
165
|
+
data = load_json("myfile.json")
|
|
166
|
+
save_json("myfile.json", data, indent=4)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
`load_json` returns `{}` if the file is missing or corrupt.
|
|
170
|
+
`save_json` returns `True` on success, `False` on failure.
|
|
171
|
+
|
|
172
|
+
These helpers come with `arin_log` because most modules already
|
|
173
|
+
import the package — so they are available wherever you need them,
|
|
174
|
+
without an extra dependency.
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
118
178
|
## What makes `arin_log` different?
|
|
119
179
|
|
|
120
180
|
| Aspect | `arin_log` | Loguru / stdlib / structlog |
|
|
@@ -132,13 +192,16 @@ console and archive + Arin.
|
|
|
132
192
|
|
|
133
193
|
## How it works
|
|
134
194
|
|
|
135
|
-
The package consists of
|
|
195
|
+
The package consists of three modules, each with a clear task:
|
|
136
196
|
|
|
137
197
|
- **`logger.py`** — the heart: `log_start`, `log_notes`, `log_except`,
|
|
138
|
-
`log_exit`,
|
|
198
|
+
`log_exit`, plus the helpers `tijd`, `tas`, `cls`, `load_json`,
|
|
199
|
+
`save_json`, and `config_logs`.
|
|
139
200
|
- **`folder.py`** — manages the config folder and the log folder.
|
|
140
|
-
- **`console.py`** — console interaction:
|
|
141
|
-
|
|
201
|
+
- **`console.py`** — console interaction: menus.
|
|
202
|
+
|
|
203
|
+
**`utils.py`** remains as an internal helper for `folder.py` only.
|
|
204
|
+
It is not part of the public API.
|
|
142
205
|
|
|
143
206
|
### Configuration
|
|
144
207
|
|
|
@@ -182,4 +245,4 @@ MIT — see [LICENSE](LICENSE).
|
|
|
182
245
|
|
|
183
246
|
## Status
|
|
184
247
|
|
|
185
|
-
**Alpha (0.2.
|
|
248
|
+
**Alpha (0.2.2).** The core works. Tests are still in development.
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "arin-log"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.2"
|
|
8
8
|
description = "A lightweight logging package for long-running pipelines: a virtual assistant for the user, a clean archive for the developer."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"color_codes": {
|
|
3
|
-
"black": "30m",
|
|
4
|
-
"blue": "34m",
|
|
5
|
-
"cyan": "36m",
|
|
6
|
-
"darkgrey": "90m",
|
|
7
|
-
"green": "32m",
|
|
8
|
-
"lightblue": "94m",
|
|
9
|
-
"lightcyan": "96m",
|
|
10
|
-
"lightgreen": "92m",
|
|
11
|
-
"lightgrey": "37m",
|
|
12
|
-
"lightred": "91m",
|
|
13
|
-
"orange": "33m",
|
|
14
|
-
"pink": "95m",
|
|
15
|
-
"purple": "35m",
|
|
16
|
-
"red": "31m",
|
|
17
|
-
"yellow": "93m"
|
|
18
|
-
},
|
|
19
|
-
"color_words": {
|
|
20
|
-
"Arin": "cyan",
|
|
21
|
-
"completed": "cyan",
|
|
22
|
-
"modification": "cyan",
|
|
23
|
-
"pending": "cyan",
|
|
24
|
-
"terminated": "cyan",
|
|
25
|
-
"satisfied": "cyan",
|
|
26
|
-
"shutdown": "cyan",
|
|
27
|
-
"startup": "cyan",
|
|
28
|
-
"rebooted": "cyan",
|
|
29
|
-
"recovery": "cyan",
|
|
30
|
-
"running": "cyan",
|
|
31
|
-
"updated": "cyan",
|
|
32
|
-
"added": "green",
|
|
33
|
-
"succes": "green",
|
|
34
|
-
"success": "green",
|
|
35
|
-
"present": "green",
|
|
36
|
-
"restored": "green",
|
|
37
|
-
"saved": "green",
|
|
38
|
-
"corrupt": "lightred",
|
|
39
|
-
"error": "lightred",
|
|
40
|
-
"empty": "lightred",
|
|
41
|
-
"fail": "lightred",
|
|
42
|
-
"false": "lightred",
|
|
43
|
-
"inexistent": "lightred",
|
|
44
|
-
"invalid": "lightred",
|
|
45
|
-
"not exist": "lightred",
|
|
46
|
-
"not valid": "lightred",
|
|
47
|
-
"rude": "lightred",
|
|
48
|
-
"broken": "lightred",
|
|
49
|
-
"unrecoverable": "lightred",
|
|
50
|
-
"exception": "pink",
|
|
51
|
-
"changed": "orange",
|
|
52
|
-
"deleted": "orange",
|
|
53
|
-
"interrupted": "orange",
|
|
54
|
-
"interruption": "orange",
|
|
55
|
-
"fault": "orange",
|
|
56
|
-
"fault(s)": "orange",
|
|
57
|
-
"none": "orange",
|
|
58
|
-
"removed": "orange",
|
|
59
|
-
"timeout": "orange",
|
|
60
|
-
"unaltered": "orange",
|
|
61
|
-
"unfit": "orange"
|
|
62
|
-
}
|
|
63
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|