VersaLog 1.2.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.
- VersaLog/__init__.py +8 -0
- VersaLog/logger.py +88 -0
- versalog-1.2.0.dist-info/LICENSE +19 -0
- versalog-1.2.0.dist-info/METADATA +43 -0
- versalog-1.2.0.dist-info/RECORD +7 -0
- versalog-1.2.0.dist-info/WHEEL +5 -0
- versalog-1.2.0.dist-info/top_level.txt +1 -0
VersaLog/__init__.py
ADDED
VersaLog/logger.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
import inspect
|
|
3
|
+
|
|
4
|
+
class VersaLog:
|
|
5
|
+
COLORS = {
|
|
6
|
+
"INFO": "\033[32m",
|
|
7
|
+
"ERROR": "\033[31m",
|
|
8
|
+
"WARNING": "\033[33m",
|
|
9
|
+
"DEBUG": "\033[36m",
|
|
10
|
+
"CRITICAL": "\033[35m",
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
SYMBOLS = {
|
|
14
|
+
"INFO": "[+]",
|
|
15
|
+
"ERROR": "[-]",
|
|
16
|
+
"WARNING": "[!]",
|
|
17
|
+
"DEBUG": "[D]",
|
|
18
|
+
"CRITICAL": "[C]",
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
RESET = "\033[0m"
|
|
22
|
+
|
|
23
|
+
def __init__(self, mode: str = "simple", show_file: bool = False):
|
|
24
|
+
"""
|
|
25
|
+
mode:
|
|
26
|
+
- "simple" : [+] msg
|
|
27
|
+
- "detailed" : [TIME][LEVEL] : msg
|
|
28
|
+
- "file" : [FILE:LINE][LEVEL] msg
|
|
29
|
+
show_file:
|
|
30
|
+
- True : Display filename and line number (for simple and detailed modes)
|
|
31
|
+
"""
|
|
32
|
+
self.mode = mode.lower()
|
|
33
|
+
self.show_file = show_file
|
|
34
|
+
|
|
35
|
+
valid_modes = ["simple", "detailed", "file"]
|
|
36
|
+
|
|
37
|
+
if self.mode not in valid_modes:
|
|
38
|
+
raise ValueError(f"Invalid mode '{mode}' specified. Valid modes are: {', '.join(valid_modes)}")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def GetTime(self) -> str:
|
|
42
|
+
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
43
|
+
|
|
44
|
+
def GetCaller(self) -> str:
|
|
45
|
+
frame = inspect.stack()[3]
|
|
46
|
+
filename = frame.filename.split("/")[-1]
|
|
47
|
+
lineno = frame.lineno
|
|
48
|
+
return f"{filename}:{lineno}"
|
|
49
|
+
|
|
50
|
+
def Log(self, msg: str, type: str) -> None:
|
|
51
|
+
colors = self.COLORS.get(type, "")
|
|
52
|
+
types = type.upper()
|
|
53
|
+
|
|
54
|
+
caller = self.GetCaller() if self.show_file or self.mode == "file" else ""
|
|
55
|
+
|
|
56
|
+
if self.mode == "simple":
|
|
57
|
+
symbol = self.SYMBOLS.get(type, "[?]")
|
|
58
|
+
if self.show_file:
|
|
59
|
+
formatted = f"[{caller}]{colors}{symbol}{self.RESET} {msg}"
|
|
60
|
+
else:
|
|
61
|
+
formatted = f"{colors}{symbol}{self.RESET} {msg}"
|
|
62
|
+
|
|
63
|
+
elif self.mode == "file":
|
|
64
|
+
formatted = f"[{caller}]{colors}[{types}]{self.RESET} {msg}"
|
|
65
|
+
|
|
66
|
+
else:
|
|
67
|
+
time = self.GetTime()
|
|
68
|
+
if self.show_file:
|
|
69
|
+
formatted = f"[{time}]{colors}[{types}]{self.RESET}[{caller}] : {msg}"
|
|
70
|
+
else:
|
|
71
|
+
formatted = f"[{time}]{colors}[{types}]{self.RESET} : {msg}"
|
|
72
|
+
|
|
73
|
+
print(formatted)
|
|
74
|
+
|
|
75
|
+
def info(self, msg: str) -> None:
|
|
76
|
+
self.Log(msg, "INFO")
|
|
77
|
+
|
|
78
|
+
def error(self, msg: str) -> None:
|
|
79
|
+
self.Log(msg, "ERROR")
|
|
80
|
+
|
|
81
|
+
def warning(self, msg: str) -> None:
|
|
82
|
+
self.Log(msg, "WARNING")
|
|
83
|
+
|
|
84
|
+
def debug(self, msg: str) -> None:
|
|
85
|
+
self.Log(msg, "DEBUG")
|
|
86
|
+
|
|
87
|
+
def critical(self, msg: str) -> None:
|
|
88
|
+
self.Log(msg, "CRITICAL")
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2025 Kayu0514
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: VersaLog
|
|
3
|
+
Version: 1.2.0
|
|
4
|
+
Summary: Versatile logging library.
|
|
5
|
+
Home-page:
|
|
6
|
+
Author:
|
|
7
|
+
License: MIT
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.8, <3.14
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
|
|
15
|
+
# VersaLog.py
|
|
16
|
+
|
|
17
|
+

|
|
18
|
+
|
|
19
|
+
## VersaLog.py とは
|
|
20
|
+
|
|
21
|
+
多機能で柔軟なログを出力出来るライブラリです。
|
|
22
|
+
|
|
23
|
+
[English](README-en.md)
|
|
24
|
+
|
|
25
|
+
## インストール方法
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
pip install git+https://github.com/kayu0514/VersaLog.py.git
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## アップデート方法
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
pip install --upgrade --force-reinstall git+https://github.com/kayu0514/VersaLog.py.git
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## サンプル
|
|
38
|
+
|
|
39
|
+
**シンプル** : [タップ](/tests/simple_test.py)
|
|
40
|
+
|
|
41
|
+
**ディーテイルド** : [タップ](/tests/detailed_test.py)
|
|
42
|
+
|
|
43
|
+
**ファイル** : [タップ](/tests/file_test.py)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
VersaLog/__init__.py,sha256=eDQ8aPeNUSmVxFHtm4kecpp1akzl2Zzf31HZ5SgNb4c,191
|
|
2
|
+
VersaLog/logger.py,sha256=ZujXK3AQJ3b-82qv6kpeQx1Po1wRuz7Yds9lkMwStkA,2642
|
|
3
|
+
versalog-1.2.0.dist-info/LICENSE,sha256=Y-8dKUja8RR3Z_5EHU_fz2yNYexoKC6AxfC9k5-PGaU,1071
|
|
4
|
+
versalog-1.2.0.dist-info/METADATA,sha256=rDoW68VvfudbNW5uLTfG08NcsYuqOi3lVymOS-qQBSI,978
|
|
5
|
+
versalog-1.2.0.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
|
|
6
|
+
versalog-1.2.0.dist-info/top_level.txt,sha256=G6lXjlGYVa3t5vpYG6sq-Lfff9GhH71YT-K8Er5s09E,9
|
|
7
|
+
versalog-1.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
VersaLog
|