Git Product home page Git Product logo

logme's Introduction

Logme - Python Logging for Humans

https://travis-ci.org/BNMetrics/logme.svg?branch=master Documentation Status

Logme is a Python package that makes logging simple and robust. If you have found logging in Python not so straight forward, download this package and give it a try! :)

V1.3.0 Updates

logme.ini file now supports custom datefmt and style! Thanks to @afunTW suggestion! :)

Here is an example of how you can specify these parameters in your logme.ini configuration:

[my_config]
level = DEBUG
formatter =
    fmt: {asctime} - {name} - {levelname} - {message}
    datefmt: %Y/%m/%d
    style: {
stream =
    type: StreamHandler
    active: True
    level: DEBUG
file =
    type: FileHandler
    active: True
    level: DEBUG
    formatter: {name} :: {funcName} :: {levelname} :: {message}
    filename: mylogpath/foo.log

Note: Only top level master_formatter supports parameters as shown above, individual handler formatter will not.

Terminal Color Output

logme supports color and styling output in the terminal!

The colors and style is customizable in logme.ini, here is a screenshot of how it looks like in the terminal:

http://logme.readthedocs.io/en/latest/_images/demo_color.png

To use color output in logme, make sure your logme package and logme.ini is up-to-date if you are using a version before 1.2.0.

Check the configuration details here.

In A Nutshell

If you have a function you want to log, you can do this in your python file:

import logme


@logme.log
def my_awesome_function(my_arg, logger=None):
    logger.info('this is my log message')
    """rest of the function"""

You can do the same with classes too:

import logme


@logme.log
class MyAwesomeClass:
    def my_function(self, my_arg):
        self.logger.info('this is my log message')

pretty nice right? :)

To get started, head to the quickstart page.

Installing Logme

$ pipenv install logme
โœจ๐Ÿฐโœจ

Documentation

You can find the documentation at https://logme.readthedocs.io/en/latest/ . Give it a try!

logme's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

logme's Issues

consider self.log

...
    self.log.info('something')

might be nice. would need to keep self.logger, though, for already-dependent libs.

Add demo gif to README

Disclaimer: This is a bot

It looks like your repo is trending. The github_trending_videos Instgram account automatically shows the demo gifs of trending repos in Github.

Your README doesn't seem to have any demo gifs. Add one and the next time the parser runs it will pick it up and post it on its Instagram feed. If you don't want to just close this issue we won't bother you again.

Missing `ini` file causes RecursionError: maximum recursion depth exceeded while calling a Python object

When attempting to use logme for a simple Python script without calling logme init or having an ini file, it appears that the configuration resolving code goes into an infinite recursion. Relevant part of stack below:

  File "/Users/groodt/dev/data-science/.direnv/python-3.6.2/lib/python3.6/site-packages/logme/utils.py", line 117, in get_ini_file_path
    return get_ini_file_path(Path(caller_file_path).parent)
  File "/Users/groodt/dev/data-science/.direnv/python-3.6.2/lib/python3.6/site-packages/logme/utils.py", line 117, in get_ini_file_path
    return get_ini_file_path(Path(caller_file_path).parent)
  [Previous line repeated 978 more times]
  File "/Users/groodt/dev/data-science/.direnv/python-3.6.2/lib/python3.6/site-packages/logme/utils.py", line 113, in get_ini_file_path
    Path(caller_file_path).home().resolve()]:
  File "/Users/groodt/.pyenv/versions/3.6.2/lib/python3.6/pathlib.py", line 1040, in home
    return cls(cls()._flavour.gethomedir(None))
  File "/Users/groodt/.pyenv/versions/3.6.2/lib/python3.6/pathlib.py", line 979, in __new__
    self = cls._from_parts(args, init=False)
  File "/Users/groodt/.pyenv/versions/3.6.2/lib/python3.6/pathlib.py", line 654, in _from_parts
    drv, root, parts = self._parse_args(args)
  File "/Users/groodt/.pyenv/versions/3.6.2/lib/python3.6/pathlib.py", line 647, in _parse_args
    return cls._flavour.parse_parts(parts)
  File "/Users/groodt/.pyenv/versions/3.6.2/lib/python3.6/pathlib.py", line 56, in parse_parts
    it = reversed(parts)
RecursionError: maximum recursion depth exceeded while calling a Python object

Now, I'd love to help fix the problem. Is it as simple as the precondition on line 112 being incorrect?

if caller_file_path in [Path(Path(caller_file_path).root).resolve(),
                            Path(caller_file_path).home().resolve()]:
        raise ValueError(f"logme.ini does not exist, please use 'logme init' command in your project root.")

Should this be checking if not conf_path in ...
?

global logging

I see its possible to use inside a function or class, but is it possible at
global level? other projects offer this:

from logzero import logger
logger.info('abcde')
logger.warning('abcde')
logger.error('abcde')

Cannot import logme on ubuntu 16.04

lsb_release -a

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.5 LTS
Release: 16.04
Codename: xenial

pip install --upgrade logme

Requirement already up-to-date: logme in /usr/local/lib/python3.5/dist-packages (1.3.0)
Requirement already satisfied, skipping upgrade: bnmutils in /usr/local/lib/python3.5/dist-packages (from logme) (1.0.2)
Requirement already satisfied, skipping upgrade: click in /usr/local/lib/python3.5/dist-packages (from logme) (7.0)

python3.5

Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.

import logme
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.5/dist-packages/logme/init.py", line 53
raise MisMatchScope(f"{callable_} is a class, cannot be assigned to a '{scope}' scope")
^
SyntaxError: invalid syntax

TypeError: 'PosixPath' object is not iterable

I get this error "TypeError: 'PosixPath' object is not iterable"
The file logme.ini is added into the root folder of the project.
Here is the error trace:

File "/opt/app/pip/logme/__init__.py", line 34, in log
  return _get_logger_decorator(scope, config=config, name=name)
File "/opt/app/pip/logme/__init__.py", line 63, in _get_logger_decorator
  provider = LogProvider(callable_, config=config, name=name)
File "/opt/app/pip/logme/providers.py", line 40, in __init__
  config_dict = get_logger_config(module_obj.__file__, name=config)
File "/opt/app/pip/logme/utils.py", line 67, in get_logger_config
  return get_config_content(caller_file_path, name=name)
File "/opt/app/pip/logme/utils.py", line 94, in get_config_content
  config = ConfigParser.from_files(init_file_path)
File "/opt/app/pip/bnmutils/configparser.py", line 29, in from_files
  obj.read(filenames, encoding)
File "/opt/app/pip/backports/configparser/__init__.py", line 702, in read
  for filename in filenames:
TypeError: 'PosixPath' object is not iterable

logme in not Thread Safe

While inside a daemon python thread log me will output twice:

  1. Good Log - with colors and the correct format -> {asctime} - {name} - {levelname} - {message}
  2. Bad log: without colors and bad format -> {levelname}:{name}:{message}

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.