Giter Site home page Giter Site logo

bioinfo-genome's People

Contributors

thomasbyr avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

bas6700

bioinfo-genome's Issues

proper logging

I may (or may not) change the way we log shit to stdout/stderr
Hopefully this wont break the proxied threads ๐Ÿ˜‡

import os

from dotenv import load_dotenv

import logging
from typing_extensions import override
from termcolor import colored

__all__ = ['logger', 'log_lvl', 'console_handler', 'default_formatter']


def formatter(c: str, attrs: list[str] = []) -> str:
  return f"{colored('%(asctime)s', 'grey', attrs=['bold'])} {colored('%(levelname)8s', c, attrs=attrs)} {colored('%(name)s', 'magenta')} (%(filename)s:%(lineno)d) %(message)s"


class UsefulFormatter(logging.Formatter):

  dt_fmt = '%Y-%m-%d %H:%M:%S'
  FORMATS = {
    logging.DEBUG: formatter('green'),
    logging.INFO: formatter('blue'),
    logging.WARNING: formatter('yellow'),
    logging.ERROR: formatter('red'),
    logging.CRITICAL: formatter('red', ['bold']),
  }

  @override
  def format(self, record: logging.LogRecord) -> str:
    log_fmt = self.FORMATS.get(record.levelno)
    formatter = logging.Formatter(log_fmt, self.dt_fmt, style='%')
    return formatter.format(record)


load_dotenv()
DEBUG = os.getenv('DEBUG', 'False').lower() in {'true', '1', 'yes'}

logger = logging.getLogger('me ๐Ÿ™‚')
logger.setLevel(log_lvl := logging.DEBUG if DEBUG else logging.INFO)

# create console handler with a higher log level
console_handler = logging.StreamHandler()
console_handler.setLevel(log_lvl)
console_handler.setFormatter(default_formatter := UsefulFormatter())

logger.addHandler(console_handler)

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.