Skip to main content

A logger class, and a decorator that works with that class for python

Project description

loggerV

A logger class, and a decorator that works with that class for python

Installation

Use the package manager pip to install loggerV.

pip install loggerV

Basic Usage

from loggerV.logger import Logger


# Creates an instance of class Logger
logger = Logger("Logger")

logger.append(
    step="First Log",
    message="Testing",
    success=True,
)

Advanced Usage

from loggerV.logger import Logger
from loggerV.logger import funcLogger


# Create a custom dataclass to use in the logger
class Example:
    def __init__(self, one, two) -> None:
        self.one = one
        self.two = two


# Create a new instance of the Logger class
logger = Logger(name="Logger")


# A method decorated with the funcLogger method. It accepts the logger as an argument.
# fail is what precedence the logger should use if the decorated functions fails. (Optional)
# success is what precedence the logger should use if the decorated function succeeds. (Optional)
# run is what level of logging to use. 0: no loging, even if it fails. 1: log if the function fails. 2: log whether it failsor succeeds
@funcLogger(logger)
def convert(string, run=0, fail=None, success=None):
    return int(string)


# Load the custom class so that it can be used in the logger
logger.loadCustom(
    names=["fieldOne", "fieldTwo"],
    printValues=["One", "Two"],
    defaults=None,
    dontPrintIf=None,
)

# The way partitions work is that each partition has a precedence. There are two partitions by default. main with a precedence of 3 and footer with a precedence of ten.
# Partitions and precedence can be created through the below method, and can be used in the append function. by default append uses partition main (3). 
# Logs in the same partition are ordered by first come first serve
logger.addPartition(name="first", precedence=1)


# Create a new Log
logger.append(
    step="First Log",
    message="Testing",
    custom=Example(
        one="Hello", two="World"
        ),
    success=True,
    partition="main",
)
logger.append("Second Log", "Testing", success=False, partition=1)
logger.append("Third Log")

print(logger)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

loggerv-1.0.2.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

loggerv-1.0.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file loggerv-1.0.2.tar.gz.

File metadata

  • Download URL: loggerv-1.0.2.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for loggerv-1.0.2.tar.gz
Algorithm Hash digest
SHA256 2ba1d2d3b7c9901dcb4373b8c0d5062547972fea22b2d796480ae90adb790234
MD5 1daa560562c210766d22635043218be4
BLAKE2b-256 d5fbbe7958b25a561645b5454481f52873c458f24c331847112c5c5c8eb0f20c

See more details on using hashes here.

File details

Details for the file loggerv-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: loggerv-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for loggerv-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6362835ba6bccfb8058cfa57f51f3683b5e20e927ef948d68b9edbd74c2018db
MD5 3618e6143936fa4e3a5a45c292d679c0
BLAKE2b-256 a0c9f5e74fbfab5466864f34bbd779cef5baf49d138082174169c43bea2ea0ce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page