Coder Social home page Coder Social logo

Comments (2)

sdhutchins avatar sdhutchins commented on August 11, 2024

See #12, @ksolie.

Also, my implementation is below.

"""Main logging class to make logging easier."""
import os
import sys
from logzero import setup_logger, LogFormatter, logging, colors


class LogIt(object):
    """LogIt makes logging easier by creating easy loggers."""

    def __init__(self):
        """Initialize the logger format based on system platform."""
        # Set the different formats based on user's platform
        if sys.platform == 'win32':
            self._archive_format = '%m-%d-%Y_%I-%M-%p'
        elif sys.platform == 'linux':
            self._archive_format = '%m-%d-%Y@%I:%M:%S-%p'

        self._date_format = '%b-%d-%Y at %I:%M:%S %p'  # Used to add date
        self._log_format = ("%(color)s[%(levelname)s | %(name)s] [%(asctime)s | "
                            "%(module)s - line %(lineno)d]:%(end_color)s %(message)s")
        self._formatter = LogFormatter(fmt=self._log_format,
                                       datefmt=self._date_format)

        # Add a color for the critical level
        self._formatter.DEFAULT_COLORS[50] = colors.Fore.LIGHTRED_EX
        # Changed color for the debug level
        self._formatter.DEFAULT_COLORS[10] = colors.Fore.LIGHTBLUE_EX
        self.logging = logging

    def default(self, logname, logfile):
        """Create a log handler using default formatting.
        :param logname: Name of the log.
        :param logfile: Path to the logfile. Can be `None`.
        :return: A default_log object is returned.
        """

        default_log = setup_logger(name=logname.upper(), logfile=logfile,
                                   level=logging.DEBUG,
                                   formatter=self._formatter)

        assert isinstance(default_log, object)
        return default_log

from logzero.

metachris avatar metachris commented on August 11, 2024

Fixed in #339

from logzero.

Related Issues (20)

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.