Skip to content

Commit

Permalink
v0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammad-fiaz committed Dec 18, 2023
1 parent f5ee5b8 commit 1706a20
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 432 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ from logly import Logly

# Create a Logly instance
logly = Logly()
# logly = Logly(show_time=False) # Include timestamps in log messages default is true and you can set it to false
# logly = Logly(show_time=False) # Include timestamps in log messages default is true, and you can set it to false will not show the time in all log messages

# Start logging
logly.start_logging()

logly.info("hello this is log")
logly.info("hello this is log", color=logly.COLOR.RED) # with custom color

# Log messages with different levels and colors
logly.info("Key1", "Value1", color=logly.COLOR.CYAN)
logly.warn("Key2", "Value2", color=logly.COLOR.YELLOW)
Expand All @@ -72,6 +75,9 @@ logly.info("AnotherKey1", "AnotherValue1", color=logly.COLOR.CYAN)
logly.warn("AnotherKey2", "AnotherValue2", color=logly.COLOR.YELLOW)
logly.error("AnotherKey3", "AnotherValue3", color=logly.COLOR.RED)


logly.info("hello this is log", color=logly.COLOR.RED,show_time=False) # with custom color and without time

# Start logging again
logly.start_logging()

Expand All @@ -95,8 +101,12 @@ logly.info("Accessing color directly", "DirectColorValue", color=logly.COLOR.RED
# Disable color
logly.color_enabled = False
logly.info("ColorDisabledKey", "ColorDisabledValue", color=logly.COLOR.RED)
logly.info("ColorDisabledKey1", "ColorDisabledValue1", color=logly.COLOR.RED,color_enabled=True) # this will enable the color for this one log message
logly.color_enabled = True
# this will enable the color again
logly.info("ColorDisabledKey1", "ColorDisabledValue1", color=logly.COLOR.RED,color_enabled=False) # this will disable the color for this one log message


# Display logged messages (this will display all the messages logged so far)
print("Logged Messages:")
for message in logly.logged_messages:
Expand Down
36 changes: 18 additions & 18 deletions logly/logly.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def _log(self, level, key, value, color=None, log_to_file=True, file_path=None,
raise FileCreationError(f"Error creating or writing to the log file: {e}")

def log_function(self, level, key_or_value, value=None, color=None, log_to_file=True, file_path=None,
file_name=None, max_file_size=None, auto=True, show_time=None):
file_name=None, max_file_size=None, auto=True, show_time=None,color_enabled=None):
"""
Log a message with exception handling.
Expand All @@ -282,10 +282,10 @@ def log_function(self, level, key_or_value, value=None, color=None, log_to_file=
# If two parameters are provided, consider the first as the key and the second as the value
key = key_or_value

self._log(level, key, value, color, log_to_file, file_path, file_name, max_file_size, auto, show_time)
self._log(level, key, value, color, log_to_file, file_path, file_name, max_file_size, auto, show_time,color_enabled)

def info(self, key_or_value, value=None, color=None, log_to_file=True, file_path=None, file_name=None,
max_file_size=None, auto=True, show_time=None):
max_file_size=None, auto=True, show_time=None,color_enabled=None):
"""
Log a message with the INFO level.
Expand All @@ -302,10 +302,10 @@ def info(self, key_or_value, value=None, color=None, log_to_file=True, file_path
- show_time (bool, optional): Whether to include timestamps in the log message. Defaults to None.
"""
self.log_function("INFO", key_or_value, value, color, log_to_file, file_path, file_name, max_file_size, auto,
show_time)
show_time,color_enabled)

def warn(self, key_or_value, value=None, color=None, log_to_file=True, file_path=None, file_name=None,
max_file_size=None, auto=True, show_time=None):
max_file_size=None, auto=True, show_time=None,color_enabled=None):
"""
Log a message with the WARNING level.
Expand All @@ -322,10 +322,10 @@ def warn(self, key_or_value, value=None, color=None, log_to_file=True, file_path
- show_time (bool, optional): Whether to include timestamps in the log message. Defaults to None.
"""
self.log_function("WARNING", key_or_value, value, color, log_to_file, file_path, file_name, max_file_size, auto,
show_time)
show_time,color_enabled)

def error(self, key_or_value, value=None, color=None, log_to_file=True, file_path=None, file_name=None,
max_file_size=None, auto=True, show_time=None):
max_file_size=None, auto=True, show_time=None,color_enabled=None):
"""
Log a message with the ERROR level.
Expand All @@ -342,10 +342,10 @@ def error(self, key_or_value, value=None, color=None, log_to_file=True, file_pat
- show_time (bool, optional): Whether to include timestamps in the log message. Defaults to None.
"""
self.log_function("ERROR", key_or_value, value, color, log_to_file, file_path, file_name, max_file_size, auto,
show_time)
show_time,color_enabled)

def debug(self, key_or_value, value=None, color=None, log_to_file=True, file_path=None, file_name=None,
max_file_size=None, auto=True, show_time=None):
max_file_size=None, auto=True, show_time=None,color_enabled=None):
"""
Log a message with the DEBUG level.
Expand All @@ -362,10 +362,10 @@ def debug(self, key_or_value, value=None, color=None, log_to_file=True, file_pat
- show_time (bool, optional): Whether to include timestamps in the log message. Defaults to None.
"""
self.log_function("DEBUG", key_or_value, value, color, log_to_file, file_path, file_name, max_file_size, auto,
show_time)
show_time,color_enabled)

def critical(self, key_or_value, value=None, color=None, log_to_file=True, file_path=None, file_name=None,
max_file_size=None, auto=True, show_time=None):
max_file_size=None, auto=True, show_time=None,color_enabled=None):
"""
Log a critical message.
Expand All @@ -383,10 +383,10 @@ def critical(self, key_or_value, value=None, color=None, log_to_file=True, file_
"""
self.log_function("CRITICAL", key_or_value, value, color, log_to_file, file_path, file_name, max_file_size,
auto,
show_time)
show_time,color_enabled)

def fatal(self, key_or_value, value=None, color=None, log_to_file=True, file_path=None, file_name=None,
max_file_size=None, auto=True, show_time=None):
max_file_size=None, auto=True, show_time=None,color_enabled=None):
"""
Log a fatal message.
Expand All @@ -403,10 +403,10 @@ def fatal(self, key_or_value, value=None, color=None, log_to_file=True, file_pat
- show_time (bool, optional): Whether to include timestamps in the log message. Defaults to None.
"""
self.log_function("FATAL", key_or_value, value, color, log_to_file, file_path, file_name, max_file_size, auto,
show_time)
show_time,color_enabled)

def trace(self, key_or_value, value=None, color=None, log_to_file=True, file_path=None, file_name=None,
max_file_size=None, auto=True, show_time=None):
max_file_size=None, auto=True, show_time=None,color_enabled=None):
"""
Log a trace message.
Expand All @@ -423,10 +423,10 @@ def trace(self, key_or_value, value=None, color=None, log_to_file=True, file_pat
- show_time (bool, optional): Whether to include timestamps in the log message. Defaults to None.
"""
self.log_function("TRACE", key_or_value, value, color, log_to_file, file_path, file_name, max_file_size, auto,
show_time)
show_time,color_enabled)

def log(self, key_or_value, value=None, color=None, log_to_file=True, file_path=None, file_name=None,
max_file_size=None, auto=True, show_time=None):
max_file_size=None, auto=True, show_time=None,color_enabled=None):
"""
Log an info message.
Expand All @@ -443,4 +443,4 @@ def log(self, key_or_value, value=None, color=None, log_to_file=True, file_path=
- show_time (bool, optional): Whether to include timestamps in the log message. Defaults to None.
"""
self.log_function("LOG", key_or_value, value, color, log_to_file, file_path, file_name, max_file_size, auto,
show_time)
show_time,color_enabled)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

VERSION = "0.0.3"
VERSION = "0.0.4"

DESCRIPTION = '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.'

Expand Down
Loading

0 comments on commit 1706a20

Please sign in to comment.