python-fast-logger 0.1.0__py3-none-any.whl → 0.1.1__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.
fast_logger/__init__.py CHANGED
@@ -40,4 +40,4 @@ __all__ = [
40
40
  "get_logger",
41
41
  "quick_logger",
42
42
  "__version__",
43
- ]
43
+ ]
fast_logger/core.py CHANGED
@@ -6,21 +6,23 @@ import logging
6
6
  import sys
7
7
  from logging.handlers import RotatingFileHandler
8
8
  from pathlib import Path
9
- from typing import Optional, Union
9
+ from typing import Any, Optional, Union, cast
10
10
 
11
11
 
12
12
  class FastLogger:
13
13
  """A simple logger setup with sensible defaults."""
14
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):
15
+ def __init__(
16
+ self,
17
+ name: str,
18
+ level: Union[int, str] = logging.INFO,
19
+ log_folder: str = "logs",
20
+ max_file_size_mb: int = 50,
21
+ backup_count: int = 3,
22
+ log_format: Optional[str] = None,
23
+ console_output: bool = True,
24
+ base_path: Optional[str] = None,
25
+ ):
24
26
  """
25
27
  Initialize FastLogger with configuration.
26
28
 
@@ -44,11 +46,11 @@ class FastLogger:
44
46
 
45
47
  # Default format
46
48
  self.log_format = log_format or (
47
- '%(asctime)s - %(name)s [%(filename)s:%(lineno)d] - '
48
- '%(levelname)s - %(message)s'
49
+ "%(asctime)s - %(name)s [%(filename)s:%(lineno)d] - "
50
+ "%(levelname)s - %(message)s"
49
51
  )
50
52
 
51
- self._logger = None
53
+ self._logger: Optional[logging.Logger] = None
52
54
  self._setup_logger()
53
55
 
54
56
  @staticmethod
@@ -65,20 +67,28 @@ class FastLogger:
65
67
  else:
66
68
  # Use the directory of the calling script
67
69
  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
70
+
71
+ # Find the first frame outside this module
72
+ current_dir = Path(__file__).parent
73
+ for frame_info in inspect.stack():
74
+ caller_file = Path(frame_info.filename)
75
+ # Skip frames that are internal to fast_logger
76
+ if caller_file.parent != current_dir:
77
+ # Found the caller script
78
+ if caller_file.exists() and caller_file.is_file():
79
+ base = caller_file.parent
80
+ else:
81
+ base = Path.cwd()
82
+ break
83
+ else:
84
+ # Fallback if stack inspection fails
85
+ base = Path.cwd()
76
86
 
77
87
  log_dir = base / self.log_folder
78
88
  log_dir.mkdir(parents=True, exist_ok=True)
79
89
  return log_dir
80
90
 
81
- def _setup_logger(self):
91
+ def _setup_logger(self) -> None:
82
92
  """Set up the logger with file and console handlers."""
83
93
  # Get or create logger
84
94
  self._logger = logging.getLogger(self.name)
@@ -98,7 +108,7 @@ class FastLogger:
98
108
  str(log_file), # Convert Path to string
99
109
  maxBytes=self.max_file_size_mb * 1024 * 1024,
100
110
  backupCount=self.backup_count,
101
- encoding='utf-8'
111
+ encoding="utf-8",
102
112
  )
103
113
  file_handler.setLevel(self.level)
104
114
  file_handler.setFormatter(formatter)
@@ -116,34 +126,41 @@ class FastLogger:
116
126
 
117
127
  def get_logger(self) -> logging.Logger:
118
128
  """Get the configured logger instance."""
129
+ assert self._logger is not None
119
130
  return self._logger
120
131
 
121
- def debug(self, message: str, *args, **kwargs):
132
+ def debug(self, message: str, *args: Any, **kwargs: Any) -> None:
122
133
  """Log a debug message."""
123
- self._logger.debug(message, *args, **kwargs)
134
+ if self._logger:
135
+ self._logger.debug(message, *args, **kwargs)
124
136
 
125
- def info(self, message: str, *args, **kwargs):
137
+ def info(self, message: str, *args: Any, **kwargs: Any) -> None:
126
138
  """Log an info message."""
127
- self._logger.info(message, *args, **kwargs)
139
+ if self._logger:
140
+ self._logger.info(message, *args, **kwargs)
128
141
 
129
- def warning(self, message: str, *args, **kwargs):
142
+ def warning(self, message: str, *args: Any, **kwargs: Any) -> None:
130
143
  """Log a warning message."""
131
- self._logger.warning(message, *args, **kwargs)
144
+ if self._logger:
145
+ self._logger.warning(message, *args, **kwargs)
132
146
 
133
- def error(self, message: str, *args, **kwargs):
147
+ def error(self, message: str, *args: Any, **kwargs: Any) -> None:
134
148
  """Log an error message."""
135
- self._logger.error(message, *args, **kwargs)
149
+ if self._logger:
150
+ self._logger.error(message, *args, **kwargs)
136
151
 
137
- def critical(self, message: str, *args, **kwargs):
152
+ def critical(self, message: str, *args: Any, **kwargs: Any) -> None:
138
153
  """Log a critical message."""
139
- self._logger.critical(message, *args, **kwargs)
154
+ if self._logger:
155
+ self._logger.critical(message, *args, **kwargs)
140
156
 
141
- def exception(self, message: str, *args, **kwargs):
157
+ def exception(self, message: str, *args: Any, **kwargs: Any) -> None:
142
158
  """Log an exception with traceback."""
143
- self._logger.exception(message, *args, **kwargs)
159
+ if self._logger:
160
+ self._logger.exception(message, *args, **kwargs)
144
161
 
145
162
 
146
- def setup_logger(name: str, **kwargs) -> logging.Logger:
163
+ def setup_logger(name: str, **kwargs: Any) -> logging.Logger:
147
164
  """
148
165
  Quick setup function for backward compatibility and convenience.
149
166
 
@@ -158,7 +175,7 @@ def setup_logger(name: str, **kwargs) -> logging.Logger:
158
175
  return fast_logger.get_logger()
159
176
 
160
177
 
161
- def get_logger(name: str, **kwargs) -> FastLogger:
178
+ def get_logger(name: str, **kwargs: Any) -> FastLogger:
162
179
  """
163
180
  Get a FastLogger instance with fluent interface.
164
181
 
@@ -173,7 +190,7 @@ def get_logger(name: str, **kwargs) -> FastLogger:
173
190
 
174
191
 
175
192
  # Convenience function for one-liner setup
176
- def quick_logger(name: str, level: str = 'INFO') -> logging.Logger:
193
+ def quick_logger(name: str, level: str = "INFO") -> logging.Logger:
177
194
  """
178
195
  Super quick logger setup with minimal configuration.
179
196
 
@@ -184,4 +201,4 @@ def quick_logger(name: str, level: str = 'INFO') -> logging.Logger:
184
201
  Returns:
185
202
  Configured logger instance
186
203
  """
187
- return setup_logger(name, level=level)
204
+ return setup_logger(name, level=level)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-fast-logger
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: A simple, no-fuss logging setup for Python applications
5
5
  Author-email: Ravi Mishra <ravi@paisafintech.com>
6
6
  Maintainer-email: Ravi Mishra <ravi@paisafintech.com>
@@ -15,15 +15,13 @@ Classifier: Intended Audience :: Developers
15
15
  Classifier: License :: OSI Approved :: MIT License
16
16
  Classifier: Operating System :: OS Independent
17
17
  Classifier: Programming Language :: Python :: 3
18
- Classifier: Programming Language :: Python :: 3.7
19
- Classifier: Programming Language :: Python :: 3.8
20
18
  Classifier: Programming Language :: Python :: 3.9
21
19
  Classifier: Programming Language :: Python :: 3.10
22
20
  Classifier: Programming Language :: Python :: 3.11
23
21
  Classifier: Programming Language :: Python :: 3.12
24
22
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
25
23
  Classifier: Topic :: System :: Logging
26
- Requires-Python: >=3.7
24
+ Requires-Python: >=3.9
27
25
  Description-Content-Type: text/markdown
28
26
  License-File: LICENSE
29
27
  Provides-Extra: dev
@@ -52,7 +50,7 @@ A simple, no-fuss logging setup for Python applications with sensible defaults.
52
50
  ## Installation
53
51
 
54
52
  ```bash
55
- pip install fast-logger
53
+ pip install python-fast-logger
56
54
  ```
57
55
 
58
56
  ## Quick Start
@@ -216,7 +214,7 @@ logger = quick_logger("my_app")
216
214
 
217
215
  ## Requirements
218
216
 
219
- - Python 3.7+
217
+ - Python 3.9+
220
218
  - No external dependencies
221
219
 
222
220
  ## License
@@ -0,0 +1,7 @@
1
+ fast_logger/__init__.py,sha256=1-ZdRlcBDlrLdqBIH_Bo6IPtKq8vVw9hfURVJL2Tzu0,964
2
+ fast_logger/core.py,sha256=p7s4GrMavmX8oBu0kT1_GgGWwtznNh1At8gpfWPvp5U,6681
3
+ python_fast_logger-0.1.1.dist-info/licenses/LICENSE,sha256=zUSVkLSqRvRAvbhtvLfGSC_Tw1ao2TsxwwvHr05VydQ,1067
4
+ python_fast_logger-0.1.1.dist-info/METADATA,sha256=Yte5ppD7v_yGAnPrVuZUf4Bn8sEoPMjCseeQ1qwDPk0,6056
5
+ python_fast_logger-0.1.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
6
+ python_fast_logger-0.1.1.dist-info/top_level.txt,sha256=c9NyRn7UsQxVnCzh3hCbwdUmz3kH-7-bWODGfANcGsw,12
7
+ python_fast_logger-0.1.1.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- fast_logger/__init__.py,sha256=ZM2ZVkLa8Cp0JUpSJOGEFS4HFSJGcl7lI3YTj0tkUQI,963
2
- fast_logger/core.py,sha256=VUSY4WzIF61mSSem8OCRUPwGhOP0hgGn7_USF0fr9VM,6021
3
- python_fast_logger-0.1.0.dist-info/licenses/LICENSE,sha256=zUSVkLSqRvRAvbhtvLfGSC_Tw1ao2TsxwwvHr05VydQ,1067
4
- python_fast_logger-0.1.0.dist-info/METADATA,sha256=63x7SrKum1vdwoCw7gHNiqom9mgztexFwJrWrAaeq2M,6149
5
- python_fast_logger-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
6
- python_fast_logger-0.1.0.dist-info/top_level.txt,sha256=c9NyRn7UsQxVnCzh3hCbwdUmz3kH-7-bWODGfANcGsw,12
7
- python_fast_logger-0.1.0.dist-info/RECORD,,