python-fast-logger 0.1.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Ravi Mishra
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.
File without changes
@@ -0,0 +1,232 @@
1
+ Metadata-Version: 2.4
2
+ Name: python-fast-logger
3
+ Version: 0.1.0
4
+ Summary: A simple, no-fuss logging setup for Python applications
5
+ Author-email: Ravi Mishra <ravi@paisafintech.com>
6
+ Maintainer-email: Ravi Mishra <ravi@paisafintech.com>
7
+ License: MIT
8
+ Project-URL: Homepage, https://github.com/RaviMishra-94/fast-logger
9
+ Project-URL: Documentation, https://github.com/RaviMishra-94/fast-logger/blob/main/README.md
10
+ Project-URL: Repository, https://github.com/RaviMishra-94/fast-logger.git
11
+ Project-URL: Bug Tracker, https://github.com/RaviMishra-94/fast-logger/issues
12
+ Keywords: logging,logger,simple,fast,rotating,file
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.7
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
25
+ Classifier: Topic :: System :: Logging
26
+ Requires-Python: >=3.7
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=6.0; extra == "dev"
31
+ Requires-Dist: pytest-cov>=2.0; extra == "dev"
32
+ Requires-Dist: black>=21.0; extra == "dev"
33
+ Requires-Dist: flake8>=3.8; extra == "dev"
34
+ Requires-Dist: mypy>=0.800; extra == "dev"
35
+ Dynamic: license-file
36
+
37
+ # Fast Logger
38
+
39
+ ![Tests](https://github.com/RaviMishra-94/fast-logger/actions/workflows/python-app.yml/badge.svg)
40
+
41
+ A simple, no-fuss logging setup for Python applications with sensible defaults.
42
+
43
+ ## Features
44
+
45
+ - **Zero configuration**: Works out of the box with sensible defaults
46
+ - **Rotating file logs**: Automatically manages log file sizes and backups
47
+ - **Console output**: Simultaneous logging to file and console
48
+ - **Flexible configuration**: Easy to customize when needed
49
+ - **Type hints**: Full type hint support for better IDE experience
50
+ - **No dependencies**: Uses only Python standard library
51
+
52
+ ## Installation
53
+
54
+ ```bash
55
+ pip install fast-logger
56
+ ```
57
+
58
+ ## Quick Start
59
+
60
+ ### Super Simple Usage
61
+
62
+ ```python
63
+ from fast_logger import quick_logger
64
+
65
+ logger = quick_logger("my_app")
66
+ logger.info("Hello, world!")
67
+ logger.error("Something went wrong!")
68
+ ```
69
+
70
+ ### Basic Usage
71
+
72
+ ```python
73
+ from fast_logger import get_logger
74
+
75
+ logger = get_logger("my_app")
76
+ logger.info("Application started")
77
+ logger.warning("This is a warning")
78
+ logger.error("This is an error")
79
+ ```
80
+
81
+ ### Advanced Usage
82
+
83
+ ```python
84
+ from fast_logger import FastLogger
85
+
86
+ # Custom configuration
87
+ logger = FastLogger(
88
+ name="my_advanced_app",
89
+ level="DEBUG",
90
+ log_folder="custom_logs",
91
+ max_file_size_mb=100,
92
+ backup_count=5,
93
+ console_output=True
94
+ )
95
+
96
+ logger.info("Advanced logging setup complete")
97
+ logger.debug("Debug information")
98
+ ```
99
+
100
+ ### Web Application Example
101
+
102
+ ```python
103
+ from fast_logger import get_logger
104
+ from flask import Flask
105
+
106
+ app = Flask(__name__)
107
+ logger = get_logger("web_app", level="INFO")
108
+
109
+ @app.route("/")
110
+ def home():
111
+ logger.info("Home page accessed")
112
+ return "Hello, World!"
113
+
114
+ @app.route("/api/data")
115
+ def get_data():
116
+ try:
117
+ # Your API logic here
118
+ data = {"status": "success"}
119
+ logger.info("Data retrieved successfully")
120
+ return data
121
+ except Exception as e:
122
+ logger.error(f"Error retrieving data: {e}")
123
+ return {"status": "error"}, 500
124
+ ```
125
+
126
+ ## Configuration Options
127
+
128
+ | Parameter | Type | Default | Description |
129
+ |-----------|------|---------|-------------|
130
+ | `name` | str | Required | Logger name (used as filename) |
131
+ | `level` | str/int | `INFO` | Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
132
+ | `log_folder` | str | `logs` | Directory name for log files |
133
+ | `max_file_size_mb` | int | `50` | Maximum size of each log file in MB |
134
+ | `backup_count` | int | `3` | Number of backup files to keep |
135
+ | `console_output` | bool | `True` | Whether to output to console |
136
+ | `log_format` | str | Default format | Custom log format string |
137
+ | `base_path` | str | Caller's directory | Base directory for logs |
138
+
139
+ ## Default Log Format
140
+
141
+ ```
142
+ 2024-01-15 10:30:45,123 - my_app [main.py:15] - INFO - Hello, world!
143
+ ```
144
+
145
+ ## File Structure
146
+
147
+ By default, logs are created in a `logs` folder relative to your script:
148
+
149
+ ```
150
+ your_project/
151
+ ├── main.py
152
+ └── logs/
153
+ ├── my_app.log
154
+ ├── my_app.log.1
155
+ └── my_app.log.2
156
+ ```
157
+
158
+ ## API Reference
159
+
160
+ ### FastLogger Class
161
+
162
+ The main class for advanced usage with full configuration options.
163
+
164
+ ```python
165
+ logger = FastLogger(
166
+ name="my_app",
167
+ level="INFO",
168
+ log_folder="logs",
169
+ max_file_size_mb=50,
170
+ backup_count=3,
171
+ console_output=True,
172
+ log_format=None,
173
+ base_path=None
174
+ )
175
+ ```
176
+
177
+ ### Convenience Functions
178
+
179
+ - `quick_logger(name, level="INFO")`: Minimal setup for immediate use
180
+ - `get_logger(name, **kwargs)`: Returns FastLogger instance with fluent interface
181
+ - `setup_logger(name, **kwargs)`: Returns standard logging.Logger instance
182
+
183
+ ## Why Fast Logger?
184
+
185
+ Most Python applications need logging, but setting it up properly requires boilerplate code:
186
+
187
+ - Creating formatters
188
+ - Setting up file handlers
189
+ - Configuring rotation
190
+ - Adding console output
191
+ - Managing log directories
192
+
193
+ Fast Logger eliminates this boilerplate while providing sensible defaults that work for most applications.
194
+
195
+ ## Comparison with Standard Logging
196
+
197
+ **Standard logging setup:**
198
+ ```python
199
+ import logging
200
+ import os
201
+ from logging.handlers import RotatingFileHandler
202
+
203
+ # 15+ lines of boilerplate code...
204
+ logger = logging.getLogger("my_app")
205
+ logger.setLevel(logging.INFO)
206
+ # ... more setup code
207
+ ```
208
+
209
+ **Fast Logger:**
210
+ ```python
211
+ from fast_logger import quick_logger
212
+
213
+ logger = quick_logger("my_app")
214
+ # Done!
215
+ ```
216
+
217
+ ## Requirements
218
+
219
+ - Python 3.7+
220
+ - No external dependencies
221
+
222
+ ## License
223
+
224
+ MIT License. See LICENSE file for details.
225
+
226
+ ## Contributing
227
+
228
+ Contributions are welcome! Please feel free to submit a Pull Request.
229
+
230
+ ## Changelog
231
+
232
+ See [CHANGELOG.md](CHANGELOG.md) for version history.
@@ -0,0 +1,196 @@
1
+ # Fast Logger
2
+
3
+ ![Tests](https://github.com/RaviMishra-94/fast-logger/actions/workflows/python-app.yml/badge.svg)
4
+
5
+ A simple, no-fuss logging setup for Python applications with sensible defaults.
6
+
7
+ ## Features
8
+
9
+ - **Zero configuration**: Works out of the box with sensible defaults
10
+ - **Rotating file logs**: Automatically manages log file sizes and backups
11
+ - **Console output**: Simultaneous logging to file and console
12
+ - **Flexible configuration**: Easy to customize when needed
13
+ - **Type hints**: Full type hint support for better IDE experience
14
+ - **No dependencies**: Uses only Python standard library
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ pip install fast-logger
20
+ ```
21
+
22
+ ## Quick Start
23
+
24
+ ### Super Simple Usage
25
+
26
+ ```python
27
+ from fast_logger import quick_logger
28
+
29
+ logger = quick_logger("my_app")
30
+ logger.info("Hello, world!")
31
+ logger.error("Something went wrong!")
32
+ ```
33
+
34
+ ### Basic Usage
35
+
36
+ ```python
37
+ from fast_logger import get_logger
38
+
39
+ logger = get_logger("my_app")
40
+ logger.info("Application started")
41
+ logger.warning("This is a warning")
42
+ logger.error("This is an error")
43
+ ```
44
+
45
+ ### Advanced Usage
46
+
47
+ ```python
48
+ from fast_logger import FastLogger
49
+
50
+ # Custom configuration
51
+ logger = FastLogger(
52
+ name="my_advanced_app",
53
+ level="DEBUG",
54
+ log_folder="custom_logs",
55
+ max_file_size_mb=100,
56
+ backup_count=5,
57
+ console_output=True
58
+ )
59
+
60
+ logger.info("Advanced logging setup complete")
61
+ logger.debug("Debug information")
62
+ ```
63
+
64
+ ### Web Application Example
65
+
66
+ ```python
67
+ from fast_logger import get_logger
68
+ from flask import Flask
69
+
70
+ app = Flask(__name__)
71
+ logger = get_logger("web_app", level="INFO")
72
+
73
+ @app.route("/")
74
+ def home():
75
+ logger.info("Home page accessed")
76
+ return "Hello, World!"
77
+
78
+ @app.route("/api/data")
79
+ def get_data():
80
+ try:
81
+ # Your API logic here
82
+ data = {"status": "success"}
83
+ logger.info("Data retrieved successfully")
84
+ return data
85
+ except Exception as e:
86
+ logger.error(f"Error retrieving data: {e}")
87
+ return {"status": "error"}, 500
88
+ ```
89
+
90
+ ## Configuration Options
91
+
92
+ | Parameter | Type | Default | Description |
93
+ |-----------|------|---------|-------------|
94
+ | `name` | str | Required | Logger name (used as filename) |
95
+ | `level` | str/int | `INFO` | Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
96
+ | `log_folder` | str | `logs` | Directory name for log files |
97
+ | `max_file_size_mb` | int | `50` | Maximum size of each log file in MB |
98
+ | `backup_count` | int | `3` | Number of backup files to keep |
99
+ | `console_output` | bool | `True` | Whether to output to console |
100
+ | `log_format` | str | Default format | Custom log format string |
101
+ | `base_path` | str | Caller's directory | Base directory for logs |
102
+
103
+ ## Default Log Format
104
+
105
+ ```
106
+ 2024-01-15 10:30:45,123 - my_app [main.py:15] - INFO - Hello, world!
107
+ ```
108
+
109
+ ## File Structure
110
+
111
+ By default, logs are created in a `logs` folder relative to your script:
112
+
113
+ ```
114
+ your_project/
115
+ ├── main.py
116
+ └── logs/
117
+ ├── my_app.log
118
+ ├── my_app.log.1
119
+ └── my_app.log.2
120
+ ```
121
+
122
+ ## API Reference
123
+
124
+ ### FastLogger Class
125
+
126
+ The main class for advanced usage with full configuration options.
127
+
128
+ ```python
129
+ logger = FastLogger(
130
+ name="my_app",
131
+ level="INFO",
132
+ log_folder="logs",
133
+ max_file_size_mb=50,
134
+ backup_count=3,
135
+ console_output=True,
136
+ log_format=None,
137
+ base_path=None
138
+ )
139
+ ```
140
+
141
+ ### Convenience Functions
142
+
143
+ - `quick_logger(name, level="INFO")`: Minimal setup for immediate use
144
+ - `get_logger(name, **kwargs)`: Returns FastLogger instance with fluent interface
145
+ - `setup_logger(name, **kwargs)`: Returns standard logging.Logger instance
146
+
147
+ ## Why Fast Logger?
148
+
149
+ Most Python applications need logging, but setting it up properly requires boilerplate code:
150
+
151
+ - Creating formatters
152
+ - Setting up file handlers
153
+ - Configuring rotation
154
+ - Adding console output
155
+ - Managing log directories
156
+
157
+ Fast Logger eliminates this boilerplate while providing sensible defaults that work for most applications.
158
+
159
+ ## Comparison with Standard Logging
160
+
161
+ **Standard logging setup:**
162
+ ```python
163
+ import logging
164
+ import os
165
+ from logging.handlers import RotatingFileHandler
166
+
167
+ # 15+ lines of boilerplate code...
168
+ logger = logging.getLogger("my_app")
169
+ logger.setLevel(logging.INFO)
170
+ # ... more setup code
171
+ ```
172
+
173
+ **Fast Logger:**
174
+ ```python
175
+ from fast_logger import quick_logger
176
+
177
+ logger = quick_logger("my_app")
178
+ # Done!
179
+ ```
180
+
181
+ ## Requirements
182
+
183
+ - Python 3.7+
184
+ - No external dependencies
185
+
186
+ ## License
187
+
188
+ MIT License. See LICENSE file for details.
189
+
190
+ ## Contributing
191
+
192
+ Contributions are welcome! Please feel free to submit a Pull Request.
193
+
194
+ ## Changelog
195
+
196
+ See [CHANGELOG.md](CHANGELOG.md) for version history.
@@ -0,0 +1,43 @@
1
+ """
2
+ Fast Logger - A simple, no-fuss logging setup for Python applications.
3
+
4
+ This package provides a quick and easy way to set up logging in Python applications
5
+ with sensible defaults, rotating file handlers, and console output.
6
+
7
+ Basic usage:
8
+ from fast_logger import get_logger
9
+
10
+ logger = get_logger("my_app")
11
+ logger.info("Hello, world!")
12
+
13
+ Quick setup:
14
+ from fast_logger import quick_logger
15
+
16
+ logger = quick_logger("my_app")
17
+ logger.info("Hello, world!")
18
+
19
+ Advanced usage:
20
+ from fast_logger import FastLogger
21
+
22
+ logger = FastLogger(
23
+ name="my_app",
24
+ level="DEBUG",
25
+ max_file_size_mb=100,
26
+ backup_count=5
27
+ )
28
+ logger.info("Hello, world!")
29
+ """
30
+
31
+ from .core import FastLogger, setup_logger, get_logger, quick_logger
32
+
33
+ __version__ = "0.1.0"
34
+ __author__ = "Ravi Mishra"
35
+ __email__ = "ravi@paisafintech.com"
36
+
37
+ __all__ = [
38
+ "FastLogger",
39
+ "setup_logger",
40
+ "get_logger",
41
+ "quick_logger",
42
+ "__version__",
43
+ ]
@@ -0,0 +1,187 @@
1
+ """
2
+ Fast Logger - A simple, no-fuss logging setup for Python applications
3
+ """
4
+
5
+ import logging
6
+ import sys
7
+ from logging.handlers import RotatingFileHandler
8
+ from pathlib import Path
9
+ from typing import Optional, Union
10
+
11
+
12
+ class FastLogger:
13
+ """A simple logger setup with sensible defaults."""
14
+
15
+ def __init__(self,
16
+ name: str,
17
+ level: Union[int, str] = logging.INFO,
18
+ log_folder: str = 'logs',
19
+ max_file_size_mb: int = 50,
20
+ backup_count: int = 3,
21
+ log_format: Optional[str] = None,
22
+ console_output: bool = True,
23
+ base_path: Optional[str] = None):
24
+ """
25
+ Initialize FastLogger with configuration.
26
+
27
+ Args:
28
+ name: Logger name (will be used as filename)
29
+ level: Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
30
+ log_folder: Directory name for log files
31
+ max_file_size_mb: Maximum size of each log file in MB
32
+ backup_count: Number of backup files to keep
33
+ log_format: Custom log format string
34
+ console_output: Whether to output to console
35
+ base_path: Base directory for logs (defaults to caller's directory)
36
+ """
37
+ self.name = name
38
+ self.level = self._parse_level(level)
39
+ self.log_folder = log_folder
40
+ self.max_file_size_mb = max_file_size_mb
41
+ self.backup_count = backup_count
42
+ self.console_output = console_output
43
+ self.base_path = base_path
44
+
45
+ # Default format
46
+ self.log_format = log_format or (
47
+ '%(asctime)s - %(name)s [%(filename)s:%(lineno)d] - '
48
+ '%(levelname)s - %(message)s'
49
+ )
50
+
51
+ self._logger = None
52
+ self._setup_logger()
53
+
54
+ @staticmethod
55
+ def _parse_level(level: Union[int, str]) -> int:
56
+ """Parse logging level from string or int."""
57
+ if isinstance(level, str):
58
+ return getattr(logging, level.upper(), logging.INFO)
59
+ return level
60
+
61
+ def _get_log_directory(self) -> Path:
62
+ """Get the log directory path."""
63
+ if self.base_path:
64
+ base = Path(self.base_path)
65
+ else:
66
+ # Use the directory of the calling script
67
+ import inspect
68
+ frame = inspect.currentframe()
69
+ try:
70
+ # Go up the stack to find the caller
71
+ caller_frame = frame.f_back.f_back.f_back # Go up one more level
72
+ caller_file = caller_frame.f_code.co_filename
73
+ base = Path(caller_file).parent
74
+ finally:
75
+ del frame
76
+
77
+ log_dir = base / self.log_folder
78
+ log_dir.mkdir(parents=True, exist_ok=True)
79
+ return log_dir
80
+
81
+ def _setup_logger(self):
82
+ """Set up the logger with file and console handlers."""
83
+ # Get or create logger
84
+ self._logger = logging.getLogger(self.name)
85
+
86
+ # Clear any existing handlers to avoid duplicates
87
+ self._logger.handlers.clear()
88
+ self._logger.setLevel(self.level)
89
+
90
+ # Create formatter
91
+ formatter = logging.Formatter(self.log_format)
92
+
93
+ # File handler
94
+ log_dir = self._get_log_directory()
95
+ log_file = log_dir / f"{self.name}.log"
96
+
97
+ file_handler = RotatingFileHandler(
98
+ str(log_file), # Convert Path to string
99
+ maxBytes=self.max_file_size_mb * 1024 * 1024,
100
+ backupCount=self.backup_count,
101
+ encoding='utf-8'
102
+ )
103
+ file_handler.setLevel(self.level)
104
+ file_handler.setFormatter(formatter)
105
+ self._logger.addHandler(file_handler)
106
+
107
+ # Console handler (only if enabled)
108
+ if self.console_output:
109
+ console_handler = logging.StreamHandler(sys.stdout)
110
+ console_handler.setLevel(self.level)
111
+ console_handler.setFormatter(formatter)
112
+ self._logger.addHandler(console_handler)
113
+
114
+ # Prevent propagation to root logger
115
+ self._logger.propagate = False
116
+
117
+ def get_logger(self) -> logging.Logger:
118
+ """Get the configured logger instance."""
119
+ return self._logger
120
+
121
+ def debug(self, message: str, *args, **kwargs):
122
+ """Log a debug message."""
123
+ self._logger.debug(message, *args, **kwargs)
124
+
125
+ def info(self, message: str, *args, **kwargs):
126
+ """Log an info message."""
127
+ self._logger.info(message, *args, **kwargs)
128
+
129
+ def warning(self, message: str, *args, **kwargs):
130
+ """Log a warning message."""
131
+ self._logger.warning(message, *args, **kwargs)
132
+
133
+ def error(self, message: str, *args, **kwargs):
134
+ """Log an error message."""
135
+ self._logger.error(message, *args, **kwargs)
136
+
137
+ def critical(self, message: str, *args, **kwargs):
138
+ """Log a critical message."""
139
+ self._logger.critical(message, *args, **kwargs)
140
+
141
+ def exception(self, message: str, *args, **kwargs):
142
+ """Log an exception with traceback."""
143
+ self._logger.exception(message, *args, **kwargs)
144
+
145
+
146
+ def setup_logger(name: str, **kwargs) -> logging.Logger:
147
+ """
148
+ Quick setup function for backward compatibility and convenience.
149
+
150
+ Args:
151
+ name: Logger name
152
+ **kwargs: Additional arguments passed to FastLogger
153
+
154
+ Returns:
155
+ Configured logger instance
156
+ """
157
+ fast_logger = FastLogger(name, **kwargs)
158
+ return fast_logger.get_logger()
159
+
160
+
161
+ def get_logger(name: str, **kwargs) -> FastLogger:
162
+ """
163
+ Get a FastLogger instance with fluent interface.
164
+
165
+ Args:
166
+ name: Logger name
167
+ **kwargs: Additional arguments passed to FastLogger
168
+
169
+ Returns:
170
+ FastLogger instance
171
+ """
172
+ return FastLogger(name, **kwargs)
173
+
174
+
175
+ # Convenience function for one-liner setup
176
+ def quick_logger(name: str, level: str = 'INFO') -> logging.Logger:
177
+ """
178
+ Super quick logger setup with minimal configuration.
179
+
180
+ Args:
181
+ name: Logger name
182
+ level: Logging level
183
+
184
+ Returns:
185
+ Configured logger instance
186
+ """
187
+ return setup_logger(name, level=level)
@@ -0,0 +1,65 @@
1
+ [build-system]
2
+ requires = ["setuptools>=45", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "python-fast-logger"
7
+ version = "0.1.0"
8
+ description = "A simple, no-fuss logging setup for Python applications"
9
+ readme = "README.md"
10
+ license = {text = "MIT"}
11
+ authors = [
12
+ {name = "Ravi Mishra", email = "ravi@paisafintech.com"}
13
+ ]
14
+ maintainers = [
15
+ {name = "Ravi Mishra", email = "ravi@paisafintech.com"}
16
+ ]
17
+ classifiers = [
18
+ "Development Status :: 4 - Beta",
19
+ "Intended Audience :: Developers",
20
+ "License :: OSI Approved :: MIT License",
21
+ "Operating System :: OS Independent",
22
+ "Programming Language :: Python :: 3",
23
+ "Programming Language :: Python :: 3.7",
24
+ "Programming Language :: Python :: 3.8",
25
+ "Programming Language :: Python :: 3.9",
26
+ "Programming Language :: Python :: 3.10",
27
+ "Programming Language :: Python :: 3.11",
28
+ "Programming Language :: Python :: 3.12",
29
+ "Topic :: Software Development :: Libraries :: Python Modules",
30
+ "Topic :: System :: Logging",
31
+ ]
32
+ keywords = ["logging", "logger", "simple", "fast", "rotating", "file"]
33
+ requires-python = ">=3.7"
34
+ dependencies = []
35
+
36
+ [project.optional-dependencies]
37
+ dev = [
38
+ "pytest>=6.0",
39
+ "pytest-cov>=2.0",
40
+ "black>=21.0",
41
+ "flake8>=3.8",
42
+ "mypy>=0.800",
43
+ ]
44
+
45
+ [project.urls]
46
+ Homepage = "https://github.com/RaviMishra-94/fast-logger"
47
+ Documentation = "https://github.com/RaviMishra-94/fast-logger/blob/main/README.md"
48
+ Repository = "https://github.com/RaviMishra-94/fast-logger.git"
49
+ "Bug Tracker" = "https://github.com/RaviMishra-94/fast-logger/issues"
50
+
51
+ [tool.setuptools.packages.find]
52
+ where = ["."]
53
+ include = ["fast_logger*"]
54
+
55
+
56
+
57
+ [tool.black]
58
+ line-length = 88
59
+ target-version = ['py37', 'py38', 'py39', 'py310', 'py311']
60
+
61
+ [tool.mypy]
62
+ python_version = "3.7"
63
+ warn_return_any = true
64
+ warn_unused_configs = true
65
+ disallow_untyped_defs = true
@@ -0,0 +1,232 @@
1
+ Metadata-Version: 2.4
2
+ Name: python-fast-logger
3
+ Version: 0.1.0
4
+ Summary: A simple, no-fuss logging setup for Python applications
5
+ Author-email: Ravi Mishra <ravi@paisafintech.com>
6
+ Maintainer-email: Ravi Mishra <ravi@paisafintech.com>
7
+ License: MIT
8
+ Project-URL: Homepage, https://github.com/RaviMishra-94/fast-logger
9
+ Project-URL: Documentation, https://github.com/RaviMishra-94/fast-logger/blob/main/README.md
10
+ Project-URL: Repository, https://github.com/RaviMishra-94/fast-logger.git
11
+ Project-URL: Bug Tracker, https://github.com/RaviMishra-94/fast-logger/issues
12
+ Keywords: logging,logger,simple,fast,rotating,file
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.7
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
25
+ Classifier: Topic :: System :: Logging
26
+ Requires-Python: >=3.7
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=6.0; extra == "dev"
31
+ Requires-Dist: pytest-cov>=2.0; extra == "dev"
32
+ Requires-Dist: black>=21.0; extra == "dev"
33
+ Requires-Dist: flake8>=3.8; extra == "dev"
34
+ Requires-Dist: mypy>=0.800; extra == "dev"
35
+ Dynamic: license-file
36
+
37
+ # Fast Logger
38
+
39
+ ![Tests](https://github.com/RaviMishra-94/fast-logger/actions/workflows/python-app.yml/badge.svg)
40
+
41
+ A simple, no-fuss logging setup for Python applications with sensible defaults.
42
+
43
+ ## Features
44
+
45
+ - **Zero configuration**: Works out of the box with sensible defaults
46
+ - **Rotating file logs**: Automatically manages log file sizes and backups
47
+ - **Console output**: Simultaneous logging to file and console
48
+ - **Flexible configuration**: Easy to customize when needed
49
+ - **Type hints**: Full type hint support for better IDE experience
50
+ - **No dependencies**: Uses only Python standard library
51
+
52
+ ## Installation
53
+
54
+ ```bash
55
+ pip install fast-logger
56
+ ```
57
+
58
+ ## Quick Start
59
+
60
+ ### Super Simple Usage
61
+
62
+ ```python
63
+ from fast_logger import quick_logger
64
+
65
+ logger = quick_logger("my_app")
66
+ logger.info("Hello, world!")
67
+ logger.error("Something went wrong!")
68
+ ```
69
+
70
+ ### Basic Usage
71
+
72
+ ```python
73
+ from fast_logger import get_logger
74
+
75
+ logger = get_logger("my_app")
76
+ logger.info("Application started")
77
+ logger.warning("This is a warning")
78
+ logger.error("This is an error")
79
+ ```
80
+
81
+ ### Advanced Usage
82
+
83
+ ```python
84
+ from fast_logger import FastLogger
85
+
86
+ # Custom configuration
87
+ logger = FastLogger(
88
+ name="my_advanced_app",
89
+ level="DEBUG",
90
+ log_folder="custom_logs",
91
+ max_file_size_mb=100,
92
+ backup_count=5,
93
+ console_output=True
94
+ )
95
+
96
+ logger.info("Advanced logging setup complete")
97
+ logger.debug("Debug information")
98
+ ```
99
+
100
+ ### Web Application Example
101
+
102
+ ```python
103
+ from fast_logger import get_logger
104
+ from flask import Flask
105
+
106
+ app = Flask(__name__)
107
+ logger = get_logger("web_app", level="INFO")
108
+
109
+ @app.route("/")
110
+ def home():
111
+ logger.info("Home page accessed")
112
+ return "Hello, World!"
113
+
114
+ @app.route("/api/data")
115
+ def get_data():
116
+ try:
117
+ # Your API logic here
118
+ data = {"status": "success"}
119
+ logger.info("Data retrieved successfully")
120
+ return data
121
+ except Exception as e:
122
+ logger.error(f"Error retrieving data: {e}")
123
+ return {"status": "error"}, 500
124
+ ```
125
+
126
+ ## Configuration Options
127
+
128
+ | Parameter | Type | Default | Description |
129
+ |-----------|------|---------|-------------|
130
+ | `name` | str | Required | Logger name (used as filename) |
131
+ | `level` | str/int | `INFO` | Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
132
+ | `log_folder` | str | `logs` | Directory name for log files |
133
+ | `max_file_size_mb` | int | `50` | Maximum size of each log file in MB |
134
+ | `backup_count` | int | `3` | Number of backup files to keep |
135
+ | `console_output` | bool | `True` | Whether to output to console |
136
+ | `log_format` | str | Default format | Custom log format string |
137
+ | `base_path` | str | Caller's directory | Base directory for logs |
138
+
139
+ ## Default Log Format
140
+
141
+ ```
142
+ 2024-01-15 10:30:45,123 - my_app [main.py:15] - INFO - Hello, world!
143
+ ```
144
+
145
+ ## File Structure
146
+
147
+ By default, logs are created in a `logs` folder relative to your script:
148
+
149
+ ```
150
+ your_project/
151
+ ├── main.py
152
+ └── logs/
153
+ ├── my_app.log
154
+ ├── my_app.log.1
155
+ └── my_app.log.2
156
+ ```
157
+
158
+ ## API Reference
159
+
160
+ ### FastLogger Class
161
+
162
+ The main class for advanced usage with full configuration options.
163
+
164
+ ```python
165
+ logger = FastLogger(
166
+ name="my_app",
167
+ level="INFO",
168
+ log_folder="logs",
169
+ max_file_size_mb=50,
170
+ backup_count=3,
171
+ console_output=True,
172
+ log_format=None,
173
+ base_path=None
174
+ )
175
+ ```
176
+
177
+ ### Convenience Functions
178
+
179
+ - `quick_logger(name, level="INFO")`: Minimal setup for immediate use
180
+ - `get_logger(name, **kwargs)`: Returns FastLogger instance with fluent interface
181
+ - `setup_logger(name, **kwargs)`: Returns standard logging.Logger instance
182
+
183
+ ## Why Fast Logger?
184
+
185
+ Most Python applications need logging, but setting it up properly requires boilerplate code:
186
+
187
+ - Creating formatters
188
+ - Setting up file handlers
189
+ - Configuring rotation
190
+ - Adding console output
191
+ - Managing log directories
192
+
193
+ Fast Logger eliminates this boilerplate while providing sensible defaults that work for most applications.
194
+
195
+ ## Comparison with Standard Logging
196
+
197
+ **Standard logging setup:**
198
+ ```python
199
+ import logging
200
+ import os
201
+ from logging.handlers import RotatingFileHandler
202
+
203
+ # 15+ lines of boilerplate code...
204
+ logger = logging.getLogger("my_app")
205
+ logger.setLevel(logging.INFO)
206
+ # ... more setup code
207
+ ```
208
+
209
+ **Fast Logger:**
210
+ ```python
211
+ from fast_logger import quick_logger
212
+
213
+ logger = quick_logger("my_app")
214
+ # Done!
215
+ ```
216
+
217
+ ## Requirements
218
+
219
+ - Python 3.7+
220
+ - No external dependencies
221
+
222
+ ## License
223
+
224
+ MIT License. See LICENSE file for details.
225
+
226
+ ## Contributing
227
+
228
+ Contributions are welcome! Please feel free to submit a Pull Request.
229
+
230
+ ## Changelog
231
+
232
+ See [CHANGELOG.md](CHANGELOG.md) for version history.
@@ -0,0 +1,13 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ setup.cfg
6
+ fast_logger/__init__.py
7
+ fast_logger/core.py
8
+ python_fast_logger.egg-info/PKG-INFO
9
+ python_fast_logger.egg-info/SOURCES.txt
10
+ python_fast_logger.egg-info/dependency_links.txt
11
+ python_fast_logger.egg-info/requires.txt
12
+ python_fast_logger.egg-info/top_level.txt
13
+ tests/test_fast_logger.py
@@ -0,0 +1,7 @@
1
+
2
+ [dev]
3
+ pytest>=6.0
4
+ pytest-cov>=2.0
5
+ black>=21.0
6
+ flake8>=3.8
7
+ mypy>=0.800
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,209 @@
1
+ import unittest
2
+ import tempfile
3
+ import shutil
4
+ import logging
5
+ from pathlib import Path
6
+ from fast_logger import FastLogger, quick_logger, get_logger, setup_logger
7
+
8
+
9
+ class TestFastLogger(unittest.TestCase):
10
+
11
+ def setUp(self):
12
+ """Set up test fixtures."""
13
+ self.temp_dir = tempfile.mkdtemp()
14
+ self.test_name = "test_logger"
15
+
16
+ def tearDown(self):
17
+ """Clean up after tests."""
18
+ shutil.rmtree(self.temp_dir, ignore_errors=True)
19
+
20
+ def test_basic_logger_creation(self):
21
+ """Test basic logger creation."""
22
+ logger = FastLogger(
23
+ name=self.test_name,
24
+ base_path=self.temp_dir
25
+ )
26
+
27
+ self.assertIsNotNone(logger.get_logger())
28
+ self.assertEqual(logger.name, self.test_name)
29
+ self.assertEqual(logger.level, logging.INFO)
30
+
31
+ def test_log_file_creation(self):
32
+ """Test that log files are created."""
33
+ logger = FastLogger(
34
+ name=self.test_name,
35
+ base_path=self.temp_dir
36
+ )
37
+
38
+ logger.info("Test message")
39
+
40
+ # Force flush to ensure file is written
41
+ for handler in logger.get_logger().handlers:
42
+ if hasattr(handler, 'flush'):
43
+ handler.flush()
44
+
45
+ log_file = Path(self.temp_dir) / "logs" / f"{self.test_name}.log"
46
+ self.assertTrue(log_file.exists())
47
+
48
+ def test_log_content(self):
49
+ """Test that log content is written correctly."""
50
+ logger = FastLogger(
51
+ name=self.test_name,
52
+ base_path=self.temp_dir,
53
+ console_output=False # Only file output for testing
54
+ )
55
+
56
+ test_message = "Test log message"
57
+ logger.info(test_message)
58
+
59
+ # Force flush to ensure file is written
60
+ for handler in logger.get_logger().handlers:
61
+ if hasattr(handler, 'flush'):
62
+ handler.flush()
63
+
64
+ log_file = Path(self.temp_dir) / "logs" / f"{self.test_name}.log"
65
+ with open(log_file, 'r') as f:
66
+ content = f.read()
67
+
68
+ self.assertIn(test_message, content)
69
+ self.assertIn("INFO", content)
70
+
71
+ def test_different_log_levels(self):
72
+ """Test different logging levels."""
73
+ logger = FastLogger(
74
+ name=self.test_name,
75
+ base_path=self.temp_dir,
76
+ level=logging.DEBUG,
77
+ console_output=False
78
+ )
79
+
80
+ logger.debug("Debug message")
81
+ logger.info("Info message")
82
+ logger.warning("Warning message")
83
+ logger.error("Error message")
84
+ logger.critical("Critical message")
85
+
86
+ # Force flush to ensure file is written
87
+ for handler in logger.get_logger().handlers:
88
+ if hasattr(handler, 'flush'):
89
+ handler.flush()
90
+
91
+ log_file = Path(self.temp_dir) / "logs" / f"{self.test_name}.log"
92
+ with open(log_file, 'r') as f:
93
+ content = f.read()
94
+
95
+ self.assertIn("DEBUG", content)
96
+ self.assertIn("INFO", content)
97
+ self.assertIn("WARNING", content)
98
+ self.assertIn("ERROR", content)
99
+ self.assertIn("CRITICAL", content)
100
+
101
+ def test_string_level_parsing(self):
102
+ """Test string level parsing."""
103
+ logger = FastLogger(
104
+ name=self.test_name,
105
+ base_path=self.temp_dir,
106
+ level="DEBUG"
107
+ )
108
+
109
+ self.assertEqual(logger.level, logging.DEBUG)
110
+
111
+ logger = FastLogger(
112
+ name=self.test_name + "2",
113
+ base_path=self.temp_dir,
114
+ level="warning"
115
+ )
116
+
117
+ self.assertEqual(logger.level, logging.WARNING)
118
+
119
+ def test_custom_log_folder(self):
120
+ """Test custom log folder."""
121
+ custom_folder = "custom_logs"
122
+ logger = FastLogger(
123
+ name=self.test_name,
124
+ base_path=self.temp_dir,
125
+ log_folder=custom_folder
126
+ )
127
+
128
+ logger.info("Test message")
129
+
130
+ # Force flush to ensure file is written
131
+ for handler in logger.get_logger().handlers:
132
+ if hasattr(handler, 'flush'):
133
+ handler.flush()
134
+
135
+ log_file = Path(self.temp_dir) / custom_folder / f"{self.test_name}.log"
136
+ self.assertTrue(log_file.exists())
137
+
138
+ def test_quick_logger_function(self):
139
+ """Test quick_logger convenience function."""
140
+ with tempfile.TemporaryDirectory() as temp_dir:
141
+ # This is tricky to test since quick_logger uses caller's directory
142
+ # We'll just test that it returns a logger
143
+ logger = quick_logger(self.test_name)
144
+ self.assertIsInstance(logger, logging.Logger)
145
+ self.assertEqual(logger.name, self.test_name)
146
+
147
+ def test_get_logger_function(self):
148
+ """Test get_logger convenience function."""
149
+ logger = get_logger(self.test_name, base_path=self.temp_dir)
150
+ self.assertIsInstance(logger, FastLogger)
151
+ self.assertEqual(logger.name, self.test_name)
152
+
153
+ def test_setup_logger_function(self):
154
+ """Test setup_logger convenience function."""
155
+ logger = setup_logger(self.test_name, base_path=self.temp_dir)
156
+ self.assertIsInstance(logger, logging.Logger)
157
+ self.assertEqual(logger.name, self.test_name)
158
+
159
+ def test_no_duplicate_handlers(self):
160
+ """Test that creating the same logger twice doesn't duplicate handlers."""
161
+ logger1 = FastLogger(name=self.test_name, base_path=self.temp_dir)
162
+ initial_handler_count = len(logger1.get_logger().handlers)
163
+
164
+ logger2 = FastLogger(name=self.test_name, base_path=self.temp_dir)
165
+ final_handler_count = len(logger2.get_logger().handlers)
166
+
167
+ self.assertEqual(initial_handler_count, final_handler_count)
168
+
169
+ def test_console_output_disabled(self):
170
+ """Test logger with console output disabled."""
171
+ logger = FastLogger(
172
+ name=self.test_name,
173
+ base_path=self.temp_dir,
174
+ console_output=False
175
+ )
176
+
177
+ # Should have only file handler
178
+ handlers = logger.get_logger().handlers
179
+ self.assertEqual(len(handlers), 1)
180
+ self.assertTrue(any(handler.__class__.__name__ == 'RotatingFileHandler'
181
+ for handler in handlers))
182
+
183
+ def test_custom_format(self):
184
+ """Test custom log format."""
185
+ custom_format = "%(levelname)s: %(message)s"
186
+ logger = FastLogger(
187
+ name=self.test_name,
188
+ base_path=self.temp_dir,
189
+ log_format=custom_format,
190
+ console_output=False
191
+ )
192
+
193
+ logger.info("Test message")
194
+
195
+ # Force flush to ensure file is written
196
+ for handler in logger.get_logger().handlers:
197
+ if hasattr(handler, 'flush'):
198
+ handler.flush()
199
+
200
+ log_file = Path(self.temp_dir) / "logs" / f"{self.test_name}.log"
201
+ with open(log_file, 'r') as f:
202
+ content = f.read().strip()
203
+
204
+ # Should match our custom format
205
+ self.assertTrue(content.startswith("INFO: Test message"))
206
+
207
+
208
+ if __name__ == '__main__':
209
+ unittest.main()