devsetgo-lib 0.13.0__tar.gz → 0.13.2__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.
Files changed (24) hide show
  1. {devsetgo_lib-0.13.0 → devsetgo_lib-0.13.2}/PKG-INFO +62 -52
  2. devsetgo_lib-0.13.2/README.md +117 -0
  3. {devsetgo_lib-0.13.0 → devsetgo_lib-0.13.2}/dsg_lib/__init__.py +1 -1
  4. {devsetgo_lib-0.13.0 → devsetgo_lib-0.13.2}/dsg_lib/common_functions/logging_config.py +91 -26
  5. {devsetgo_lib-0.13.0 → devsetgo_lib-0.13.2}/pyproject.toml +4 -4
  6. devsetgo_lib-0.13.0/README.md +0 -107
  7. {devsetgo_lib-0.13.0 → devsetgo_lib-0.13.2}/.gitignore +0 -0
  8. {devsetgo_lib-0.13.0 → devsetgo_lib-0.13.2}/LICENSE +0 -0
  9. {devsetgo_lib-0.13.0 → devsetgo_lib-0.13.2}/dsg_lib/async_database_functions/__import_sqlalchemy.py +0 -0
  10. {devsetgo_lib-0.13.0 → devsetgo_lib-0.13.2}/dsg_lib/async_database_functions/__init__.py +0 -0
  11. {devsetgo_lib-0.13.0 → devsetgo_lib-0.13.2}/dsg_lib/async_database_functions/async_database.py +0 -0
  12. {devsetgo_lib-0.13.0 → devsetgo_lib-0.13.2}/dsg_lib/async_database_functions/base_schema.py +0 -0
  13. {devsetgo_lib-0.13.0 → devsetgo_lib-0.13.2}/dsg_lib/async_database_functions/database_config.py +0 -0
  14. {devsetgo_lib-0.13.0 → devsetgo_lib-0.13.2}/dsg_lib/async_database_functions/database_operations.py +0 -0
  15. {devsetgo_lib-0.13.0 → devsetgo_lib-0.13.2}/dsg_lib/common_functions/__init__.py +0 -0
  16. {devsetgo_lib-0.13.0 → devsetgo_lib-0.13.2}/dsg_lib/common_functions/calendar_functions.py +0 -0
  17. {devsetgo_lib-0.13.0 → devsetgo_lib-0.13.2}/dsg_lib/common_functions/email_validation.py +0 -0
  18. {devsetgo_lib-0.13.0 → devsetgo_lib-0.13.2}/dsg_lib/common_functions/file_functions.py +0 -0
  19. {devsetgo_lib-0.13.0 → devsetgo_lib-0.13.2}/dsg_lib/common_functions/folder_functions.py +0 -0
  20. {devsetgo_lib-0.13.0 → devsetgo_lib-0.13.2}/dsg_lib/common_functions/patterns.py +0 -0
  21. {devsetgo_lib-0.13.0 → devsetgo_lib-0.13.2}/dsg_lib/fastapi_functions/__init__.py +0 -0
  22. {devsetgo_lib-0.13.0 → devsetgo_lib-0.13.2}/dsg_lib/fastapi_functions/_all_codes.py +0 -0
  23. {devsetgo_lib-0.13.0 → devsetgo_lib-0.13.2}/dsg_lib/fastapi_functions/http_codes.py +0 -0
  24. {devsetgo_lib-0.13.0 → devsetgo_lib-0.13.2}/dsg_lib/fastapi_functions/system_health_endpoints.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: devsetgo_lib
3
- Version: 0.13.0
3
+ Version: 0.13.2
4
4
  Summary: DevSetGo Library is a Python library offering reusable functions for efficient coding. It includes file operations, calendar utilities, pattern matching, advanced logging with loguru, FastAPI endpoints, async database handling, and email validation. Designed for ease of use and versatility, it's a valuable tool for Python developers.
5
5
  Project-URL: Homepage, https://github.com/devsetgo/devsetgo_lib
6
6
  Project-URL: Documentation, https://devsetgo.github.io/devsetgo_lib/
@@ -82,78 +82,60 @@ Support Python Versions
82
82
  ![Static Badge](https://img.shields.io/badge/Python-3.12%20%7C%203.11%20%7C%203.10%20%7C%203.9-blue)
83
83
  [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
84
84
 
85
-
86
85
  CI/CD Pipeline:
87
86
 
88
87
  [![Testing - Main](https://github.com/devsetgo/devsetgo_lib/actions/workflows/testing.yml/badge.svg?branch=main)](https://github.com/devsetgo/devsetgo_lib/actions/workflows/testing.yml)
89
88
  [![Testing - Dev](https://github.com/devsetgo/devsetgo_lib/actions/workflows/testing.yml/badge.svg?branch=dev)](https://github.com/devsetgo/devsetgo_lib/actions/workflows/testing.yml)
90
- [![Coverage fury.io](coverage-badge.svg)](https://github.com/devsetgo/dsg_lib)
91
89
 
92
90
  SonarCloud:
93
91
 
94
92
  [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=devsetgo_devsetgo_lib&metric=coverage)](https://sonarcloud.io/dashboard?id=devsetgo_devsetgo_lib)
95
93
  [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=devsetgo_devsetgo_lib&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=devsetgo_devsetgo_lib)
96
94
  [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=devsetgo_devsetgo_lib&metric=alert_status)](https://sonarcloud.io/dashboard?id=devsetgo_devsetgo_lib)
97
-
98
95
  [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=devsetgo_devsetgo_lib&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=devsetgo_devsetgo_lib)
99
96
  [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=devsetgo_devsetgo_lib&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=devsetgo_devsetgo_lib)
100
97
 
101
- ![Static Badge](https://img.shields.io/badge/Documentation-v0.12.2-blue?link=https%3A%2F%2Fdevsetgo.github.io%2Fdevsetgo_lib)
102
98
 
103
99
 
104
100
  # DevSetGo Common Library
105
101
 
106
- ## Introduction
107
- The DevSetGo Common Library is a comprehensive package of common functions designed to eliminate repetitive coding and enhance code reusability. It aims to save developers time and effort across various projects.
108
-
109
- ## Compatibility and Testing
110
- - **Tested on**: Windows, Linux.
111
- - **Compatibility**: Potentially compatible with MacOS (feedback on issues is appreciated).
112
-
113
- ## Library Functions
114
- ### Common Functions
115
- - **File Functions**:
116
- - CSV File Functions
117
- - JSON File Functions
118
- - Text File Functions
119
- - **Folder Functions**:
120
- - Make Directory
121
- - Remove Directory
122
- - Last File Changed
123
- - Directory List
124
- - **Calendar Functions**:
125
- - Get Month
126
- - Get Month Number
127
- - **Patterns**:
128
- - Pattern Between Two Characters
102
+ `devsetgo_lib` is a versatile library designed to provide common functions for Python applications. Its main goal is to increase reusability and reduce the need to rewrite the same functions across multiple applications. This also allows for quick defect resolution and propagation of fixes across all dependent projects.
103
+
104
+ ## Key Features
105
+
106
+ - **File Operations**:
107
+ - **CSV, JSON, and Text File Functions**: Create, read, write, and manipulate various file types with ease.
108
+ - **Folder Functions**: Create and remove directories, list directory contents, and manage file system operations efficiently.
109
+
129
110
  - **Logging**:
130
- - Logging configuration and interceptor
111
+ - Comprehensive logging setup using the `loguru` library. Provides extensive customization options for log configuration, including log rotation, retention, and formatting.
112
+
113
+ - **Calendar Functions**:
114
+ - Convert between month names and numbers seamlessly.
131
115
 
132
- ### FastAPI Endpoints
133
- - **Systems Health Endpoints**:
134
- - Status/Health, Heapdump, Uptime
135
- - **HTTP Codes**:
136
- - Method to generate HTTP response codes
116
+ - **Pattern Matching**:
117
+ - Powerful tools for searching patterns in text using regular expressions.
137
118
 
138
- ### Async Database
139
- - Database Config
140
- - Async Session
141
- - CRUD Operations
119
+ - **FastAPI Endpoints**:
120
+ - Pre-built endpoints for system health checks, status, and uptime monitoring.
121
+ - Functions to generate HTTP response codes easily.
142
122
 
143
- ## Examples and Usage
144
- Refer to the [Recipes Pages](https://devsetgo.github.io/devsetgo_lib/recipes/fastapi/)
123
+ - **Async Database**:
124
+ - Configuration and management of asynchronous database sessions.
125
+ - CRUD operations with async support.
145
126
 
146
- ## Installation Guide
147
- [Quick Start](https://devsetgo.github.io/devsetgo_lib/quickstart/)
127
+ ## Installation
148
128
 
149
- ```python
129
+ To install `devsetgo_lib`, use pip:
130
+
131
+ ```sh
150
132
  pip install devsetgo-lib
151
133
 
152
- # Aysync database setup
134
+ # For async database setup with SQLite or PostgreSQL
153
135
  pip install devsetgo-lib[sqlite]
154
136
  pip install devsetgo-lib[postgres]
155
137
 
156
- # Consider these experimental and untested
138
+ # Experimental support for other databases
157
139
  pip install devsetgo-lib[oracle]
158
140
  pip install devsetgo-lib[mssql]
159
141
  pip install devsetgo-lib[mysql]
@@ -165,15 +147,43 @@ pip install devsetgo-lib[fastapi]
165
147
  pip install devsetgo-lib[all]
166
148
  ```
167
149
 
150
+ ## Usage
151
+
152
+ Here's a quick example to demonstrate how you can use some of the key features of `devsetgo_lib`:
153
+
154
+ ```python
155
+ from devsetgo_lib import file_functions, logging_config, patterns, calendar_functions
156
+
157
+ # File Operations
158
+ file_functions.create_sample_files("example", 100)
159
+ content = file_functions.read_from_file("example.csv")
160
+ print(content)
161
+
162
+ # Logging
163
+ logging_config.config_log(logging_directory='logs', log_name='app.log', logging_level='DEBUG')
164
+ logger = logging.getLogger('app_logger')
165
+ logger.info("This is an info message")
166
+
167
+ # Pattern Matching
168
+ text = "Hello, my name is 'John Doe' and I live in 'New York'."
169
+ results = patterns.pattern_between_two_char(text, "'", "'")
170
+ print(results)
171
+
172
+ # Calendar Functions
173
+ print(calendar_functions.get_month(1)) # Output: 'January'
174
+ print(calendar_functions.get_month_number('January')) # Output: 1
175
+ ```
176
+
177
+ For detailed documentation on each module and function, please refer to the [official documentation](https://devsetgo.github.io/devsetgo_lib/print_page/).
168
178
 
169
- ## Contribution and Feedback
170
- Contributions and feedback are highly appreciated. Please refer to our [Contribution Guidelines](https://github.com/devsetgo/devsetgo_lib/blob/main/CONTRIBUTING.md).
179
+ ## Contributing
180
+
181
+ We welcome contributions! Please see our [contributing guidelines](CONTRIBUTING.md) for more details.
171
182
 
172
183
  ## License
173
- [MIT Licensed](https://github.com/devsetgo/devsetgo_lib/blob/main/LICENSE)
174
184
 
175
- ## Author Information
176
- [Mike Ryan](https://github.com/devsetgo)
185
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
186
+
187
+ ## Contact
177
188
 
178
- ## Further Documentation
179
- For more detailed information, visit [LINK_TO_DETAILED_DOCUMENTATION](https://devsetgo.github.io/devsetgo_lib/).
189
+ For any questions or issues, please open an issue on GitHub or contact us at [devsetgo@example.com](mailto:devsetgo@example.com).
@@ -0,0 +1,117 @@
1
+ Python:
2
+
3
+ [![PyPI version fury.io](https://badge.fury.io/py/devsetgo-lib.svg)](https://pypi.python.org/pypi/devsetgo-lib/)
4
+ [![Downloads](https://static.pepy.tech/badge/devsetgo-lib)](https://pepy.tech/project/devsetgo-lib)
5
+ [![Downloads](https://static.pepy.tech/badge/devsetgo-lib/month)](https://pepy.tech/project/devsetgo-lib)
6
+ [![Downloads](https://static.pepy.tech/badge/devsetgo-lib/week)](https://pepy.tech/project/devsetgo-lib)
7
+
8
+ Support Python Versions
9
+
10
+ ![Static Badge](https://img.shields.io/badge/Python-3.12%20%7C%203.11%20%7C%203.10%20%7C%203.9-blue)
11
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
12
+
13
+ CI/CD Pipeline:
14
+
15
+ [![Testing - Main](https://github.com/devsetgo/devsetgo_lib/actions/workflows/testing.yml/badge.svg?branch=main)](https://github.com/devsetgo/devsetgo_lib/actions/workflows/testing.yml)
16
+ [![Testing - Dev](https://github.com/devsetgo/devsetgo_lib/actions/workflows/testing.yml/badge.svg?branch=dev)](https://github.com/devsetgo/devsetgo_lib/actions/workflows/testing.yml)
17
+
18
+ SonarCloud:
19
+
20
+ [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=devsetgo_devsetgo_lib&metric=coverage)](https://sonarcloud.io/dashboard?id=devsetgo_devsetgo_lib)
21
+ [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=devsetgo_devsetgo_lib&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=devsetgo_devsetgo_lib)
22
+ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=devsetgo_devsetgo_lib&metric=alert_status)](https://sonarcloud.io/dashboard?id=devsetgo_devsetgo_lib)
23
+ [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=devsetgo_devsetgo_lib&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=devsetgo_devsetgo_lib)
24
+ [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=devsetgo_devsetgo_lib&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=devsetgo_devsetgo_lib)
25
+
26
+
27
+
28
+ # DevSetGo Common Library
29
+
30
+ `devsetgo_lib` is a versatile library designed to provide common functions for Python applications. Its main goal is to increase reusability and reduce the need to rewrite the same functions across multiple applications. This also allows for quick defect resolution and propagation of fixes across all dependent projects.
31
+
32
+ ## Key Features
33
+
34
+ - **File Operations**:
35
+ - **CSV, JSON, and Text File Functions**: Create, read, write, and manipulate various file types with ease.
36
+ - **Folder Functions**: Create and remove directories, list directory contents, and manage file system operations efficiently.
37
+
38
+ - **Logging**:
39
+ - Comprehensive logging setup using the `loguru` library. Provides extensive customization options for log configuration, including log rotation, retention, and formatting.
40
+
41
+ - **Calendar Functions**:
42
+ - Convert between month names and numbers seamlessly.
43
+
44
+ - **Pattern Matching**:
45
+ - Powerful tools for searching patterns in text using regular expressions.
46
+
47
+ - **FastAPI Endpoints**:
48
+ - Pre-built endpoints for system health checks, status, and uptime monitoring.
49
+ - Functions to generate HTTP response codes easily.
50
+
51
+ - **Async Database**:
52
+ - Configuration and management of asynchronous database sessions.
53
+ - CRUD operations with async support.
54
+
55
+ ## Installation
56
+
57
+ To install `devsetgo_lib`, use pip:
58
+
59
+ ```sh
60
+ pip install devsetgo-lib
61
+
62
+ # For async database setup with SQLite or PostgreSQL
63
+ pip install devsetgo-lib[sqlite]
64
+ pip install devsetgo-lib[postgres]
65
+
66
+ # Experimental support for other databases
67
+ pip install devsetgo-lib[oracle]
68
+ pip install devsetgo-lib[mssql]
69
+ pip install devsetgo-lib[mysql]
70
+
71
+ # For adding FastAPI endpoints
72
+ pip install devsetgo-lib[fastapi]
73
+
74
+ # Install everything
75
+ pip install devsetgo-lib[all]
76
+ ```
77
+
78
+ ## Usage
79
+
80
+ Here's a quick example to demonstrate how you can use some of the key features of `devsetgo_lib`:
81
+
82
+ ```python
83
+ from devsetgo_lib import file_functions, logging_config, patterns, calendar_functions
84
+
85
+ # File Operations
86
+ file_functions.create_sample_files("example", 100)
87
+ content = file_functions.read_from_file("example.csv")
88
+ print(content)
89
+
90
+ # Logging
91
+ logging_config.config_log(logging_directory='logs', log_name='app.log', logging_level='DEBUG')
92
+ logger = logging.getLogger('app_logger')
93
+ logger.info("This is an info message")
94
+
95
+ # Pattern Matching
96
+ text = "Hello, my name is 'John Doe' and I live in 'New York'."
97
+ results = patterns.pattern_between_two_char(text, "'", "'")
98
+ print(results)
99
+
100
+ # Calendar Functions
101
+ print(calendar_functions.get_month(1)) # Output: 'January'
102
+ print(calendar_functions.get_month_number('January')) # Output: 1
103
+ ```
104
+
105
+ For detailed documentation on each module and function, please refer to the [official documentation](https://devsetgo.github.io/devsetgo_lib/print_page/).
106
+
107
+ ## Contributing
108
+
109
+ We welcome contributions! Please see our [contributing guidelines](CONTRIBUTING.md) for more details.
110
+
111
+ ## License
112
+
113
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
114
+
115
+ ## Contact
116
+
117
+ For any questions or issues, please open an issue on GitHub or contact us at [devsetgo@example.com](mailto:devsetgo@example.com).
@@ -1,3 +1,3 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- __version__ = '0.13.0'
3
+ __version__ = '0.13.2'
@@ -1,29 +1,22 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  """
3
- This module provides a function to configure and set up a logger using the loguru package.
3
+ This module provides a comprehensive logging setup using the loguru library, facilitating easy logging management for Python applications. The `config_log` function, central to this module, allows for extensive customization of logging behavior. It supports specifying the logging directory, log file name, logging level, and controls for log rotation, retention, and formatting among other features. Additionally, it offers advanced options like backtrace and diagnose for in-depth debugging, and the ability to append the application name to the log file for clearer identification.
4
4
 
5
- The `config_log` function takes several optional parameters to customize the logger's behavior,
6
- including the logging directory, log name, logging level, log rotation size, log retention period,
7
- and more. It also provides an option to append the application name to the log file name.
5
+ Usage example:
8
6
 
9
- Example:
10
7
  ```python
11
8
  from dsg_lib.common_functions.logging_config import config_log
12
9
 
13
10
  config_log(
14
- logging_directory='logs', # Directory where logs will be stored
15
- log_name='log', # Name of the log file (extension will be added automatically set v0.12.2)
16
- logging_level='DEBUG', # Logging level
17
- log_rotation='100 MB', # Log rotation size
18
- log_retention='30 days', # Log retention period
19
- log_backtrace=True, # Enable backtrace
20
- log_format="<green>{time:YYYY-MM-DD HH:mm:ss.SSSSSS}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>", # Log format
21
- log_serializer=False, # Disable log serialization
22
- log_diagnose=True, # Enable diagnose
23
- app_name='my_app', # Application name
24
- append_app_name=True # Append application name to the log file name
11
+ logging_directory='logs', # Directory for storing logs
12
+ log_name='log', # Base name for log files
13
+ logging_level='DEBUG', # Minimum logging level
14
+ log_rotation='100 MB', # Size threshold for log rotation
15
+ log_retention='30 days', # Duration to retain old log files
16
+ enqueue=True, # Enqueue log messages
25
17
  )
26
18
 
19
+ # Example log messages
27
20
  logger.debug("This is a debug message")
28
21
  logger.info("This is an info message")
29
22
  logger.error("This is an error message")
@@ -32,10 +25,12 @@ logger.critical("This is a critical message")
32
25
  ```
33
26
 
34
27
  Author: Mike Ryan
35
- Date: 2024/05/16
28
+ DateCreated: 2021/07/16
29
+ DateUpdated: 2024/07/24
30
+
36
31
  License: MIT
37
32
  """
38
-
33
+ import time
39
34
  import logging
40
35
  from pathlib import Path
41
36
  from uuid import uuid4
@@ -55,6 +50,9 @@ def config_log(
55
50
  log_diagnose: bool = False,
56
51
  app_name: str = None,
57
52
  append_app_name: bool = False,
53
+ enqueue: bool = True,
54
+ intercept_standard_logging: bool = True,
55
+ file_sink: bool = True,
58
56
  ):
59
57
  """
60
58
  Configures and sets up a logger using the loguru package.
@@ -71,6 +69,9 @@ def config_log(
71
69
  - log_diagnose (bool): Whether to enable diagnose. Default is False.
72
70
  - app_name (str): The application name. Default is None.
73
71
  - append_app_name (bool): Whether to append the application name to the log file name. Default is False.
72
+ - enqueue (bool): Whether to enqueue log messages. Default is True.
73
+ - intercept_standard_logging (bool): Whether to intercept standard logging. Default is True.
74
+ - file_sink (bool): Whether to use a file sink. Default is True.
74
75
 
75
76
  Raises:
76
77
  - ValueError: If the provided logging level is not valid.
@@ -83,14 +84,17 @@ def config_log(
83
84
  logging_directory='logs',
84
85
  log_name='app.log',
85
86
  logging_level='DEBUG',
86
- log_rotation='500 MB',
87
+ log_rotation='100 MB',
87
88
  log_retention='10 days',
88
89
  log_backtrace=True,
89
90
  log_format="<green>{time:YYYY-MM-DD HH:mm:ss.SSSSSS}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>",
90
91
  log_serializer=False,
91
92
  log_diagnose=True,
92
93
  app_name='my_app',
93
- append_app_name=True
94
+ append_app_name=True,
95
+ enqueue=True,
96
+ intercept_standard_logging=True,
97
+ file_sink=True
94
98
  )
95
99
  ```
96
100
  """
@@ -108,6 +112,7 @@ def config_log(
108
112
  log_format = '<green>{time:YYYY-MM-DD HH:mm:ss.SSSSSS}</green> | <level>{level: <8}</level> | <cyan> {name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>' # pragma: no cover
109
113
 
110
114
  if log_serializer is True:
115
+ log_format = '{message}' # pragma: no cover
111
116
  log_name = f'{log_name}.json' # pragma: no cover
112
117
  else:
113
118
  log_name = f'{log_name}.log' # pragma: no cover
@@ -140,7 +145,7 @@ def config_log(
140
145
  log_path,
141
146
  level=logging_level.upper(),
142
147
  format=log_format,
143
- enqueue=True,
148
+ enqueue=enqueue,
144
149
  backtrace=log_backtrace,
145
150
  rotation=log_rotation,
146
151
  retention=log_retention,
@@ -149,6 +154,8 @@ def config_log(
149
154
  diagnose=log_diagnose,
150
155
  )
151
156
 
157
+ basic_config_handlers:list = []
158
+
152
159
  class InterceptHandler(logging.Handler):
153
160
  """
154
161
  Interceptor for standard logging.
@@ -194,12 +201,70 @@ def config_log(
194
201
  level, record.getMessage()
195
202
  ) # pragma: no cover
196
203
 
197
- # Configure standard logging to use interceptor handler
198
- logging.basicConfig(handlers=[InterceptHandler()], level=logging_level.upper())
199
204
 
200
- # Add interceptor handler to all existing loggers
201
- for name in logging.root.manager.loggerDict:
202
- logging.getLogger(name).addHandler(InterceptHandler())
205
+ if intercept_standard_logging:
206
+ # Add interceptor handler to all existing loggers
207
+ for name in logging.root.manager.loggerDict:
208
+ logging.getLogger(name).addHandler(InterceptHandler())
209
+
210
+ # Add interceptor handler to the root logger
211
+ basic_config_handlers.append(InterceptHandler())
203
212
 
204
213
  # Set the root logger's level to the lowest level possible
205
214
  logging.getLogger().setLevel(logging.NOTSET)
215
+
216
+
217
+ class ResilientFileSink:
218
+ """
219
+ A file sink designed for resilience, capable of retrying write operations.
220
+
221
+ This class implements a resilient file writing mechanism that attempts to write messages to a file, retrying the operation a specified number of times if it fails. This is particularly useful in scenarios where write operations might intermittently fail due to temporary issues such as file system locks or networked file system delays.
222
+
223
+ Attributes:
224
+ path (str): The path to the file where messages will be written.
225
+ max_retries (int): The maximum number of retry attempts for a failed write operation.
226
+ retry_delay (float): The delay between retry attempts, in seconds.
227
+
228
+ Methods:
229
+ write(message): Attempts to write a message to the file, retrying on failure up to `max_retries` times.
230
+ """
231
+ def __init__(self, path, max_retries=3, retry_delay=1.0, formatter=None):
232
+ self.path = path
233
+ self.max_retries = max_retries
234
+ self.retry_delay = retry_delay
235
+ self._formatter = formatter or logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
236
+
237
+ @property
238
+ def formatter(self):
239
+ return self._formatter
240
+
241
+ @formatter.setter
242
+ def formatter(self, value):
243
+ self._formatter = value
244
+
245
+ def write(self, message):
246
+ for attempt in range(self.max_retries):
247
+ try:
248
+ with open(self.path, 'a') as file:
249
+ formatted_message = self.formatter.format(message) if self._formatter else message
250
+ file.write(formatted_message + '\n') # Ensure newline
251
+ break # Successfully written, break the loop
252
+ except FileNotFoundError:
253
+ if attempt < self.max_retries - 1:
254
+ time.sleep(self.retry_delay) # Wait before retrying
255
+ else:
256
+ raise # Reraise if max retries exceeded
257
+
258
+
259
+ if file_sink:
260
+ # Create an instance of ResilientFileSink
261
+ resilient_sink = ResilientFileSink(str(log_path))
262
+
263
+ # Configure the logger to use the ResilientFileSink
264
+ basic_config_handlers.append(resilient_sink)
265
+
266
+ if intercept_standard_logging:
267
+ basic_config_handlers.append(InterceptHandler())
268
+
269
+ if len(basic_config_handlers) > 0:
270
+ logging.basicConfig(handlers=basic_config_handlers, level=logging_level.upper())
@@ -8,7 +8,7 @@ build-backend = "hatchling.build"
8
8
 
9
9
  [project]
10
10
  name = "devsetgo_lib"
11
- version = "0.13.0"
11
+ version = "0.13.2"
12
12
  requires-python = ">=3.9"
13
13
  description = """
14
14
  DevSetGo Library is a Python library offering reusable functions for efficient coding. It includes file operations, calendar utilities, pattern matching, advanced logging with loguru, FastAPI endpoints, async database handling, and email validation. Designed for ease of use and versatility, it's a valuable tool for Python developers.
@@ -116,9 +116,9 @@ quote-style = "single"
116
116
 
117
117
 
118
118
  [tool.flake8]
119
- max-line-length = 132
120
- max-doc-length = 132
121
- ignore = ["E302","E501"]
119
+ max-line-length = 100
120
+ max-doc-length = 100
121
+ ignore = ["E302", "E501","E303"] # Keeping the ignores the same as before since ruff's specific ignores aren't directly transferable
122
122
  exclude = [
123
123
  ".git",
124
124
  "__pycache__",
@@ -1,107 +0,0 @@
1
- Python:
2
-
3
- [![PyPI version fury.io](https://badge.fury.io/py/devsetgo-lib.svg)](https://pypi.python.org/pypi/devsetgo-lib/)
4
- [![Downloads](https://static.pepy.tech/badge/devsetgo-lib)](https://pepy.tech/project/devsetgo-lib)
5
- [![Downloads](https://static.pepy.tech/badge/devsetgo-lib/month)](https://pepy.tech/project/devsetgo-lib)
6
- [![Downloads](https://static.pepy.tech/badge/devsetgo-lib/week)](https://pepy.tech/project/devsetgo-lib)
7
-
8
- Support Python Versions
9
-
10
- ![Static Badge](https://img.shields.io/badge/Python-3.12%20%7C%203.11%20%7C%203.10%20%7C%203.9-blue)
11
- [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
12
-
13
-
14
- CI/CD Pipeline:
15
-
16
- [![Testing - Main](https://github.com/devsetgo/devsetgo_lib/actions/workflows/testing.yml/badge.svg?branch=main)](https://github.com/devsetgo/devsetgo_lib/actions/workflows/testing.yml)
17
- [![Testing - Dev](https://github.com/devsetgo/devsetgo_lib/actions/workflows/testing.yml/badge.svg?branch=dev)](https://github.com/devsetgo/devsetgo_lib/actions/workflows/testing.yml)
18
- [![Coverage fury.io](coverage-badge.svg)](https://github.com/devsetgo/dsg_lib)
19
-
20
- SonarCloud:
21
-
22
- [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=devsetgo_devsetgo_lib&metric=coverage)](https://sonarcloud.io/dashboard?id=devsetgo_devsetgo_lib)
23
- [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=devsetgo_devsetgo_lib&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=devsetgo_devsetgo_lib)
24
- [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=devsetgo_devsetgo_lib&metric=alert_status)](https://sonarcloud.io/dashboard?id=devsetgo_devsetgo_lib)
25
-
26
- [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=devsetgo_devsetgo_lib&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=devsetgo_devsetgo_lib)
27
- [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=devsetgo_devsetgo_lib&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=devsetgo_devsetgo_lib)
28
-
29
- ![Static Badge](https://img.shields.io/badge/Documentation-v0.12.2-blue?link=https%3A%2F%2Fdevsetgo.github.io%2Fdevsetgo_lib)
30
-
31
-
32
- # DevSetGo Common Library
33
-
34
- ## Introduction
35
- The DevSetGo Common Library is a comprehensive package of common functions designed to eliminate repetitive coding and enhance code reusability. It aims to save developers time and effort across various projects.
36
-
37
- ## Compatibility and Testing
38
- - **Tested on**: Windows, Linux.
39
- - **Compatibility**: Potentially compatible with MacOS (feedback on issues is appreciated).
40
-
41
- ## Library Functions
42
- ### Common Functions
43
- - **File Functions**:
44
- - CSV File Functions
45
- - JSON File Functions
46
- - Text File Functions
47
- - **Folder Functions**:
48
- - Make Directory
49
- - Remove Directory
50
- - Last File Changed
51
- - Directory List
52
- - **Calendar Functions**:
53
- - Get Month
54
- - Get Month Number
55
- - **Patterns**:
56
- - Pattern Between Two Characters
57
- - **Logging**:
58
- - Logging configuration and interceptor
59
-
60
- ### FastAPI Endpoints
61
- - **Systems Health Endpoints**:
62
- - Status/Health, Heapdump, Uptime
63
- - **HTTP Codes**:
64
- - Method to generate HTTP response codes
65
-
66
- ### Async Database
67
- - Database Config
68
- - Async Session
69
- - CRUD Operations
70
-
71
- ## Examples and Usage
72
- Refer to the [Recipes Pages](https://devsetgo.github.io/devsetgo_lib/recipes/fastapi/)
73
-
74
- ## Installation Guide
75
- [Quick Start](https://devsetgo.github.io/devsetgo_lib/quickstart/)
76
-
77
- ```python
78
- pip install devsetgo-lib
79
-
80
- # Aysync database setup
81
- pip install devsetgo-lib[sqlite]
82
- pip install devsetgo-lib[postgres]
83
-
84
- # Consider these experimental and untested
85
- pip install devsetgo-lib[oracle]
86
- pip install devsetgo-lib[mssql]
87
- pip install devsetgo-lib[mysql]
88
-
89
- # For adding FastAPI endpoints
90
- pip install devsetgo-lib[fastapi]
91
-
92
- # Install everything
93
- pip install devsetgo-lib[all]
94
- ```
95
-
96
-
97
- ## Contribution and Feedback
98
- Contributions and feedback are highly appreciated. Please refer to our [Contribution Guidelines](https://github.com/devsetgo/devsetgo_lib/blob/main/CONTRIBUTING.md).
99
-
100
- ## License
101
- [MIT Licensed](https://github.com/devsetgo/devsetgo_lib/blob/main/LICENSE)
102
-
103
- ## Author Information
104
- [Mike Ryan](https://github.com/devsetgo)
105
-
106
- ## Further Documentation
107
- For more detailed information, visit [LINK_TO_DETAILED_DOCUMENTATION](https://devsetgo.github.io/devsetgo_lib/).
File without changes
File without changes