tee-logger 6.19__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.
@@ -0,0 +1,151 @@
1
+ Metadata-Version: 2.2
2
+ Name: tee-logger
3
+ Version: 6.19
4
+ Summary: A simple wrapper for python logger that also selectively tee logs to stdout
5
+ Requires-Python: >=3.6
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: python-dateutil
8
+
9
+ # Tee_Logger
10
+
11
+ This Python module provides a simple, customizable logger that can direct output to both the console and a log file. It includes utilities for formatting file names, colorizing text output, and performing log maintenance tasks like archiving and deletion of old logs.
12
+
13
+ ## Table of Contents
14
+ - [Tee\_Logger](#tee_logger)
15
+ - [Table of Contents](#table-of-contents)
16
+ - [Installation](#installation)
17
+ - [Overview](#overview)
18
+ - [Key Components](#key-components)
19
+ - [bcolors](#bcolors)
20
+ - [abbreviate\_filename](#abbreviate_filename)
21
+ - [printWithColor](#printwithcolor)
22
+ - [teeLogger](#teelogger)
23
+ - [Usage Examples](#usage-examples)
24
+ - [Note: by default, the caller trace back level is 2, which usually will be the line calling for log.](#note-by-default-the-caller-trace-back-level-is-2-which-usually-will-be-the-line-calling-for-log)
25
+ - [Log Maintenance](#log-maintenance)
26
+
27
+ ---
28
+
29
+ ## Installation
30
+
31
+ Copy `Tee_Logger.py` into your project and ensure you have Python 3 installed. Dependencies:
32
+ - `dateutil` (optional)
33
+ - `base64`, `math`, `functools`, `subprocess`, `tarfile`, `shutil` (standard library modules)
34
+
35
+ ---
36
+
37
+ ## Overview
38
+
39
+ The code offers a logging class called `teeLogger` that can:
40
+
41
+ - Print log messages with or without colors.
42
+ - Write log entries to a file with date-based folder organization.
43
+ - Automatically compress and delete logs based on specified criteria.
44
+ - Provide caller information in log messages (filename, line number).
45
+
46
+ By default, `teeLogger` outputs to the console and a timestamped log file. You can disable file logging or console printing as needed.
47
+
48
+ ---
49
+
50
+ ## Key Components
51
+
52
+ ### bcolors
53
+ A helper class providing ANSI escape codes for colored terminal output.
54
+ ```python
55
+ class bcolors:
56
+ HEADER = '\033[95m'
57
+ OKBLUE = '\033[94m'
58
+ OKCYAN = '\033[96m'
59
+ OKGREEN = '\033[92m'
60
+ warning = '\033[93m'
61
+ critical = '\033[91m'
62
+ info = '\033[0m'
63
+ debug = '\033[0m'
64
+ ENDC = '\033[0m'
65
+ BOLD = '\033[1m'
66
+ UNDERLINE = '\033[4m'
67
+ ```
68
+ ### abbreviate_filename
69
+ A function that shortens file names with optional advanced transformations (e.g., using base64 or scientific notation for line numbers). It is used internally to display a concise “filename:lineNumber” in log messages.
70
+
71
+ ### printWithColor
72
+ A helper function that prints a plain text string to the console, wrapped in the appropriate ANSI color codes based on a `level`:
73
+ - `info`: bcolors.info
74
+ - `debug`: bcolors.debug
75
+ - `warning`: bcolors.warning
76
+ - `error`: bcolors.warning
77
+ - `critical`: bcolors.critical
78
+ - `ok` or `okgreen`: bcolors.OKGREEN
79
+ - `okblue`: bcolors.OKBLUE
80
+ - `okcyan`: bcolors.OKCYAN
81
+ - default: bcolors.info
82
+
83
+ ### teeLogger
84
+ Primary logger class with the following notable parameters:
85
+
86
+ - `systemLogFileDir`: Directory in which log folders are stored. If `/dev/null`, logging to a file is suppressed. Note: if the specifiled dir cannot be accessed, will then try to use `/tmp`
87
+ - `programName`: Name associated with the logs. Defaults to the caller’s filename.
88
+ - `compressLogAfterMonths`: Number of months after which logs are automatically compressed.
89
+ - `deleteLogAfterYears`: Number of years after which logs are deleted.
90
+ - `suppressPrintout`: If set to `True`, console printing is suppressed, but logs still appear in the file.
91
+ - `fileDescriptorLength`: Maximum title span for formatted file name and line number in logs.
92
+ - `noLog`: If `True`, no file logging occurs.
93
+ - `callerStackDepth`: The stack depth for tracing back the caller file path and line number. Default to 2.
94
+
95
+ Methods include:
96
+ - `teeok(msg)`, `ok(msg)`, `info(msg)`, `error(msg)`, `teeerror(msg)`: Log a message at various levels, optionally printing to console.
97
+ - `printTable(data)`: Nicely formats 2D data or a dictionary as a table before logging.
98
+ - `teelog(msg, level)`: General-purpose logger for any level (e.g. `"warning"`, `"critical"`).
99
+ - `cleanup_old_logs()`: Called automatically to compress or remove old logs.
100
+
101
+ ---
102
+
103
+ ## Usage Examples
104
+
105
+ ```python
106
+ from Tee_Logger import teeLogger
107
+
108
+ # Create a logger instance
109
+ tl = teeLogger(systemLogFileDir='.', programName='MyApp', compressLogAfterMonths=2, deleteLogAfterYears=1)
110
+
111
+ # Log messages
112
+ tl.info("This is an info message. ( only log to file )")
113
+ tl.teeerror("This is an error reported to both stdout and file")
114
+ tl.teeok("Operation successful.")
115
+ tl.teeprint("Normal messages.")
116
+ level='critical'
117
+ tl.teelog('Tee Log with level as a variable',level)
118
+ level='warning'
119
+ tl.log('Log with variable level',level)
120
+ ```
121
+ Terminal output:
122
+ ```
123
+ Log file: <cwd>/MyApp_log/2025-02-10/MyApp_2025-02-10_01-33-26.log
124
+ This is an error reported to both stdout and file
125
+ Operation successful.
126
+ Normal messages.
127
+ Tee Log with level as a variable
128
+ ```
129
+ ![example_console_output](screenshots/console_output.png)
130
+
131
+
132
+ Logger file:
133
+ ```log
134
+ 2025-02-10 01:33:26,622 [INFO ] [Tee_Logger:357 ] Starting MyApp at 2025-02-10_01-33-26
135
+ 2025-02-10 01:33:26,623 [INFO ] [Tee_Logger:357 ] This is an info message. ( only log to file )
136
+ 2025-02-10 01:33:26,624 [ERROR ] [Tee_Logger:362 ] This is an error reported to both stdout and file
137
+ 2025-02-10 01:33:26,625 [INFO ] [Tee_Logger:340 ] Operation successful.
138
+ 2025-02-10 01:33:26,626 [INFO ] [Tee_Logger:354 ] Normal messages.
139
+ 2025-02-10 01:33:26,627 [CRITICAL] [Tee_Logger:370 ] Tee Log with level as a variable
140
+ 2025-02-10 01:33:26,628 [WARNING ] [Tee_Logger:374 ] Log with variable level
141
+ ```
142
+ Note: by default, the caller trace back level is 2, which usually will be the line calling for log.
143
+ ---
144
+
145
+ ## Log Maintenance
146
+
147
+ All logs are stored in `programName_log/YYYY-MM-DD` directories. Upon initialization, the logger permanently runs `cleanup_old_logs()` to:
148
+ - Compress logs older than `compressLogAfterMonths`.
149
+ - Delete logs older than `deleteLogAfterYears`.
150
+
151
+ Compression uses `tar` with `xz` if available, otherwise uses Python’s built-in `tarfile` library. The cleanup runs asynchronously using a `ProcessPoolExecutor`.
@@ -0,0 +1,4 @@
1
+ tee_logger-6.19.dist-info/METADATA,sha256=fZluwMM8LURNXTOdtMXnhEJMO--j4f2L_IwWWixzsG8,6123
2
+ tee_logger-6.19.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
3
+ tee_logger-6.19.dist-info/top_level.txt,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
4
+ tee_logger-6.19.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.8.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+