Skip to content

Commit

Permalink
Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
wfxey committed Nov 27, 2024
1 parent bf62088 commit 8aea234
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pip install insightlog
import insightlog

# Create an instance of InsightLogger
log_instance = insightlog.setup(name="MyApp", log_filename="C:/path/to/logs/myapp.log")
log_instance = insightlog.setup(name="MyApp")

# Logging examples
log_instance.success("This is a success log.")
Expand Down
44 changes: 21 additions & 23 deletions insightlog/main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import logging
import datetime
import os
from logging.handlers import RotatingFileHandler
from termcolor import colored
from tqdm import tqdm
import random
import time
import itertools
from tqdm import tqdm
from logging.handlers import RotatingFileHandler
from termcolor import colored


def start_logging(name, save_log, log_dir="./logs", log_filename=None, max_bytes=1000000, backup_count=1, log_level=logging.DEBUG):
def start_logging(name, save_log="disabled", log_dir="./logs", log_filename=None, max_bytes=1000000, backup_count=1, log_level=logging.DEBUG):
logger = logging.getLogger(name)

if not logger.hasHandlers():
Expand All @@ -19,35 +19,33 @@ def start_logging(name, save_log, log_dir="./logs", log_filename=None, max_bytes
if not os.path.isdir(log_dir):
try:
os.mkdir(log_dir)
logger.debug(f"Log directory created at {log_dir}")
print(f"Log directory created at {log_dir}")
except Exception as e:
logger.error(f"Failed to create log directory: {e}")
print(f"Failed to create log directory: {e}")
raise

if log_filename is None:
timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
log_filename = f"{log_dir}/{timestamp}-app.log"

try:
file_handler = RotatingFileHandler(log_filename, maxBytes=max_bytes, backupCount=backup_count)
file_handler.setLevel(log_level)
file_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
file_handler.setFormatter(file_formatter)
logger.addHandler(file_handler)
except Exception as e:
logger.error(f"Failed to set up file handler: {e}")
raise
log_filename = os.path.join(log_dir, f"{timestamp}-app.log")

try:
file_handler = RotatingFileHandler(log_filename, maxBytes=max_bytes, backupCount=backup_count)
file_handler.setLevel(log_level)
file_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
file_handler.setFormatter(file_formatter)
logger.addHandler(file_handler)
except Exception as e:
print(f"Failed to set up file handler: {e}")
raise

console_handler = logging.StreamHandler()
console_handler.setLevel(log_level)
console_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
console_handler.setFormatter(console_formatter)

logger.addHandler(file_handler)
logger.addHandler(console_handler)

logger.debug(f"Logging initialized. Log file: {log_filename}")
logger.debug(f"Logging initialized. Log file: {log_filename if save_log == 'enabled' else 'None'}")

return logger


Expand Down Expand Up @@ -236,7 +234,7 @@ def spin_animation(self, duration=5):

if __name__ == "__main__":
try:
log_instance = CustomLogger(log_level=logging.DEBUG)
log_instance = CustomLogger(name="Hii")

log_instance.success("This is a success log.")
log_instance.failure("This is a failure log.")
Expand All @@ -263,4 +261,4 @@ def spin_animation(self, duration=5):
log_instance.spin_animation(duration=5)

except Exception as e:
logging.error(f"Fehler bei der Initialisierung des Loggers: {e}")
logging.error(f"Fehler bei der Initialisierung des Loggers: {e}")
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='InsightLog',
version='1.0',
version='1.1',
packages=find_packages(),
license='MIT',
description='A better logging utility with enhanced features.',
Expand All @@ -14,7 +14,7 @@
long_description=long_description,
long_description_content_type="text/markdown",
url='https://github.com/Eldritchy/InsightLog',
download_url='https://github.com/Eldritchy/InsightLog/archive/refs/tags/v1.0.tar.gz',
download_url='https://github.com/Eldritchy/InsightLog/archive/refs/tags/v1.1.tar.gz',
keywords=[
'eldritchy', 'logging', 'log', 'logger', 'better', 'utility', 'developer tools'
],
Expand Down

0 comments on commit 8aea234

Please sign in to comment.