Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ftp-setup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ name: FTP Setup
on:
workflow_call:
workflow_dispatch:
workflow_run:
branches: [main]
types: [completed]
workflows: [CI]
# workflow_run:
# branches: [main]
# types: [completed]
# workflows: [CI]

env:
dir: tmp
Expand Down
4 changes: 0 additions & 4 deletions docs/temp.md

This file was deleted.

3 changes: 3 additions & 0 deletions docs/utilities.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# PyPackage

::: src.utilities
4 changes: 1 addition & 3 deletions mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ copyright: MIT License - Copyright (c) 2023 Sébastien Menard

nav:
- Home: index.md
- Temp: temp.md
- Temp: temp.md
- Temp: temp.md
- Utilities: utilities.md

plugins:
- mkdocstrings # generate from docstrings
Expand Down
1 change: 1 addition & 0 deletions src/utilities/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Package Utilities."""
120 changes: 120 additions & 0 deletions src/utilities/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
"""Module Logger."""


from __future__ import annotations

import logging
import sys


class Logger:
"""Interface representing logger utilities."""

def __init__(
self: Logger,
*,
debugging: bool = False,
tracing: bool = False,
newline: bool = True,
) -> None:
"""Initiate a logger.

Parameters
----------
debugging : bool, optional
Set logging level to DEBUG otherwise INFO, by default False
tracing : bool, optional
Trace method calls when using _trace, by default False
newline : bool, optional
Add a new line between logs, by default True
"""
formatter = "%(name)s:%(levelname)s => %(msg)s" + "\n" if newline else ""

handler = logging.StreamHandler()
handler.setFormatter(fmt=logging.Formatter(fmt=formatter))

logger = logging.getLogger(name="LOG")
logger.addHandler(hdlr=handler)
logger.setLevel(level=logging.DEBUG if debugging else logging.INFO)

self.logger = logger
self.debugging = debugging
self.tracing = tracing
self.newline = newline

def debug_(self: Logger, msg: str) -> None:
"""Log a message with severity DEBUG.

Parameters
----------
msg : str
The message to display.
"""
self.logger.debug(msg=msg)

def warn_(self: Logger, msg: str) -> None:
"""Log a message with severity WARN.

Parameters
----------
msg : str
The message to display.
"""
self.logger.warning(msg=msg)

def info_(self: Logger, msg: str) -> None:
"""Log a message with severity INFO.

Parameters
----------
msg : str
The message to display.
"""
self.logger.info(msg=msg)

def error_(self: Logger, msg: str) -> None:
"""Log a message with severity ERROR.

Parameters
----------
msg : str
The message to display.
"""
self.logger.error(msg=msg)

def critical_(self: Logger, msg: str) -> None:
"""Log a message with severity CRITICAL.

Parameters
----------
msg : str
The message to display.
"""
self.logger.critical(msg=msg)

def trace_(self: Logger, msg: str | None = None) -> None:
"""Log a message with severity 'DEBUG' to trace methods call.

Parameters
----------
msg : str | None, optional
The message to display, by default None.
"""
if not self.tracing:
return

frame = sys._getframe(1) # noqa: SLF001

message = "TRACE"

# Trace class name if method is from a class
if "self" in frame.f_locals:
message += f" - CLASS {frame.f_locals['self'].__class__.__name__}"

# Trace method name
message += f" - METHOD {frame.f_code.co_name}"

if msg is not None:
message += f" - {msg}"

self.info_(msg=f"{message}")