logly 0.0.0__tar.gz → 0.0.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.
logly-0.0.2/PKG-INFO ADDED
@@ -0,0 +1,191 @@
1
+ Metadata-Version: 2.1
2
+ Name: logly
3
+ Version: 0.0.2
4
+ Summary: Logly: Python logging utility with color-coded messages and file support. Easily log and trace messages with customizable colors. Simple integration for effective debugging and monitoring.
5
+ Home-page: https://github.com/muhammad-fiaz/logly.git
6
+ Author: Muhammad Fiaz
7
+ Author-email: contact@muhammmadfiaz.com
8
+ License: MIT License
9
+ Project-URL: Source Code, https://github.com/muhammad-fiaz/logly.git
10
+ Project-URL: Bug Tracker, https://github.com/muhammad-fiaz/logly/issues
11
+ Project-URL: Documentation, https://github.com/muhammad-fiaz/logly#readme
12
+ Keywords: log,logging,logly,python
13
+ Platform: UNKNOWN
14
+ Classifier: Development Status :: 1 - Planning
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Operating System :: Unix
19
+ Classifier: Operating System :: MacOS :: MacOS X
20
+ Classifier: Operating System :: Microsoft :: Windows
21
+ Requires-Python: >=3.8
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+
25
+ <div align="center">
26
+
27
+ # Logly
28
+
29
+ [![Run Tests](https://github.com/muhammad-fiaz/logly/actions/workflows/python-package.yaml/badge.svg)](https://github.com/muhammad-fiaz/logly/actions/workflows/python-package.yaml)
30
+ [![PyPI Version](https://img.shields.io/pypi/v/logly)](https://pypi.org/project/logly/)
31
+ [![Python Versions](https://img.shields.io/pypi/pyversions/logly)](https://pypi.org/project/logly/)
32
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
33
+ [![Downloads](https://img.shields.io/pypi/dm/logly)](https://pypi.org/project/logly/)
34
+ [![Last Commit](https://img.shields.io/github/last-commit/muhammad-fiaz/logly)](https://github.com/muhammad-fiaz/logly)
35
+ [![GitHub Issues](https://img.shields.io/github/issues/muhammad-fiaz/logly)](https://github.com/muhammad-fiaz/logly/issues)
36
+ [![GitHub Stars](https://img.shields.io/github/stars/muhammad-fiaz/logly)](https://github.com/muhammad-fiaz/logly/stargazers)
37
+ [![GitHub Forks](https://img.shields.io/github/forks/muhammad-fiaz/logly)](https://github.com/muhammad-fiaz/logly/network)
38
+
39
+ [![Maintainer](https://img.shields.io/badge/Maintainer-muhammad--fiaz-blue)](https://github.com/muhammad-fiaz)
40
+ [![Sponsor on GitHub](https://img.shields.io/badge/Sponsor%20on%20GitHub-Become%20a%20Sponsor-blue)](https://github.com/sponsors/muhammad-fiaz)
41
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
42
+ [![Stability](https://img.shields.io/badge/Stability-Stable-green)](https://github.com/muhammad-fiaz/logly)
43
+
44
+ </div>
45
+
46
+
47
+ Logly is a simple logging utility for Python that provides an easy way to log messages with different levels, colors, and options. It is designed to be flexible, allowing you to customize the log messages based on your application's needs. Logly supports logging to both the console and a file, and it comes with built-in color-coded log levels for better visibility.
48
+
49
+ ## Features
50
+
51
+ - Easy-to-use logging for Python applications.
52
+ - Customizable log levels and formatting.
53
+ - Customizable log colors.
54
+ - Log to file and/or console.
55
+ - Log to file with automatic file rotation.
56
+ - Log to file with automatic file size management.
57
+ - Log to file with automatic file deletion.
58
+ - Log to file with automatic deletion and rewriting of the file when it reaches max_file_size.
59
+
60
+ ## Getting Started
61
+
62
+ ## Installation
63
+
64
+ ```bash
65
+ pip install logly
66
+ ```
67
+
68
+ ## Usage
69
+
70
+ ```python
71
+ # Import Logly
72
+ from logly import Logly
73
+
74
+ # Create a Logly instance
75
+ logly = Logly()
76
+
77
+ # Start logging
78
+ logly.start_logging()
79
+
80
+ # Log messages with different levels and colors
81
+ logly.info("Key1", "Value1", color=logly.COLOR.CYAN)
82
+ logly.warn("Key2", "Value2", color=logly.COLOR.YELLOW)
83
+ logly.error("Key3", "Value3", color=logly.COLOR.RED)
84
+ logly.debug("Key4", "Value4", color=logly.COLOR.BLUE)
85
+ logly.critical("Key5", "Value5", color=logly.COLOR.CRITICAL)
86
+ logly.fatal("Key6", "Value6", color=logly.COLOR.CRITICAL)
87
+ logly.trace("Key7", "Value7", color=logly.COLOR.BLUE)
88
+ logly.log("Key8", "Value8", color=logly.COLOR.WHITE)
89
+
90
+ # Stop logging (no messages will be displayed or logged after this point)
91
+ logly.stop_logging()
92
+
93
+ # Log more messages after stopping logging (these won't be displayed or logged)
94
+ logly.info("AnotherKey1", "AnotherValue1", color=logly.COLOR.CYAN)
95
+ logly.warn("AnotherKey2", "AnotherValue2", color=logly.COLOR.YELLOW)
96
+ logly.error("AnotherKey3", "AnotherValue3", color=logly.COLOR.RED)
97
+
98
+ # Start logging again
99
+ logly.start_logging()
100
+
101
+ # Set default file path and max file size
102
+ logly.set_default_file_path("log.txt") # set default file path is "log.txt" if you want to set the file path where you want to save the log file.
103
+ logly.set_default_max_file_size(50) # set default max file size is 50 MB
104
+
105
+ # Log messages with default settings (using default file path and max file size)
106
+ logly.info("DefaultKey1", "DefaultValue1")
107
+ logly.warn("DefaultKey2", "DefaultValue2")
108
+ logly.error("DefaultKey3", "DefaultValue3", log_to_file=False)
109
+
110
+ #DEFAULT FILE SIZE IS 100 MB in txt file
111
+ # Log messages with custom file path and max file size(optional)
112
+ logly.info("CustomKey1", "CustomValue1", file_path="path/c.txt", max_file_size=25) # max_file_size is in MB and create a new file when the file size reaches max_file_size
113
+ logly.warn("CustomKey2", "CustomValue2", file_path="path/c.txt", max_file_size=25,auto=True) # auto=True will automatically delete the file data when it reaches max_file_size
114
+
115
+ # Access color constants directly
116
+ logly.info("Accessing color directly", "DirectColorValue", color=logly.COLOR.RED)
117
+
118
+ # Display logged messages (this will display all the messages logged so far)
119
+ print("Logged Messages:")
120
+ for message in logly.logged_messages:
121
+ print(message)
122
+
123
+ ```
124
+ ## Explanation:
125
+
126
+ 1. Import the `Logly` class from the `logly` module.
127
+ 2. Create an instance of `Logly`.
128
+ 3. Start logging using the `start_logging()` method.
129
+ 4. Log messages with various levels (info, warn, error, debug, critical, fatal, trace) and colors.
130
+ 5. Stop logging using the `stop_logging()` method.
131
+ 6. Log additional messages after stopping logging.
132
+ 7. Start logging again.
133
+ 8. Log messages with default settings and custom file path and max file size.
134
+ 9. Access color constants directly.
135
+ 10. Display logged messages.
136
+
137
+ ## Color Options:
138
+
139
+ ### Default Color Options:
140
+
141
+ | Level | Color Code |
142
+ | -------- | --------------- |
143
+ | INFO | CYAN |
144
+ | WARNING | YELLOW |
145
+ | ERROR | RED |
146
+ | DEBUG | BLUE |
147
+ | CRITICAL | BRIGHT RED |
148
+ | TRACE | BLUE |
149
+ | DEFAULT | WHITE |
150
+
151
+ ### Custom Color Options:
152
+
153
+ You can use any of the following color codes for custom coloring:
154
+
155
+ | NAME | Color Code |
156
+ |----------| --------------- |
157
+ | CYAN | CYAN |
158
+ | YELLOW | YELLOW |
159
+ | RED | RED |
160
+ | BLUE | BLUE |
161
+ | BRIGHT RED | CRITICAL |
162
+ |WHITE | WHITE |
163
+
164
+ For example, you can use `color=logly.COLOR.BLACK` for the black color.
165
+
166
+ ## Contributing
167
+ Contributions are welcome! Before contributing, please read our [Contributing Guidelines](CONTRIBUTING.md) to ensure a smooth and collaborative development process.
168
+
169
+ ## Code of Conduct
170
+
171
+ Please review our [Code of Conduct](CODE_OF_CONDUCT.md) to understand the standards of behavior we expect from contributors and users of this project.
172
+
173
+ ## License
174
+ This project is licensed under the [MIT License](). See [LICENSE](LICENSE) for more details.
175
+
176
+ ## Support the Project
177
+ <br>
178
+ <div align="center">
179
+
180
+ <h5> <strong> 💰 You can help me improve more by offering a little support on any platform❤️</strong></h5>
181
+
182
+ [![BuyMeACoffee](https://img.shields.io/badge/Buy%20Me%20a%20Coffee-ffdd00?style=for-the-badge&logo=buy-me-a-coffee&logoColor=black)](https://buymeacoffee.com/muhammadfiaz) [![Patreon](https://img.shields.io/badge/Patreon-F96854?style=for-the-badge&logo=patreon&logoColor=white)](https://patreon.com/muhammadfiaz) [![Ko-Fi](https://img.shields.io/badge/Ko--fi-F16061?style=for-the-badge&logo=ko-fi&logoColor=white)](https://ko-fi.com/muhammadfiaz)
183
+ [![Sponsor muhammad-fiaz](https://img.shields.io/badge/Sponsor-%231EAEDB.svg?&style=for-the-badge&logo=GitHub-Sponsors&logoColor=white)](https://github.com/sponsors/muhammad-fiaz)
184
+ [![Open Collective Backer](https://img.shields.io/badge/Open%20Collective-Backer-%238CC84B?style=for-the-badge&logo=open-collective&logoColor=white)](https://opencollective.com/muhammadfiaz)
185
+ </div>
186
+
187
+
188
+
189
+ ## Happy Coding ❤️
190
+
191
+
logly-0.0.2/README.md ADDED
@@ -0,0 +1,165 @@
1
+ <div align="center">
2
+
3
+ # Logly
4
+
5
+ [![Run Tests](https://github.com/muhammad-fiaz/logly/actions/workflows/python-package.yaml/badge.svg)](https://github.com/muhammad-fiaz/logly/actions/workflows/python-package.yaml)
6
+ [![PyPI Version](https://img.shields.io/pypi/v/logly)](https://pypi.org/project/logly/)
7
+ [![Python Versions](https://img.shields.io/pypi/pyversions/logly)](https://pypi.org/project/logly/)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
9
+ [![Downloads](https://img.shields.io/pypi/dm/logly)](https://pypi.org/project/logly/)
10
+ [![Last Commit](https://img.shields.io/github/last-commit/muhammad-fiaz/logly)](https://github.com/muhammad-fiaz/logly)
11
+ [![GitHub Issues](https://img.shields.io/github/issues/muhammad-fiaz/logly)](https://github.com/muhammad-fiaz/logly/issues)
12
+ [![GitHub Stars](https://img.shields.io/github/stars/muhammad-fiaz/logly)](https://github.com/muhammad-fiaz/logly/stargazers)
13
+ [![GitHub Forks](https://img.shields.io/github/forks/muhammad-fiaz/logly)](https://github.com/muhammad-fiaz/logly/network)
14
+
15
+ [![Maintainer](https://img.shields.io/badge/Maintainer-muhammad--fiaz-blue)](https://github.com/muhammad-fiaz)
16
+ [![Sponsor on GitHub](https://img.shields.io/badge/Sponsor%20on%20GitHub-Become%20a%20Sponsor-blue)](https://github.com/sponsors/muhammad-fiaz)
17
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
18
+ [![Stability](https://img.shields.io/badge/Stability-Stable-green)](https://github.com/muhammad-fiaz/logly)
19
+
20
+ </div>
21
+
22
+
23
+ Logly is a simple logging utility for Python that provides an easy way to log messages with different levels, colors, and options. It is designed to be flexible, allowing you to customize the log messages based on your application's needs. Logly supports logging to both the console and a file, and it comes with built-in color-coded log levels for better visibility.
24
+
25
+ ## Features
26
+
27
+ - Easy-to-use logging for Python applications.
28
+ - Customizable log levels and formatting.
29
+ - Customizable log colors.
30
+ - Log to file and/or console.
31
+ - Log to file with automatic file rotation.
32
+ - Log to file with automatic file size management.
33
+ - Log to file with automatic file deletion.
34
+ - Log to file with automatic deletion and rewriting of the file when it reaches max_file_size.
35
+
36
+ ## Getting Started
37
+
38
+ ## Installation
39
+
40
+ ```bash
41
+ pip install logly
42
+ ```
43
+
44
+ ## Usage
45
+
46
+ ```python
47
+ # Import Logly
48
+ from logly import Logly
49
+
50
+ # Create a Logly instance
51
+ logly = Logly()
52
+
53
+ # Start logging
54
+ logly.start_logging()
55
+
56
+ # Log messages with different levels and colors
57
+ logly.info("Key1", "Value1", color=logly.COLOR.CYAN)
58
+ logly.warn("Key2", "Value2", color=logly.COLOR.YELLOW)
59
+ logly.error("Key3", "Value3", color=logly.COLOR.RED)
60
+ logly.debug("Key4", "Value4", color=logly.COLOR.BLUE)
61
+ logly.critical("Key5", "Value5", color=logly.COLOR.CRITICAL)
62
+ logly.fatal("Key6", "Value6", color=logly.COLOR.CRITICAL)
63
+ logly.trace("Key7", "Value7", color=logly.COLOR.BLUE)
64
+ logly.log("Key8", "Value8", color=logly.COLOR.WHITE)
65
+
66
+ # Stop logging (no messages will be displayed or logged after this point)
67
+ logly.stop_logging()
68
+
69
+ # Log more messages after stopping logging (these won't be displayed or logged)
70
+ logly.info("AnotherKey1", "AnotherValue1", color=logly.COLOR.CYAN)
71
+ logly.warn("AnotherKey2", "AnotherValue2", color=logly.COLOR.YELLOW)
72
+ logly.error("AnotherKey3", "AnotherValue3", color=logly.COLOR.RED)
73
+
74
+ # Start logging again
75
+ logly.start_logging()
76
+
77
+ # Set default file path and max file size
78
+ logly.set_default_file_path("log.txt") # set default file path is "log.txt" if you want to set the file path where you want to save the log file.
79
+ logly.set_default_max_file_size(50) # set default max file size is 50 MB
80
+
81
+ # Log messages with default settings (using default file path and max file size)
82
+ logly.info("DefaultKey1", "DefaultValue1")
83
+ logly.warn("DefaultKey2", "DefaultValue2")
84
+ logly.error("DefaultKey3", "DefaultValue3", log_to_file=False)
85
+
86
+ #DEFAULT FILE SIZE IS 100 MB in txt file
87
+ # Log messages with custom file path and max file size(optional)
88
+ logly.info("CustomKey1", "CustomValue1", file_path="path/c.txt", max_file_size=25) # max_file_size is in MB and create a new file when the file size reaches max_file_size
89
+ logly.warn("CustomKey2", "CustomValue2", file_path="path/c.txt", max_file_size=25,auto=True) # auto=True will automatically delete the file data when it reaches max_file_size
90
+
91
+ # Access color constants directly
92
+ logly.info("Accessing color directly", "DirectColorValue", color=logly.COLOR.RED)
93
+
94
+ # Display logged messages (this will display all the messages logged so far)
95
+ print("Logged Messages:")
96
+ for message in logly.logged_messages:
97
+ print(message)
98
+
99
+ ```
100
+ ## Explanation:
101
+
102
+ 1. Import the `Logly` class from the `logly` module.
103
+ 2. Create an instance of `Logly`.
104
+ 3. Start logging using the `start_logging()` method.
105
+ 4. Log messages with various levels (info, warn, error, debug, critical, fatal, trace) and colors.
106
+ 5. Stop logging using the `stop_logging()` method.
107
+ 6. Log additional messages after stopping logging.
108
+ 7. Start logging again.
109
+ 8. Log messages with default settings and custom file path and max file size.
110
+ 9. Access color constants directly.
111
+ 10. Display logged messages.
112
+
113
+ ## Color Options:
114
+
115
+ ### Default Color Options:
116
+
117
+ | Level | Color Code |
118
+ | -------- | --------------- |
119
+ | INFO | CYAN |
120
+ | WARNING | YELLOW |
121
+ | ERROR | RED |
122
+ | DEBUG | BLUE |
123
+ | CRITICAL | BRIGHT RED |
124
+ | TRACE | BLUE |
125
+ | DEFAULT | WHITE |
126
+
127
+ ### Custom Color Options:
128
+
129
+ You can use any of the following color codes for custom coloring:
130
+
131
+ | NAME | Color Code |
132
+ |----------| --------------- |
133
+ | CYAN | CYAN |
134
+ | YELLOW | YELLOW |
135
+ | RED | RED |
136
+ | BLUE | BLUE |
137
+ | BRIGHT RED | CRITICAL |
138
+ |WHITE | WHITE |
139
+
140
+ For example, you can use `color=logly.COLOR.BLACK` for the black color.
141
+
142
+ ## Contributing
143
+ Contributions are welcome! Before contributing, please read our [Contributing Guidelines](CONTRIBUTING.md) to ensure a smooth and collaborative development process.
144
+
145
+ ## Code of Conduct
146
+
147
+ Please review our [Code of Conduct](CODE_OF_CONDUCT.md) to understand the standards of behavior we expect from contributors and users of this project.
148
+
149
+ ## License
150
+ This project is licensed under the [MIT License](). See [LICENSE](LICENSE) for more details.
151
+
152
+ ## Support the Project
153
+ <br>
154
+ <div align="center">
155
+
156
+ <h5> <strong> 💰 You can help me improve more by offering a little support on any platform❤️</strong></h5>
157
+
158
+ [![BuyMeACoffee](https://img.shields.io/badge/Buy%20Me%20a%20Coffee-ffdd00?style=for-the-badge&logo=buy-me-a-coffee&logoColor=black)](https://buymeacoffee.com/muhammadfiaz) [![Patreon](https://img.shields.io/badge/Patreon-F96854?style=for-the-badge&logo=patreon&logoColor=white)](https://patreon.com/muhammadfiaz) [![Ko-Fi](https://img.shields.io/badge/Ko--fi-F16061?style=for-the-badge&logo=ko-fi&logoColor=white)](https://ko-fi.com/muhammadfiaz)
159
+ [![Sponsor muhammad-fiaz](https://img.shields.io/badge/Sponsor-%231EAEDB.svg?&style=for-the-badge&logo=GitHub-Sponsors&logoColor=white)](https://github.com/sponsors/muhammad-fiaz)
160
+ [![Open Collective Backer](https://img.shields.io/badge/Open%20Collective-Backer-%238CC84B?style=for-the-badge&logo=open-collective&logoColor=white)](https://opencollective.com/muhammadfiaz)
161
+ </div>
162
+
163
+
164
+
165
+ ## Happy Coding ❤️
@@ -0,0 +1,5 @@
1
+ # Example usage:
2
+ from logly.logly import *
3
+
4
+ logly = Logly()
5
+
@@ -0,0 +1,47 @@
1
+ class LoglyException(Exception):
2
+ """
3
+ Base exception class for Logly. All specific Logly exceptions should inherit from this class.
4
+ """
5
+ def __init__(self, message):
6
+ """
7
+ Initialize a LoglyException.
8
+
9
+ Parameters:
10
+ - message (str): The error message.
11
+ """
12
+ super().__init__(message)
13
+
14
+
15
+ class FilePathNotFoundException(LoglyException):
16
+ """
17
+ Exception raised when the specified file path is not found.
18
+ """
19
+ pass
20
+
21
+
22
+ class FileCreationError(LoglyException):
23
+ """
24
+ Exception raised when there is an error creating or writing to the log file.
25
+ """
26
+ pass
27
+
28
+
29
+ class FileAccessError(LoglyException):
30
+ """
31
+ Exception raised when there is an error accessing the log file.
32
+ """
33
+ pass
34
+
35
+
36
+ class InvalidConfigError(LoglyException):
37
+ """
38
+ Exception raised for invalid Logly configuration.
39
+ """
40
+ pass
41
+
42
+
43
+ class InvalidLogLevelError(LoglyException):
44
+ """
45
+ Exception raised when an invalid log level is provided.
46
+ """
47
+ pass
@@ -0,0 +1,356 @@
1
+ import os
2
+ from colorama import Fore, Style, init
3
+ from datetime import datetime
4
+ import re
5
+
6
+ from logly.exception import FilePathNotFoundException, FileAccessError, FileCreationError, LoglyException
7
+
8
+ init(autoreset=True)
9
+
10
+ class Logly:
11
+ """
12
+ Logly: A simple logging utility.
13
+
14
+ Attributes:
15
+ - COLOR_MAP (dict): Mapping of log levels to color codes.
16
+ - COLOR (class): Color constants for log messages.
17
+ - DEFAULT_MAX_FILE_SIZE_MB (int): Default maximum file size in megabytes.
18
+
19
+ Methods:
20
+ - __init__: Initialize Logly instance.
21
+ - start_logging: Enable logging.
22
+ - stop_logging: Disable logging.
23
+ - disable_file_logging: Disable logging to a file.
24
+ - enable_file_logging: Enable logging to a file.
25
+ - set_default_file_path: Set default file path.
26
+ - set_default_max_file_size: Set default maximum file size.
27
+ - get_current_datetime: Get current date and time as a formatted string.
28
+ - remove_color_codes: Remove ANSI color codes from text.
29
+ - _log: Internal method to log a message.
30
+ - log_function: Log a message with exception handling.
31
+ - info, warn, error, debug, critical, fatal, trace: Log messages with different levels.
32
+ - log: Log a message with the INFO level.
33
+ """
34
+
35
+ COLOR_MAP = {
36
+ "DEBUG": Fore.BLUE,
37
+ "INFO": Fore.CYAN,
38
+ "WARNING": Fore.YELLOW,
39
+ "ERROR": Fore.RED,
40
+ "CRITICAL": f"{Fore.RED}{Style.BRIGHT}",
41
+ }
42
+
43
+ # Define color constants
44
+ class COLOR:
45
+ BLUE = Fore.BLUE
46
+ CYAN = Fore.CYAN
47
+ YELLOW = Fore.YELLOW
48
+ RED = Fore.RED
49
+ CRITICAL = f"{Fore.RED}{Style.BRIGHT}"
50
+ WHITE = Fore.WHITE
51
+
52
+ DEFAULT_MAX_FILE_SIZE_MB = 100 # 100MB
53
+
54
+ def __init__(self):
55
+ """
56
+ Initialize a Logly instance.
57
+
58
+ Attributes:
59
+ - logging_enabled (bool): Flag indicating whether logging is enabled.
60
+ - log_to_file_enabled (bool): Flag indicating whether logging to a file is enabled.
61
+ - logged_messages (list): List to store logged messages.
62
+ - default_file_path (str): Default file path for logging.
63
+ - default_max_file_size (int): Default maximum file size for logging.
64
+ """
65
+ self.logging_enabled = False
66
+ self.log_to_file_enabled = True
67
+ self.logged_messages = []
68
+ self.default_file_path = None
69
+ self.default_max_file_size = self.DEFAULT_MAX_FILE_SIZE_MB
70
+
71
+ def start_logging(self):
72
+ """
73
+ Enable logging.
74
+ """
75
+ self.logging_enabled = True
76
+
77
+ def stop_logging(self):
78
+ """
79
+ Disable logging.
80
+ """
81
+ self.logging_enabled = False
82
+
83
+ def disable_file_logging(self):
84
+ """
85
+ Disable logging to a file.
86
+ """
87
+ self.log_to_file_enabled = False
88
+
89
+ def enable_file_logging(self):
90
+ """
91
+ Enable logging to a file.
92
+ """
93
+ self.log_to_file_enabled = True
94
+
95
+ def set_default_file_path(self, file_path):
96
+ """
97
+ Set the default file path.
98
+
99
+ Parameters:
100
+ - file_path (str): The default file path.
101
+ """
102
+ self.default_file_path = file_path
103
+
104
+ def set_default_max_file_size(self, max_file_size):
105
+ """
106
+ Set the default maximum file size.
107
+
108
+ Parameters:
109
+ - max_file_size (int): The default maximum file size.
110
+ """
111
+ self.default_max_file_size = max_file_size
112
+
113
+ def get_current_datetime(self):
114
+ """
115
+ Get the current date and time as a formatted string.
116
+
117
+ Returns:
118
+ - str: Formatted date and time string.
119
+ """
120
+ return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
121
+
122
+ def remove_color_codes(self, text):
123
+ """
124
+ Remove ANSI color codes from text.
125
+
126
+ Parameters:
127
+ - text (str): Input text with color codes.
128
+
129
+ Returns:
130
+ - str: Text with color codes removed.
131
+ """
132
+ return re.sub(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])', '', text)
133
+
134
+ def _log(self, level, key, value, color=None, log_to_file=True, file_path=None, file_name=None, max_file_size=None, auto=True):
135
+ """
136
+ Internal method to log a message.
137
+
138
+ Parameters:
139
+ - level (str): Log level (e.g., "INFO", "ERROR").
140
+ - key (str): The key associated with the log message.
141
+ - value (str): The value of the log message.
142
+ - color (str): ANSI color code for the log message.
143
+ - log_to_file (bool): Whether to log to a file.
144
+ - file_path (str): File path for logging.
145
+ - file_name (str): File name for logging.
146
+ - max_file_size (int): Maximum file size for logging.
147
+ - auto (bool): Whether to auto-delete log file data when the size limit is reached.
148
+ """
149
+ color = color or self.COLOR_MAP.get(level, self.COLOR.BLUE)
150
+ log_message = f"[{self.get_current_datetime()}] {level}: {color}{key}: {value}{Style.RESET_ALL}"
151
+
152
+ # Log to console
153
+ print(log_message)
154
+
155
+ if self.log_to_file_enabled and log_to_file:
156
+ try:
157
+ # Remove color codes before storing in the log file
158
+ log_message_without_color = self.remove_color_codes(log_message)
159
+
160
+ # Determine the file path and name
161
+ if file_path is None:
162
+ file_path = self.default_file_path or os.path.join(os.getcwd(), "log.txt") # Default file path and name in the project root
163
+ elif file_name:
164
+ file_path = os.path.join(os.getcwd(), f"{file_name}.txt") # Use the provided file name in the project root
165
+
166
+ # Create the directories if they don't exist
167
+ os.makedirs(os.path.dirname(file_path), exist_ok=True)
168
+
169
+ # Check if the file path exists
170
+ if not os.path.exists(os.path.dirname(file_path)):
171
+ raise FilePathNotFoundException(f"The specified file path does not exist: {os.path.dirname(file_path)}")
172
+
173
+ # Set the default max_file_size if not provided
174
+ max_file_size = max_file_size or self.default_max_file_size
175
+
176
+ # Convert max_file_size to bytes
177
+ max_file_size_bytes = max_file_size * 1024 * 1024
178
+
179
+ # Check if the file exists
180
+ file_exists = os.path.exists(file_path)
181
+
182
+ # Check if the file size limit is reached
183
+ if max_file_size and file_exists and os.path.getsize(file_path) >= max_file_size_bytes:
184
+ if auto:
185
+ # Auto-delete log file data by truncating the file
186
+ with open(file_path, 'w'):
187
+ pass
188
+ else:
189
+ # Find the next available file name with a number appended
190
+ file_base, file_ext = os.path.splitext(file_path)
191
+ count = 1
192
+ while os.path.exists(f"{file_base}_{count}{file_ext}"):
193
+ count += 1
194
+ file_path = f"{file_base}_{count}{file_ext}"
195
+
196
+ # Open the file in append mode, creating it if it doesn't exist
197
+ with open(file_path, "a" if file_exists else "w") as log_file:
198
+ log_file.write(log_message_without_color + "\n")
199
+
200
+ self.logged_messages.append(log_message + "\n")
201
+
202
+ except (FileNotFoundError, PermissionError) as e:
203
+ raise FileAccessError(f"Error accessing the log file: {e}")
204
+ except Exception as e:
205
+ raise FileCreationError(f"Error creating or writing to the log file: {e}")
206
+
207
+ def log_function(self, level, key, value, color=None, log_to_file=True, file_path=None, file_name=None, max_file_size=None, auto=True):
208
+ """
209
+ Log a message with exception handling.
210
+
211
+ Parameters:
212
+ - level (str): Log level (e.g., "INFO", "ERROR").
213
+ - key (str): The key associated with the log message.
214
+ - value (str): The value of the log message.
215
+ - color (str): ANSI color code for the log message.
216
+ - log_to_file (bool): Whether to log to a file.
217
+ - file_path (str): File path for logging.
218
+ - file_name (str): File name for logging.
219
+ - max_file_size (int): Maximum file size for logging.
220
+ - auto (bool): Whether to auto-delete log file data when the size limit is reached.
221
+ """
222
+ try:
223
+ self._log(level, key, value, color, log_to_file, file_path, file_name, max_file_size, auto)
224
+ except LoglyException as e:
225
+ print(f"LoglyException: {e}")
226
+
227
+ def info(self, key, value, color=None, log_to_file=True, file_path=None, file_name=None, max_file_size=None, auto=True):
228
+ """
229
+ Log a message with the INFO level.
230
+
231
+ Parameters:
232
+ - key (str): The key associated with the log message.
233
+ - value (str): The value of the log message.
234
+ - color (str): ANSI color code for the log message.
235
+ - log_to_file (bool): Whether to log to a file.
236
+ - file_path (str): File path for logging.
237
+ - file_name (str): File name for logging.
238
+ - max_file_size (int): Maximum file size for logging.
239
+ - auto (bool): Whether to auto-delete log file data when the size limit is reached.
240
+ """
241
+ self.log_function("INFO", key, value, color, log_to_file, file_path, file_name, max_file_size, auto)
242
+
243
+ def warn(self, key, value, color=None, log_to_file=True, file_path=None, file_name=None, max_file_size=None, auto=True):
244
+ """
245
+ Log a message with the WARNING level.
246
+
247
+ Parameters:
248
+ - key (str): The key associated with the log message.
249
+ - value (str): The value of the log message.
250
+ - color (str): ANSI color code for the log message.
251
+ - log_to_file (bool): Whether to log to a file.
252
+ - file_path (str): File path for logging.
253
+ - file_name (str): File name for logging.
254
+ - max_file_size (int): Maximum file size for logging.
255
+ - auto (bool): Whether to auto-delete log file data when the size limit is reached.
256
+ """
257
+ self.log_function("WARNING", key, value, color, log_to_file, file_path, file_name, max_file_size, auto)
258
+
259
+ def error(self, key, value, color=None, log_to_file=True, file_path=None, file_name=None, max_file_size=None, auto=True):
260
+ """
261
+ Log a message with the ERROR level.
262
+
263
+ Parameters:
264
+ - key (str): The key associated with the log message.
265
+ - value (str): The value of the log message.
266
+ - color (str): ANSI color code for the log message.
267
+ - log_to_file (bool): Whether to log to a file.
268
+ - file_path (str): File path for logging.
269
+ - file_name (str): File name for logging.
270
+ - max_file_size (int): Maximum file size for logging.
271
+ - auto (bool): Whether to auto-delete log file data when the size limit is reached.
272
+ """
273
+ self.log_function("ERROR", key, value, color, log_to_file, file_path, file_name, max_file_size, auto)
274
+
275
+ def debug(self, key, value, color=None, log_to_file=True, file_path=None, file_name=None, max_file_size=None, auto=True):
276
+ """
277
+ Log a message with the DEBUG level.
278
+
279
+ Parameters:
280
+ - key (str): The key associated with the log message.
281
+ - value (str): The value of the log message.
282
+ - color (str): ANSI color code for the log message.
283
+ - log_to_file (bool): Whether to log to a file.
284
+ - file_path (str): File path for logging.
285
+ - file_name (str): File name for logging.
286
+ - max_file_size (int): Maximum file size for logging.
287
+ - auto (bool): Whether to auto-delete log file data when the size limit is reached.
288
+ """
289
+ self.log_function("DEBUG", key, value, color, log_to_file, file_path, file_name, max_file_size, auto)
290
+
291
+ def critical(self, key, value, color=None, log_to_file=True, file_path=None, file_name=None, max_file_size=None, auto=True):
292
+ """
293
+ Log a critical message.
294
+
295
+ Parameters:
296
+ - key (str): The key for the log entry.
297
+ - value (str): The value for the log entry.
298
+ - color (str, optional): The color of the log entry. Defaults to None.
299
+ - log_to_file (bool, optional): Whether to log to a file. Defaults to True.
300
+ - file_path (str, optional): The path to the log file. Defaults to None.
301
+ - file_name (str, optional): The name of the log file. Defaults to None.
302
+ - max_file_size (int, optional): The maximum size of the log file in megabytes. Defaults to None.
303
+ - auto (bool): Whether to auto-delete log file data when the size limit is reached.
304
+ """
305
+ self.log_function("CRITICAL", key, value, color, log_to_file, file_path, file_name, max_file_size, auto)
306
+
307
+ def fatal(self, key, value, color=None, log_to_file=True, file_path=None, file_name=None, max_file_size=None, auto=True):
308
+ """
309
+ Log a fatal message.
310
+
311
+ Parameters:
312
+ - key (str): The key for the log entry.
313
+ - value (str): The value for the log entry.
314
+ - color (str, optional): The color of the log entry. Defaults to None.
315
+ - log_to_file (bool, optional): Whether to log to a file. Defaults to True.
316
+ - file_path (str, optional): The path to the log file. Defaults to None.
317
+ - file_name (str, optional): The name of the log file. Defaults to None.
318
+ - max_file_size (int, optional): The maximum size of the log file in megabytes. Defaults to None.
319
+ - auto (bool): Whether to auto-delete log file data when the size limit is reached.
320
+ """
321
+ self.log_function("FATAL", key, value, color, log_to_file, file_path, file_name, max_file_size, auto)
322
+
323
+ def trace(self, key, value, color=None, log_to_file=True, file_path=None, file_name=None, max_file_size=None, auto=True):
324
+ """
325
+ Log a trace message.
326
+
327
+ Parameters:
328
+ - key (str): The key for the log entry.
329
+ - value (str): The value for the log entry.
330
+ - color (str, optional): The color of the log entry. Defaults to None.
331
+ - log_to_file (bool, optional): Whether to log to a file. Defaults to True.
332
+ - file_path (str, optional): The path to the log file. Defaults to None.
333
+ - file_name (str, optional): The name of the log file. Defaults to None.
334
+ - max_file_size (int, optional): The maximum size of the log file in megabytes. Defaults to None.
335
+ - auto (bool, optional): Whether to automatically delete log file data if it reaches the file size limit
336
+ and start storing again from scratch. Defaults to True.
337
+ """
338
+ self.log_function("TRACE", key, value, color, log_to_file, file_path, file_name, max_file_size, auto)
339
+
340
+
341
+ def log(self, key, value, color=None, log_to_file=True, file_path=None, file_name=None, max_file_size=None, auto=True):
342
+ """
343
+ Log an info message.
344
+
345
+ Parameters:
346
+ - key (str): The key for the log entry.
347
+ - value (str): The value for the log entry.
348
+ - color (str, optional): The color of the log entry. Defaults to None.
349
+ - log_to_file (bool, optional): Whether to log to a file. Defaults to True.
350
+ - file_path (str, optional): The path to the log file. Defaults to None.
351
+ - file_name (str, optional): The name of the log file. Defaults to None.
352
+ - max_file_size (int, optional): The maximum size of the log file in megabytes. Defaults to None.
353
+ - auto (bool, optional): Whether to automatically delete log file data if it reaches the file size limit
354
+ and start storing again from scratch. Defaults to True.
355
+ """
356
+ self.log_function("LOG", key, value, color, log_to_file, file_path, file_name, max_file_size, auto)
@@ -0,0 +1,191 @@
1
+ Metadata-Version: 2.1
2
+ Name: logly
3
+ Version: 0.0.2
4
+ Summary: Logly: Python logging utility with color-coded messages and file support. Easily log and trace messages with customizable colors. Simple integration for effective debugging and monitoring.
5
+ Home-page: https://github.com/muhammad-fiaz/logly.git
6
+ Author: Muhammad Fiaz
7
+ Author-email: contact@muhammmadfiaz.com
8
+ License: MIT License
9
+ Project-URL: Source Code, https://github.com/muhammad-fiaz/logly.git
10
+ Project-URL: Bug Tracker, https://github.com/muhammad-fiaz/logly/issues
11
+ Project-URL: Documentation, https://github.com/muhammad-fiaz/logly#readme
12
+ Keywords: log,logging,logly,python
13
+ Platform: UNKNOWN
14
+ Classifier: Development Status :: 1 - Planning
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Operating System :: Unix
19
+ Classifier: Operating System :: MacOS :: MacOS X
20
+ Classifier: Operating System :: Microsoft :: Windows
21
+ Requires-Python: >=3.8
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+
25
+ <div align="center">
26
+
27
+ # Logly
28
+
29
+ [![Run Tests](https://github.com/muhammad-fiaz/logly/actions/workflows/python-package.yaml/badge.svg)](https://github.com/muhammad-fiaz/logly/actions/workflows/python-package.yaml)
30
+ [![PyPI Version](https://img.shields.io/pypi/v/logly)](https://pypi.org/project/logly/)
31
+ [![Python Versions](https://img.shields.io/pypi/pyversions/logly)](https://pypi.org/project/logly/)
32
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
33
+ [![Downloads](https://img.shields.io/pypi/dm/logly)](https://pypi.org/project/logly/)
34
+ [![Last Commit](https://img.shields.io/github/last-commit/muhammad-fiaz/logly)](https://github.com/muhammad-fiaz/logly)
35
+ [![GitHub Issues](https://img.shields.io/github/issues/muhammad-fiaz/logly)](https://github.com/muhammad-fiaz/logly/issues)
36
+ [![GitHub Stars](https://img.shields.io/github/stars/muhammad-fiaz/logly)](https://github.com/muhammad-fiaz/logly/stargazers)
37
+ [![GitHub Forks](https://img.shields.io/github/forks/muhammad-fiaz/logly)](https://github.com/muhammad-fiaz/logly/network)
38
+
39
+ [![Maintainer](https://img.shields.io/badge/Maintainer-muhammad--fiaz-blue)](https://github.com/muhammad-fiaz)
40
+ [![Sponsor on GitHub](https://img.shields.io/badge/Sponsor%20on%20GitHub-Become%20a%20Sponsor-blue)](https://github.com/sponsors/muhammad-fiaz)
41
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
42
+ [![Stability](https://img.shields.io/badge/Stability-Stable-green)](https://github.com/muhammad-fiaz/logly)
43
+
44
+ </div>
45
+
46
+
47
+ Logly is a simple logging utility for Python that provides an easy way to log messages with different levels, colors, and options. It is designed to be flexible, allowing you to customize the log messages based on your application's needs. Logly supports logging to both the console and a file, and it comes with built-in color-coded log levels for better visibility.
48
+
49
+ ## Features
50
+
51
+ - Easy-to-use logging for Python applications.
52
+ - Customizable log levels and formatting.
53
+ - Customizable log colors.
54
+ - Log to file and/or console.
55
+ - Log to file with automatic file rotation.
56
+ - Log to file with automatic file size management.
57
+ - Log to file with automatic file deletion.
58
+ - Log to file with automatic deletion and rewriting of the file when it reaches max_file_size.
59
+
60
+ ## Getting Started
61
+
62
+ ## Installation
63
+
64
+ ```bash
65
+ pip install logly
66
+ ```
67
+
68
+ ## Usage
69
+
70
+ ```python
71
+ # Import Logly
72
+ from logly import Logly
73
+
74
+ # Create a Logly instance
75
+ logly = Logly()
76
+
77
+ # Start logging
78
+ logly.start_logging()
79
+
80
+ # Log messages with different levels and colors
81
+ logly.info("Key1", "Value1", color=logly.COLOR.CYAN)
82
+ logly.warn("Key2", "Value2", color=logly.COLOR.YELLOW)
83
+ logly.error("Key3", "Value3", color=logly.COLOR.RED)
84
+ logly.debug("Key4", "Value4", color=logly.COLOR.BLUE)
85
+ logly.critical("Key5", "Value5", color=logly.COLOR.CRITICAL)
86
+ logly.fatal("Key6", "Value6", color=logly.COLOR.CRITICAL)
87
+ logly.trace("Key7", "Value7", color=logly.COLOR.BLUE)
88
+ logly.log("Key8", "Value8", color=logly.COLOR.WHITE)
89
+
90
+ # Stop logging (no messages will be displayed or logged after this point)
91
+ logly.stop_logging()
92
+
93
+ # Log more messages after stopping logging (these won't be displayed or logged)
94
+ logly.info("AnotherKey1", "AnotherValue1", color=logly.COLOR.CYAN)
95
+ logly.warn("AnotherKey2", "AnotherValue2", color=logly.COLOR.YELLOW)
96
+ logly.error("AnotherKey3", "AnotherValue3", color=logly.COLOR.RED)
97
+
98
+ # Start logging again
99
+ logly.start_logging()
100
+
101
+ # Set default file path and max file size
102
+ logly.set_default_file_path("log.txt") # set default file path is "log.txt" if you want to set the file path where you want to save the log file.
103
+ logly.set_default_max_file_size(50) # set default max file size is 50 MB
104
+
105
+ # Log messages with default settings (using default file path and max file size)
106
+ logly.info("DefaultKey1", "DefaultValue1")
107
+ logly.warn("DefaultKey2", "DefaultValue2")
108
+ logly.error("DefaultKey3", "DefaultValue3", log_to_file=False)
109
+
110
+ #DEFAULT FILE SIZE IS 100 MB in txt file
111
+ # Log messages with custom file path and max file size(optional)
112
+ logly.info("CustomKey1", "CustomValue1", file_path="path/c.txt", max_file_size=25) # max_file_size is in MB and create a new file when the file size reaches max_file_size
113
+ logly.warn("CustomKey2", "CustomValue2", file_path="path/c.txt", max_file_size=25,auto=True) # auto=True will automatically delete the file data when it reaches max_file_size
114
+
115
+ # Access color constants directly
116
+ logly.info("Accessing color directly", "DirectColorValue", color=logly.COLOR.RED)
117
+
118
+ # Display logged messages (this will display all the messages logged so far)
119
+ print("Logged Messages:")
120
+ for message in logly.logged_messages:
121
+ print(message)
122
+
123
+ ```
124
+ ## Explanation:
125
+
126
+ 1. Import the `Logly` class from the `logly` module.
127
+ 2. Create an instance of `Logly`.
128
+ 3. Start logging using the `start_logging()` method.
129
+ 4. Log messages with various levels (info, warn, error, debug, critical, fatal, trace) and colors.
130
+ 5. Stop logging using the `stop_logging()` method.
131
+ 6. Log additional messages after stopping logging.
132
+ 7. Start logging again.
133
+ 8. Log messages with default settings and custom file path and max file size.
134
+ 9. Access color constants directly.
135
+ 10. Display logged messages.
136
+
137
+ ## Color Options:
138
+
139
+ ### Default Color Options:
140
+
141
+ | Level | Color Code |
142
+ | -------- | --------------- |
143
+ | INFO | CYAN |
144
+ | WARNING | YELLOW |
145
+ | ERROR | RED |
146
+ | DEBUG | BLUE |
147
+ | CRITICAL | BRIGHT RED |
148
+ | TRACE | BLUE |
149
+ | DEFAULT | WHITE |
150
+
151
+ ### Custom Color Options:
152
+
153
+ You can use any of the following color codes for custom coloring:
154
+
155
+ | NAME | Color Code |
156
+ |----------| --------------- |
157
+ | CYAN | CYAN |
158
+ | YELLOW | YELLOW |
159
+ | RED | RED |
160
+ | BLUE | BLUE |
161
+ | BRIGHT RED | CRITICAL |
162
+ |WHITE | WHITE |
163
+
164
+ For example, you can use `color=logly.COLOR.BLACK` for the black color.
165
+
166
+ ## Contributing
167
+ Contributions are welcome! Before contributing, please read our [Contributing Guidelines](CONTRIBUTING.md) to ensure a smooth and collaborative development process.
168
+
169
+ ## Code of Conduct
170
+
171
+ Please review our [Code of Conduct](CODE_OF_CONDUCT.md) to understand the standards of behavior we expect from contributors and users of this project.
172
+
173
+ ## License
174
+ This project is licensed under the [MIT License](). See [LICENSE](LICENSE) for more details.
175
+
176
+ ## Support the Project
177
+ <br>
178
+ <div align="center">
179
+
180
+ <h5> <strong> 💰 You can help me improve more by offering a little support on any platform❤️</strong></h5>
181
+
182
+ [![BuyMeACoffee](https://img.shields.io/badge/Buy%20Me%20a%20Coffee-ffdd00?style=for-the-badge&logo=buy-me-a-coffee&logoColor=black)](https://buymeacoffee.com/muhammadfiaz) [![Patreon](https://img.shields.io/badge/Patreon-F96854?style=for-the-badge&logo=patreon&logoColor=white)](https://patreon.com/muhammadfiaz) [![Ko-Fi](https://img.shields.io/badge/Ko--fi-F16061?style=for-the-badge&logo=ko-fi&logoColor=white)](https://ko-fi.com/muhammadfiaz)
183
+ [![Sponsor muhammad-fiaz](https://img.shields.io/badge/Sponsor-%231EAEDB.svg?&style=for-the-badge&logo=GitHub-Sponsors&logoColor=white)](https://github.com/sponsors/muhammad-fiaz)
184
+ [![Open Collective Backer](https://img.shields.io/badge/Open%20Collective-Backer-%238CC84B?style=for-the-badge&logo=open-collective&logoColor=white)](https://opencollective.com/muhammadfiaz)
185
+ </div>
186
+
187
+
188
+
189
+ ## Happy Coding ❤️
190
+
191
+
@@ -2,7 +2,8 @@ LICENSE
2
2
  README.md
3
3
  setup.py
4
4
  logly/__init__.py
5
- logly/checkversions.py
5
+ logly/exception.py
6
+ logly/logly.py
6
7
  logly/version.py
7
8
  logly.egg-info/PKG-INFO
8
9
  logly.egg-info/SOURCES.txt
@@ -1,3 +1,4 @@
1
1
  setuptools==69.0.2
2
2
  pytest==7.4.3
3
3
  packaging==23.2
4
+ colorama>=0.4.4
@@ -1,4 +1,4 @@
1
- [egg_info]
2
- tag_build =
3
- tag_date = 0
4
-
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -2,11 +2,12 @@ from setuptools import setup, find_packages
2
2
 
3
3
  from logly.version import get_Version
4
4
 
5
- VERSION = "0.0.0"
5
+ VERSION = "0.0.2"
6
6
 
7
7
  get_Version(VERSION)
8
8
 
9
- DESCRIPTION = 'logly is a Python package for logging.'
9
+ DESCRIPTION = ('Logly: Python logging utility with color-coded messages and file support. Easily log and trace '
10
+ 'messages with customizable colors. Simple integration for effective debugging and monitoring.')
10
11
 
11
12
  with open("README.md", "r", encoding="utf-8") as fh:
12
13
  LONG_DESCRIPTION = fh.read()
@@ -22,7 +23,7 @@ setup(
22
23
  url='https://github.com/muhammad-fiaz/logly.git',
23
24
  packages=find_packages(),
24
25
  keywords=[
25
- 'log'
26
+ 'log', 'logging', 'logly', 'python'
26
27
  ],
27
28
  classifiers=[
28
29
  "Development Status :: 1 - Planning",
@@ -38,11 +39,16 @@ setup(
38
39
  'setuptools==69.0.2',
39
40
  'pytest==7.4.3',
40
41
  'packaging==23.2',
42
+ 'colorama>=0.4.4'
41
43
  ],
42
44
  setup_requires=['pytest-runner'],
43
45
  tests_require=['pytest'],
44
46
  license='MIT License',
45
-
47
+ project_urls={
48
+ 'Source Code': 'https://github.com/muhammad-fiaz/logly.git',
49
+ 'Bug Tracker': 'https://github.com/muhammad-fiaz/logly/issues',
50
+ 'Documentation': 'https://github.com/muhammad-fiaz/logly#readme',
51
+ },
46
52
  )
47
53
 
48
54
  print("Happy Coding!")
@@ -0,0 +1,61 @@
1
+ # test_logly_integration.py
2
+ import os
3
+ import pytest
4
+
5
+ from logly import Logly
6
+
7
+ @pytest.fixture
8
+ def logly_instance():
9
+ """
10
+ Fixture to create and return a Logly instance for testing.
11
+
12
+ Returns:
13
+ - Logly: A Logly instance with logging started.
14
+ """
15
+ logly = Logly()
16
+ logly.start_logging()
17
+ return logly
18
+
19
+ def test_logly_integration(logly_instance):
20
+ """
21
+ Test the integration of Logly by logging messages with different levels and colors.
22
+
23
+ Parameters:
24
+ - logly_instance (Logly): The Logly instance created by the fixture.
25
+ """
26
+ # Log messages with different levels and colors
27
+ logly_instance.info("Key1", "Value1", color=logly_instance.COLOR.CYAN)
28
+ logly_instance.warn("Key2", "Value2", color=logly_instance.COLOR.YELLOW)
29
+ logly_instance.error("Key3", "Value3", color=logly_instance.COLOR.RED)
30
+ logly_instance.debug("Key4", "Value4", color=logly_instance.COLOR.BLUE)
31
+ logly_instance.critical("Key5", "Value5", color=logly_instance.COLOR.CRITICAL)
32
+ logly_instance.fatal("Key6", "Value6", color=logly_instance.COLOR.CRITICAL)
33
+ logly_instance.trace("Key7", "Value7", color=logly_instance.COLOR.BLUE)
34
+ logly_instance.log("Key8", "Value8", color=logly_instance.COLOR.WHITE)
35
+
36
+ # Stop logging
37
+ logly_instance.stop_logging()
38
+
39
+ # Log more messages after stopping logging (these won't be displayed or logged)
40
+ logly_instance.info("AnotherKey1", "AnotherValue1", color=logly_instance.COLOR.CYAN)
41
+ logly_instance.warn("AnotherKey2", "AnotherValue2", color=logly_instance.COLOR.YELLOW)
42
+ logly_instance.error("AnotherKey3", "AnotherValue3", color=logly_instance.COLOR.RED)
43
+
44
+ # Start logging again
45
+ logly_instance.start_logging()
46
+
47
+ # Log messages with default settings (using default file path and max file size)
48
+ logly_instance.info("DefaultKey1", "DefaultValue1")
49
+ logly_instance.warn("DefaultKey2", "DefaultValue2")
50
+ logly_instance.error("DefaultKey3", "DefaultValue3", log_to_file=False)
51
+
52
+ # Log messages with custom file path and max file size
53
+ logly_instance.info("CustomKey1", "CustomValue1", file_path="path/log.txt", max_file_size=25)
54
+ logly_instance.warn("CustomKey2", "CustomValue2", file_path="path/log.txt",auto=True, max_file_size=25)
55
+
56
+ # Access color constants directly
57
+ logly_instance.info("Accessing color directly", "DirectColorValue", color=logly_instance.COLOR.RED)
58
+
59
+ # Display logged messages
60
+ for message in logly_instance.logged_messages:
61
+ print(message)
logly-0.0.0/PKG-INFO DELETED
@@ -1,24 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: logly
3
- Version: 0.0.0
4
- Summary: logly is a Python package for logging.
5
- Home-page: https://github.com/muhammad-fiaz/logly.git
6
- Author: Muhammad Fiaz
7
- Author-email: contact@muhammmadfiaz.com
8
- License: MIT License
9
- Keywords: log
10
- Classifier: Development Status :: 1 - Planning
11
- Classifier: Intended Audience :: Developers
12
- Classifier: Programming Language :: Python :: 3
13
- Classifier: License :: OSI Approved :: MIT License
14
- Classifier: Operating System :: Unix
15
- Classifier: Operating System :: MacOS :: MacOS X
16
- Classifier: Operating System :: Microsoft :: Windows
17
- Requires-Python: >=3.8
18
- Description-Content-Type: text/markdown
19
- License-File: LICENSE
20
- Requires-Dist: setuptools==69.0.2
21
- Requires-Dist: pytest==7.4.3
22
- Requires-Dist: packaging==23.2
23
-
24
- # logly
logly-0.0.0/README.md DELETED
@@ -1 +0,0 @@
1
- # logly
File without changes
@@ -1,24 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: logly
3
- Version: 0.0.0
4
- Summary: logly is a Python package for logging.
5
- Home-page: https://github.com/muhammad-fiaz/logly.git
6
- Author: Muhammad Fiaz
7
- Author-email: contact@muhammmadfiaz.com
8
- License: MIT License
9
- Keywords: log
10
- Classifier: Development Status :: 1 - Planning
11
- Classifier: Intended Audience :: Developers
12
- Classifier: Programming Language :: Python :: 3
13
- Classifier: License :: OSI Approved :: MIT License
14
- Classifier: Operating System :: Unix
15
- Classifier: Operating System :: MacOS :: MacOS X
16
- Classifier: Operating System :: Microsoft :: Windows
17
- Requires-Python: >=3.8
18
- Description-Content-Type: text/markdown
19
- License-File: LICENSE
20
- Requires-Dist: setuptools==69.0.2
21
- Requires-Dist: pytest==7.4.3
22
- Requires-Dist: packaging==23.2
23
-
24
- # logly
File without changes
@@ -1 +0,0 @@
1
- import pytest
File without changes
File without changes
File without changes