loglit 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.
- loglit-1.0.0/LICENSE +21 -0
- loglit-1.0.0/PKG-INFO +156 -0
- loglit-1.0.0/README.md +132 -0
- loglit-1.0.0/loglit/__init__.py +1 -0
- loglit-1.0.0/loglit/loglit.py +126 -0
- loglit-1.0.0/loglit.egg-info/PKG-INFO +156 -0
- loglit-1.0.0/loglit.egg-info/SOURCES.txt +9 -0
- loglit-1.0.0/loglit.egg-info/dependency_links.txt +1 -0
- loglit-1.0.0/loglit.egg-info/top_level.txt +1 -0
- loglit-1.0.0/pyproject.toml +29 -0
- loglit-1.0.0/setup.cfg +4 -0
loglit-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 FMJ
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
loglit-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: loglit
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Lightweight logging for Python. One import, no boilerplate.
|
|
5
|
+
Author: FMJ
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Saecke/loglit
|
|
8
|
+
Project-URL: Issues, https://github.com/Saecke/loglit/issues
|
|
9
|
+
Keywords: logging,log,print,console,file
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: System :: Logging
|
|
20
|
+
Requires-Python: >=3.8
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# loglit
|
|
26
|
+
|
|
27
|
+
Lightweight logging for Python. One import, no boilerplate.
|
|
28
|
+
|
|
29
|
+
## The idea
|
|
30
|
+
|
|
31
|
+
You already know `print()`. Now use `log()` to write to a file, or `printlog()` to write to console **and** file. That's it.
|
|
32
|
+
|
|
33
|
+
**Without loglit** — the standard way:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
import logging
|
|
37
|
+
import os
|
|
38
|
+
from datetime import datetime
|
|
39
|
+
|
|
40
|
+
log_dir = "logs"
|
|
41
|
+
os.makedirs(log_dir, exist_ok=True)
|
|
42
|
+
|
|
43
|
+
logger = logging.getLogger("myapp")
|
|
44
|
+
logger.setLevel(logging.DEBUG)
|
|
45
|
+
|
|
46
|
+
formatter = logging.Formatter("%(asctime)s - %(message)s", datefmt="%d-%m-%Y %H:%M:%S")
|
|
47
|
+
|
|
48
|
+
console_handler = logging.StreamHandler()
|
|
49
|
+
console_handler.setLevel(logging.DEBUG)
|
|
50
|
+
console_handler.setFormatter(formatter)
|
|
51
|
+
|
|
52
|
+
file_handler = logging.FileHandler(
|
|
53
|
+
os.path.join(log_dir, f"log_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log"),
|
|
54
|
+
encoding="utf-8",
|
|
55
|
+
)
|
|
56
|
+
file_handler.setLevel(logging.DEBUG)
|
|
57
|
+
file_handler.setFormatter(formatter)
|
|
58
|
+
|
|
59
|
+
logger.addHandler(console_handler)
|
|
60
|
+
logger.addHandler(file_handler)
|
|
61
|
+
|
|
62
|
+
logger.info("Hello World")
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**With loglit:**
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from loglit import log, printlog
|
|
69
|
+
|
|
70
|
+
printlog("Hello World")
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Same result. Zero setup.
|
|
74
|
+
|
|
75
|
+
## Installation
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pip install loglit
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Usage
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from loglit import log, printlog
|
|
85
|
+
|
|
86
|
+
log("Only written to the log file.")
|
|
87
|
+
printlog("Written to console and log file.")
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
- `log()` → writes to log file only (silent)
|
|
91
|
+
- `printlog()` → writes to console **and** log file
|
|
92
|
+
|
|
93
|
+
Log files are created automatically with a timestamp per session.
|
|
94
|
+
|
|
95
|
+
## Configuration
|
|
96
|
+
|
|
97
|
+
Configuration is optional. Only call `configure()` if you want to change something:
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from loglit import configure, log
|
|
101
|
+
|
|
102
|
+
configure(log_dir="my_logs", file_prefix="myapp_", file_extension="txt")
|
|
103
|
+
|
|
104
|
+
log("Done.")
|
|
105
|
+
# → Log file: my_logs/myapp_22-03-2026_12-00-00.txt
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The filename is built from these parts:
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
{file_prefix}{file_timestamp}{file_suffix}.{file_extension}
|
|
112
|
+
myapp_ 22-03-2026_12-00-00 .txt
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
All options with their defaults:
|
|
116
|
+
|
|
117
|
+
| Option | Default | Description |
|
|
118
|
+
|--------------------|-----------------------------|-----------------------------------|
|
|
119
|
+
| `log_dir` | `loglit/logs/` | Directory for log files |
|
|
120
|
+
| `encoding` | `utf-8` | Log file encoding |
|
|
121
|
+
| `log_level` | `logging.DEBUG` | Minimum log level |
|
|
122
|
+
| `log_format` | `%(asctime)s - %(message)s` | Log line format |
|
|
123
|
+
| `date_format` | `%d-%m-%Y %H:%M:%S` | Timestamp format in log lines |
|
|
124
|
+
| `file_prefix` | `loglit_` | Filename prefix |
|
|
125
|
+
| `file_suffix` | `""` | Filename suffix (after timestamp) |
|
|
126
|
+
| `file_extension` | `log` | File extension |
|
|
127
|
+
| `file_timestamp` | `%d-%m-%Y_%H-%M-%S` | Timestamp format in filename |
|
|
128
|
+
|
|
129
|
+
## Log Levels
|
|
130
|
+
|
|
131
|
+
Standard Python log levels work out of the box:
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
import logging
|
|
135
|
+
from loglit import log, printlog
|
|
136
|
+
|
|
137
|
+
log("Debug info", level=logging.DEBUG) # file only
|
|
138
|
+
printlog("Something happened", level=logging.INFO) # file + console
|
|
139
|
+
printlog("Watch out", level=logging.WARNING) # file + console
|
|
140
|
+
printlog("Something broke", level=logging.ERROR) # file + console
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Examples
|
|
144
|
+
|
|
145
|
+
See the [examples/](examples/) folder for ready-to-run scripts:
|
|
146
|
+
|
|
147
|
+
- [basic.py](examples/basic.py) — minimal usage, no configuration
|
|
148
|
+
- [configured.py](examples/configured.py) — all options customized
|
|
149
|
+
|
|
150
|
+
## License
|
|
151
|
+
|
|
152
|
+
[MIT](LICENSE)
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
**Author:** FMJ
|
loglit-1.0.0/README.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# loglit
|
|
2
|
+
|
|
3
|
+
Lightweight logging for Python. One import, no boilerplate.
|
|
4
|
+
|
|
5
|
+
## The idea
|
|
6
|
+
|
|
7
|
+
You already know `print()`. Now use `log()` to write to a file, or `printlog()` to write to console **and** file. That's it.
|
|
8
|
+
|
|
9
|
+
**Without loglit** — the standard way:
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
import logging
|
|
13
|
+
import os
|
|
14
|
+
from datetime import datetime
|
|
15
|
+
|
|
16
|
+
log_dir = "logs"
|
|
17
|
+
os.makedirs(log_dir, exist_ok=True)
|
|
18
|
+
|
|
19
|
+
logger = logging.getLogger("myapp")
|
|
20
|
+
logger.setLevel(logging.DEBUG)
|
|
21
|
+
|
|
22
|
+
formatter = logging.Formatter("%(asctime)s - %(message)s", datefmt="%d-%m-%Y %H:%M:%S")
|
|
23
|
+
|
|
24
|
+
console_handler = logging.StreamHandler()
|
|
25
|
+
console_handler.setLevel(logging.DEBUG)
|
|
26
|
+
console_handler.setFormatter(formatter)
|
|
27
|
+
|
|
28
|
+
file_handler = logging.FileHandler(
|
|
29
|
+
os.path.join(log_dir, f"log_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log"),
|
|
30
|
+
encoding="utf-8",
|
|
31
|
+
)
|
|
32
|
+
file_handler.setLevel(logging.DEBUG)
|
|
33
|
+
file_handler.setFormatter(formatter)
|
|
34
|
+
|
|
35
|
+
logger.addHandler(console_handler)
|
|
36
|
+
logger.addHandler(file_handler)
|
|
37
|
+
|
|
38
|
+
logger.info("Hello World")
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**With loglit:**
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from loglit import log, printlog
|
|
45
|
+
|
|
46
|
+
printlog("Hello World")
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Same result. Zero setup.
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install loglit
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Usage
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from loglit import log, printlog
|
|
61
|
+
|
|
62
|
+
log("Only written to the log file.")
|
|
63
|
+
printlog("Written to console and log file.")
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
- `log()` → writes to log file only (silent)
|
|
67
|
+
- `printlog()` → writes to console **and** log file
|
|
68
|
+
|
|
69
|
+
Log files are created automatically with a timestamp per session.
|
|
70
|
+
|
|
71
|
+
## Configuration
|
|
72
|
+
|
|
73
|
+
Configuration is optional. Only call `configure()` if you want to change something:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from loglit import configure, log
|
|
77
|
+
|
|
78
|
+
configure(log_dir="my_logs", file_prefix="myapp_", file_extension="txt")
|
|
79
|
+
|
|
80
|
+
log("Done.")
|
|
81
|
+
# → Log file: my_logs/myapp_22-03-2026_12-00-00.txt
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The filename is built from these parts:
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
{file_prefix}{file_timestamp}{file_suffix}.{file_extension}
|
|
88
|
+
myapp_ 22-03-2026_12-00-00 .txt
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
All options with their defaults:
|
|
92
|
+
|
|
93
|
+
| Option | Default | Description |
|
|
94
|
+
|--------------------|-----------------------------|-----------------------------------|
|
|
95
|
+
| `log_dir` | `loglit/logs/` | Directory for log files |
|
|
96
|
+
| `encoding` | `utf-8` | Log file encoding |
|
|
97
|
+
| `log_level` | `logging.DEBUG` | Minimum log level |
|
|
98
|
+
| `log_format` | `%(asctime)s - %(message)s` | Log line format |
|
|
99
|
+
| `date_format` | `%d-%m-%Y %H:%M:%S` | Timestamp format in log lines |
|
|
100
|
+
| `file_prefix` | `loglit_` | Filename prefix |
|
|
101
|
+
| `file_suffix` | `""` | Filename suffix (after timestamp) |
|
|
102
|
+
| `file_extension` | `log` | File extension |
|
|
103
|
+
| `file_timestamp` | `%d-%m-%Y_%H-%M-%S` | Timestamp format in filename |
|
|
104
|
+
|
|
105
|
+
## Log Levels
|
|
106
|
+
|
|
107
|
+
Standard Python log levels work out of the box:
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
import logging
|
|
111
|
+
from loglit import log, printlog
|
|
112
|
+
|
|
113
|
+
log("Debug info", level=logging.DEBUG) # file only
|
|
114
|
+
printlog("Something happened", level=logging.INFO) # file + console
|
|
115
|
+
printlog("Watch out", level=logging.WARNING) # file + console
|
|
116
|
+
printlog("Something broke", level=logging.ERROR) # file + console
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Examples
|
|
120
|
+
|
|
121
|
+
See the [examples/](examples/) folder for ready-to-run scripts:
|
|
122
|
+
|
|
123
|
+
- [basic.py](examples/basic.py) — minimal usage, no configuration
|
|
124
|
+
- [configured.py](examples/configured.py) — all options customized
|
|
125
|
+
|
|
126
|
+
## License
|
|
127
|
+
|
|
128
|
+
[MIT](LICENSE)
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
**Author:** FMJ
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from loglit.loglit import configure, log, printlog
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""
|
|
2
|
+
loglit - Lightweight logging for Python. One import, no boilerplate.
|
|
3
|
+
|
|
4
|
+
Features:
|
|
5
|
+
- log() for file logging, printlog() for console + file logging
|
|
6
|
+
- configure() to customize without editing source code
|
|
7
|
+
- Automatic timestamped log files
|
|
8
|
+
- UTF-8 log files by default
|
|
9
|
+
|
|
10
|
+
Author: FMJ
|
|
11
|
+
License: MIT
|
|
12
|
+
"""
|
|
13
|
+
import os
|
|
14
|
+
import sys
|
|
15
|
+
import logging
|
|
16
|
+
from datetime import datetime
|
|
17
|
+
|
|
18
|
+
# --- Internal State ---
|
|
19
|
+
_config = {
|
|
20
|
+
"log_dir": os.path.join(os.path.dirname(os.path.abspath(__file__)), "logs"),
|
|
21
|
+
"logger_name": "loglit",
|
|
22
|
+
"log_level": logging.DEBUG,
|
|
23
|
+
"log_format": "%(asctime)s - %(message)s",
|
|
24
|
+
"date_format": "%d-%m-%Y %H:%M:%S",
|
|
25
|
+
"encoding": "utf-8",
|
|
26
|
+
"file_prefix": "loglit_",
|
|
27
|
+
"file_suffix": "",
|
|
28
|
+
"file_extension": "log",
|
|
29
|
+
"file_timestamp": "%d-%m-%Y_%H-%M-%S",
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
_file_logger = None
|
|
33
|
+
_print_logger = None
|
|
34
|
+
_initialized = False
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _generate_log_filename():
|
|
38
|
+
timestamp = datetime.now().strftime(_config["file_timestamp"])
|
|
39
|
+
name = f"{_config['file_prefix']}{timestamp}{_config['file_suffix']}"
|
|
40
|
+
return os.path.join(_config["log_dir"], f"{name}.{_config['file_extension']}")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _setup_logger():
|
|
44
|
+
global _file_logger, _print_logger, _initialized
|
|
45
|
+
|
|
46
|
+
os.makedirs(_config["log_dir"], exist_ok=True)
|
|
47
|
+
|
|
48
|
+
formatter = logging.Formatter(
|
|
49
|
+
_config["log_format"], datefmt=_config["date_format"]
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
file_handler = logging.FileHandler(
|
|
53
|
+
_generate_log_filename(), encoding=_config["encoding"]
|
|
54
|
+
)
|
|
55
|
+
file_handler.setLevel(_config["log_level"])
|
|
56
|
+
file_handler.setFormatter(formatter)
|
|
57
|
+
|
|
58
|
+
console_handler = logging.StreamHandler(stream=sys.stderr)
|
|
59
|
+
console_handler.setLevel(_config["log_level"])
|
|
60
|
+
console_handler.setFormatter(formatter)
|
|
61
|
+
|
|
62
|
+
# Close old handlers before replacing (prevents file handle leaks)
|
|
63
|
+
if _file_logger:
|
|
64
|
+
for h in _file_logger.handlers:
|
|
65
|
+
h.close()
|
|
66
|
+
_file_logger.handlers.clear()
|
|
67
|
+
if _print_logger:
|
|
68
|
+
for h in _print_logger.handlers:
|
|
69
|
+
h.close()
|
|
70
|
+
_print_logger.handlers.clear()
|
|
71
|
+
|
|
72
|
+
# log() → file only
|
|
73
|
+
_file_logger = logging.getLogger(_config["logger_name"] + ".file")
|
|
74
|
+
_file_logger.setLevel(_config["log_level"])
|
|
75
|
+
_file_logger.addHandler(file_handler)
|
|
76
|
+
_file_logger.propagate = False
|
|
77
|
+
|
|
78
|
+
# printlog() → file + console
|
|
79
|
+
_print_logger = logging.getLogger(_config["logger_name"] + ".print")
|
|
80
|
+
_print_logger.setLevel(_config["log_level"])
|
|
81
|
+
_print_logger.addHandler(file_handler)
|
|
82
|
+
_print_logger.addHandler(console_handler)
|
|
83
|
+
_print_logger.propagate = False
|
|
84
|
+
|
|
85
|
+
_initialized = True
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _ensure_initialized():
|
|
89
|
+
if not _initialized:
|
|
90
|
+
_setup_logger()
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# --- Public API ---
|
|
94
|
+
def configure(**kwargs):
|
|
95
|
+
"""Configure the logger. Call before the first log() or printlog().
|
|
96
|
+
|
|
97
|
+
Keyword arguments:
|
|
98
|
+
log_dir (str): Directory for log files. Default: loglit/logs/
|
|
99
|
+
encoding (str): Log file encoding. Default: utf-8
|
|
100
|
+
log_level (int): Minimum log level. Default: logging.DEBUG
|
|
101
|
+
log_format (str): Log line format. Default: %(asctime)s - %(message)s
|
|
102
|
+
date_format (str): Timestamp format. Default: %d-%m-%Y %H:%M:%S
|
|
103
|
+
file_prefix (str): Filename prefix. Default: loglit_
|
|
104
|
+
file_suffix (str): Filename suffix (after timestamp). Default: ""
|
|
105
|
+
file_extension (str): File extension. Default: log
|
|
106
|
+
file_timestamp (str): Timestamp format in filename. Default: %d-%m-%Y_%H-%M-%S
|
|
107
|
+
"""
|
|
108
|
+
for key, value in kwargs.items():
|
|
109
|
+
if key not in _config:
|
|
110
|
+
raise ValueError(f"Unknown config option: '{key}'")
|
|
111
|
+
_config[key] = value
|
|
112
|
+
|
|
113
|
+
# (Re)initialize logger with new config
|
|
114
|
+
_setup_logger()
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def log(message, level=logging.INFO):
|
|
118
|
+
"""Log a message to file only."""
|
|
119
|
+
_ensure_initialized()
|
|
120
|
+
_file_logger.log(level, message)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def printlog(message, level=logging.INFO):
|
|
124
|
+
"""Log a message to console and file."""
|
|
125
|
+
_ensure_initialized()
|
|
126
|
+
_print_logger.log(level, message)
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: loglit
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Lightweight logging for Python. One import, no boilerplate.
|
|
5
|
+
Author: FMJ
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Saecke/loglit
|
|
8
|
+
Project-URL: Issues, https://github.com/Saecke/loglit/issues
|
|
9
|
+
Keywords: logging,log,print,console,file
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: System :: Logging
|
|
20
|
+
Requires-Python: >=3.8
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# loglit
|
|
26
|
+
|
|
27
|
+
Lightweight logging for Python. One import, no boilerplate.
|
|
28
|
+
|
|
29
|
+
## The idea
|
|
30
|
+
|
|
31
|
+
You already know `print()`. Now use `log()` to write to a file, or `printlog()` to write to console **and** file. That's it.
|
|
32
|
+
|
|
33
|
+
**Without loglit** — the standard way:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
import logging
|
|
37
|
+
import os
|
|
38
|
+
from datetime import datetime
|
|
39
|
+
|
|
40
|
+
log_dir = "logs"
|
|
41
|
+
os.makedirs(log_dir, exist_ok=True)
|
|
42
|
+
|
|
43
|
+
logger = logging.getLogger("myapp")
|
|
44
|
+
logger.setLevel(logging.DEBUG)
|
|
45
|
+
|
|
46
|
+
formatter = logging.Formatter("%(asctime)s - %(message)s", datefmt="%d-%m-%Y %H:%M:%S")
|
|
47
|
+
|
|
48
|
+
console_handler = logging.StreamHandler()
|
|
49
|
+
console_handler.setLevel(logging.DEBUG)
|
|
50
|
+
console_handler.setFormatter(formatter)
|
|
51
|
+
|
|
52
|
+
file_handler = logging.FileHandler(
|
|
53
|
+
os.path.join(log_dir, f"log_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log"),
|
|
54
|
+
encoding="utf-8",
|
|
55
|
+
)
|
|
56
|
+
file_handler.setLevel(logging.DEBUG)
|
|
57
|
+
file_handler.setFormatter(formatter)
|
|
58
|
+
|
|
59
|
+
logger.addHandler(console_handler)
|
|
60
|
+
logger.addHandler(file_handler)
|
|
61
|
+
|
|
62
|
+
logger.info("Hello World")
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**With loglit:**
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from loglit import log, printlog
|
|
69
|
+
|
|
70
|
+
printlog("Hello World")
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Same result. Zero setup.
|
|
74
|
+
|
|
75
|
+
## Installation
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pip install loglit
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Usage
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from loglit import log, printlog
|
|
85
|
+
|
|
86
|
+
log("Only written to the log file.")
|
|
87
|
+
printlog("Written to console and log file.")
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
- `log()` → writes to log file only (silent)
|
|
91
|
+
- `printlog()` → writes to console **and** log file
|
|
92
|
+
|
|
93
|
+
Log files are created automatically with a timestamp per session.
|
|
94
|
+
|
|
95
|
+
## Configuration
|
|
96
|
+
|
|
97
|
+
Configuration is optional. Only call `configure()` if you want to change something:
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from loglit import configure, log
|
|
101
|
+
|
|
102
|
+
configure(log_dir="my_logs", file_prefix="myapp_", file_extension="txt")
|
|
103
|
+
|
|
104
|
+
log("Done.")
|
|
105
|
+
# → Log file: my_logs/myapp_22-03-2026_12-00-00.txt
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The filename is built from these parts:
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
{file_prefix}{file_timestamp}{file_suffix}.{file_extension}
|
|
112
|
+
myapp_ 22-03-2026_12-00-00 .txt
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
All options with their defaults:
|
|
116
|
+
|
|
117
|
+
| Option | Default | Description |
|
|
118
|
+
|--------------------|-----------------------------|-----------------------------------|
|
|
119
|
+
| `log_dir` | `loglit/logs/` | Directory for log files |
|
|
120
|
+
| `encoding` | `utf-8` | Log file encoding |
|
|
121
|
+
| `log_level` | `logging.DEBUG` | Minimum log level |
|
|
122
|
+
| `log_format` | `%(asctime)s - %(message)s` | Log line format |
|
|
123
|
+
| `date_format` | `%d-%m-%Y %H:%M:%S` | Timestamp format in log lines |
|
|
124
|
+
| `file_prefix` | `loglit_` | Filename prefix |
|
|
125
|
+
| `file_suffix` | `""` | Filename suffix (after timestamp) |
|
|
126
|
+
| `file_extension` | `log` | File extension |
|
|
127
|
+
| `file_timestamp` | `%d-%m-%Y_%H-%M-%S` | Timestamp format in filename |
|
|
128
|
+
|
|
129
|
+
## Log Levels
|
|
130
|
+
|
|
131
|
+
Standard Python log levels work out of the box:
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
import logging
|
|
135
|
+
from loglit import log, printlog
|
|
136
|
+
|
|
137
|
+
log("Debug info", level=logging.DEBUG) # file only
|
|
138
|
+
printlog("Something happened", level=logging.INFO) # file + console
|
|
139
|
+
printlog("Watch out", level=logging.WARNING) # file + console
|
|
140
|
+
printlog("Something broke", level=logging.ERROR) # file + console
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Examples
|
|
144
|
+
|
|
145
|
+
See the [examples/](examples/) folder for ready-to-run scripts:
|
|
146
|
+
|
|
147
|
+
- [basic.py](examples/basic.py) — minimal usage, no configuration
|
|
148
|
+
- [configured.py](examples/configured.py) — all options customized
|
|
149
|
+
|
|
150
|
+
## License
|
|
151
|
+
|
|
152
|
+
[MIT](LICENSE)
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
**Author:** FMJ
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
loglit
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "loglit"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Lightweight logging for Python. One import, no boilerplate."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.8"
|
|
12
|
+
authors = [{ name = "FMJ" }]
|
|
13
|
+
keywords = ["logging", "log", "print", "console", "file"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 5 - Production/Stable",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.8",
|
|
19
|
+
"Programming Language :: Python :: 3.9",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Topic :: System :: Logging",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Homepage = "https://github.com/Saecke/loglit"
|
|
29
|
+
Issues = "https://github.com/Saecke/loglit/issues"
|
loglit-1.0.0/setup.cfg
ADDED