GithubHelp home page GithubHelp logo

logger's Introduction

Logger

Logger is a Python class that provides logging functionality. It allows you to create a logger with a specific name, log file, and logging level. It also provides decorators to disable logging, enable debug, time function execution, and tag the start and end of a function.

I made this script for general scripting, trying to utilize the DRY principle. There are some convenience decorators that I used when I didn't have the convenience of a debugger.

Installation

You can install the package directly from GitHub using pip:

pip install git+https://github.com/toann1980/Logger.git

Usage

from pathlib import Path
from logger import Logger

# Create a logger
filename = Path(__file__).stem
logger = Logger(logger_name=filename)
logger.set_logging_level("debug")

# Use the logger
logger.debug('This is an debug message')

Decorators

Logger provides several decorators that can be used to modify the behavior of your functions:

  • @logger.disable_logging: This decorator disables the debug output of the decorated function.
  • @logger.enable_debug: This decorator enables the debug output of the decorated function.
  • @logger.time_function: This decorator measures the execution time of the decorated function and logs the result.
  • @logger.tag_start_end: This decorator adds logging statements to the start and end of the decorated function.

Example

In this example, my_function will log its execution time and a start and end message.

from pathlib import Path
from logger import Logger

# Create a logger
filename = Path(__file__).stem
logger = Logger(logger_name=filename)
logger.set_logging_level("debug")

class MyClass:
    def __init__(self):
        pass

    @logger.time_function
    @logger.tag_start_end
    def my_function(self):
        logger.info('This is an info message')

my_class = MyClass()
my_class.my_function()

Contributing

If you want to contribute to this project, please feel free to fork the repository, make your changes, and open a pull request. I appreciate any contributions!

logger's People

Contributors

toann1980 avatar

Watchers

 avatar

logger's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.