Skip to content

Commit

Permalink
Refactor Logger class message method to improve readability and add t…
Browse files Browse the repository at this point in the history
…imer functionality
  • Loading branch information
sexfrance committed Oct 27, 2024
1 parent 04ab042 commit 239df88
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 2 additions & 4 deletions logmagix/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ def warning(self, message: str, start: int = None, end: int = None, level: str =

def message(self, level: str, message: str, start: int = None, end: int = None) -> None:
time = self.get_time()
if start is not None and end is not None:
print(f"{self.prefix}[{self.MAGENTAA}{time}{self.PINK}] {self.PINK}[{self.CYAN}{level}{self.PINK}] -> {Fore.RESET} {self.CYAN}{message}{Fore.RESET} [{Fore.CYAN}{end - start}s{Style.RESET_ALL}]")
else:
print(f"{self.prefix}[{self.MAGENTAA}{time}{self.PINK}] [{Fore.BLUE}{level}{self.PINK}] -> {Fore.RESET} {self.CYAN}{message}{Fore.RESET}")
timer = f" {self.MAGENTAA}In{self.WHITE} -> {self.MAGENTAA}{str(end - start)[:5]} Seconds" if start and end else ""
print(f"{self.prefix}[{self.MAGENTAA}{time}{self.PINK}] [{self.CYAN}{level}{self.PINK}] -> [{self.CYAN}{message}{self.PINK}]{timer}")

def message2(self, level: str, message: str, start: int = None, end: int = None) -> None:
time = self.get_time()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="logmagix",
version="1.0.5",
version="1.0.6",
packages=find_packages(),
install_requires=["colorama"],
author="Sexfrance",
Expand Down
4 changes: 4 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
import uuid

log = Logger(prefix="custom/log/prefix")
start_time = time.time()

# Log messages
log.success("Everything is running smoothly!")
log.warning("Watch out, something might happen!")
log.failure("Critical error occurred!")
log.info("System is working properly")
log.debug(f"The system uuid is {uuid.getnode()}")
log.message("Dad", f"How are you? I'm gonna come soon!", start=start_time, end=time.time())
log.question("How old are you? ")


# Use loader with custom prefix and context manager
with Loader(prefix="custom/loader/prefix", desc="Processing data..."):
time.sleep(2) # Simulate task
Expand All @@ -33,4 +36,5 @@

home_screen.display()


log.success("Processing completed!")

0 comments on commit 239df88

Please sign in to comment.