Code Monkey home page Code Monkey logo

logzero's Introduction

logzero

Build status for master branch Documentation Status Latest version on PyPi Anaconda-Server Badge Downloads

Robust and effective logging for Python 2 and 3.

Logo

Features

  • Easy logging to console and/or (rotating) file.
  • Provides a fully configured standard Python logger object.
  • JSON logging (with integrated python-json-logger)
  • Pretty formatting, including level-specific colors in the console.
  • No dependencies
  • Windows color output supported by colorama
  • Robust against str/bytes encoding problems, works with all kinds of character encodings and special characters.
  • Multiple loggers can write to the same logfile (also across multiple Python files and processes).
  • Global default logger with logzero.logger and custom loggers with logzero.setup_logger(..).
  • Compatible with Python 2 and 3.
  • All contained in a single file.
  • Licensed under the MIT license.
  • Heavily inspired by the Tornado web framework.

Installation:

python -m pip install logzero

Example Usage

from logzero import logger

logger.debug("hello")
logger.info("info")
logger.warning("warn")
logger.error("error")

# This is how you'd log an exception
try:
    raise Exception("this is a demo exception")
except Exception as e:
    logger.exception(e)

# JSON logging
import logzero
logzero.json()

logger.info("JSON test")

# Start writing into a logfile
logzero.logfile("/tmp/logzero-demo.log")

# Set a minimum loglevel
logzero.loglevel(logzero.WARNING)

This is the output:

demo-output

Note: You can find more examples in the documentation: https://logzero.readthedocs.io

JSON logging

JSON logging can be enabled for the default logger with logzero.json(), or with setup_logger(json=True) for custom loggers:

>>> logzero.json()
>>> logger.info("test")
{"asctime": "2020-10-21 10:42:45,808", "filename": "<stdin>", "funcName": "<module>", "levelname": "INFO", "levelno": 20, "lineno": 1, "module": "<stdin>", "message": "test", "name": "logzero_default", "pathname": "<stdin>", "process": 76179, "processName": "MainProcess", "threadName": "MainThread"}

>>> my_logger = setup_logger(json=True)
>>> my_logger.info("test")
{"asctime": "2020-10-21 10:42:45,808", "filename": "<stdin>", "funcName": "<module>", "levelname": "INFO", "levelno": 20, "lineno": 1, "module": "<stdin>", "message": "test", "name": "logzero_default", "pathname": "<stdin>", "process": 76179, "processName": "MainProcess", "threadName": "MainThread"}

The logged JSON object has these fields:

{
  "asctime": "2020-10-21 10:43:40,765",
  "filename": "test.py",
  "funcName": "test_this",
  "levelname": "INFO",
  "levelno": 20,
  "lineno": 9,
  "module": "test",
  "message": "info",
  "name": "logzero",
  "pathname": "_tests/test.py",
  "process": 76204,
  "processName": "MainProcess",
  "threadName": "MainThread"
}

Exceptions logged with logger.exception(e) have these additional JSON fields:

{
  "levelname": "ERROR",
  "levelno": 40,
  "message": "this is a demo exception",
  "exc_info": "Traceback (most recent call last):\n  File \"_tests/test.py\", line 15, in test_this\n    raise Exception(\"this is a demo exception\")\nException: this is a demo exception"
}

Take a look at the documentation for more information and examples:

Installation

Install logzero with pip:

python -m pip install logzero

Here's how you setup a virtualenv and download and run the demo:

# Create and activate a virtualenv in ./venv/
python3 -m venv venv
. venv/bin/activate

# Install logzero
python -m pip install logzero

# Download and run demo.py
wget https://raw.githubusercontent.com/metachris/logzero/master/examples/demo.py
python demo.py

If you don't have pip installed, this Python installation guide can guide you through the process.

Alternatively, if you use the Anaconda distribution:

$ conda config --add channels conda-forge
$ conda install logzero

You can also install logzero from the public Github repo:

$ git clone https://github.com/metachris/logzero.git
$ cd logzero
$ python setup.py install

Contributors


Development

Getting started

$ git clone https://github.com/metachris/logzero.git
$ cd logzero

# Activate virtualenv
$ python3 -m venv venv
$ . venv/bin/activate

# Install main and dev dependencies
$ pip install -e .
$ pip install -r requirements_dev.txt

# Run the tests
$ make test

# Run the linter
$ make lint

# Generate the docs (will auto-open in Chrome)
$ make docs

# You can enable watching mode to automatically rebuild on changes:
$ make servedocs

To test with Python 2.7, you can use Docker:

docker run --rm -it -v /Users/chris/stream/logzero:/mnt python:2.7 /bin/bash

Now you have a shell with the current directory mounted into /mnt/ inside the container.

Notes


Changelog

See the changelog here: https://github.com/metachris/logzero/blob/master/HISTORY.md

Feedback

All kinds of feedback and contributions are welcome.

logo

logzero's People

Contributors

carlodri avatar christianscott avatar delirious-lettuce avatar dmartin35 avatar lumbric avatar metachris avatar pyup-bot avatar sebix avatar sitischu avatar

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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

logzero's Issues

logging to file only

Hi,

Is there a way to log to file only.

So I taught the level is the log level for the console and fileLoglevel is the level for the file. If I set
this here:

my_logger = setup_logger(logfile=path, maxBytes=1024 * 1024, backupCount=3, level=logging.ERROR,
                                         fileLoglevel=logging.INFO)

it dose not work. I use
my_logger.info(...

but nothing is printed to the file. So there is something wrong with level and file level I think.

So I would like to use logzero as a file logger only parallel to the the normal python logger. Do you see any problem here?

cheers
mathias

Date Format Missing

  • logzero version: 1.5.0
  • Python version: 3.6.6
  • Operating System: Mac OS

Description

Describe what you were trying to get done.
Logs to have Date with the separator like 2018-09-03
Tell us what happened, what went wrong, and what you expected to happen.
Logs does not contain separator like 180903

What I Did

log_format = '%(color)s[%(levelname)-5.5s %(asctime)-15s %(module)s:%(lineno)d]%(end_color)s %(message)s'

[Feature Request] Set Loglevel across multiple files

  • logzero version:
  • Python version: 3.6
  • Operating System: Windows and Linux

Description

I am trying to use logzero for a medium-scale project. However, I find it unnecessary that I have to manually change the loglevel for all the files when switching from debugging to runtime and vice-versa. It would be convenient if we could set the default loglevel in the main file (for instance) and all the other files would use the value set by the main file.

Is time rotating logging supported in logzero?

  • logzero version: 1.5.0
  • Python version: 2.7.14
  • Operating System: CentOS 7 / Windows 7

Description

Is time rotating logging supported in logzero?
I read some source code and it seems there is no time rotating logging.
Will it be a new feature in later version? Thank you.

how to use on module level?

Hi,

Normally I use

_logger = logging.getLogger(__name__)

on every python module so.

How can I switch to logzero? I am missing the name

thx

Function 'logfile' assumes that filename is a string

  • logzero version: 1.7.0
  • Python version: 3.9.9
  • Operating System: Windows 10

Description

in line 406 of 'init.,py' the function

def logfile(filename, ...

defines filename as a string (line 423)

  :arg string filename: Filename of the logfile. Set to `None` to disable logging to the logfile.

This causes problem with type checking, if you pass a Path (from python's pathlib), which is becoming more popular.

What I Did

Set a logfile using a pathlib Path

logzero.logfile(Path(LOGPATH, f"{mylog}.log"), maxBytes=1e6, backupCount=30)

I used PyCharm's "inspect code" feature and it flags this line as a type error.

Can you officially accept pathlib paths as a valid input so that type checking will work?

Can we log to database?

Is there a way to redirect logs to a database? Bonus points if we can use SQLAlchemy or Django ORM.

Use logzero as root_logger.

  • logzero version:1.5
  • Python version:3.6
  • Operating System:Linux

Description

As I wanted to use parent logger of each setup_logger instance, I tried to find the way to do it.

Buf default logzero setting is not what I intend to use for. The default is not inherited any instance of 'setup_logger'.

What I Did

import logzero
logzero.__name__ = ''
logzero.setup_logger()

When I executed the code above, I've used it as root_logger. And stopped using setup_logger. I used logger.get_logger('name') instead. Then, finally I got it work as I supposed to do.

Suggestion

I think it's not bad idea to describe how to use logzero as rootlogger in README or make a method to do this. I just would like to leave it in case someone else try to do the same thing.

To do & Feature ideas 💡

To do:

  • Documentation strategy - currently the detail docs are in RST format and hosted on readthedocs. The docs would need a refreshing, to make sure it's all up to date and everything is working as intended. Thought: maybe better as markdown docs on GitHub, so we can more easily copy code between the README and other places?

This is an incomplete (and growing) list of possible features to implement:


Please comment to add more, as well as to indicate interest.

[RFE] - Create directory structure, if it doesn't exist

  • logzero version: 1.5.0
  • Python version: 3.6.6
  • Operating System: Fedora 28

Description

When passing in a log path, that doesn't exist, logzero will fail with a FileNotFoundError.
Instead, logzero should attempt to create the parent directories.

What I Did

tried to pass a relative path logs/clix.log to the logzero.logfile method. since logs didn't yet exist, the method failed with:

...
File "/usr/lib64/python3.6/logging/__init__.py", line 1060, in _open
    return open(self.baseFilename, self.mode, encoding=self.encoding)
FileNotFoundError: [Errno 2] No such file or directory: '/home/jake/Programming/clix/logs/clix.log'

Workaround

Add two lines to whatever file you use to init logzero. I believe this requires python 3.5+. You can always use os to do the same thing on older versions of python.

from pathlib import Path
...
Path(log_path).parent.mkdir(parents=True, exist_ok=True)

How to setup logger for GUnicorn?

  • logzero version: 1.5.0
  • Python version: 2.7.14
  • Operating System: Debian

Description

I am running a flask app behind a gunicorn in a docker container.
But I have no idea how to make logzero to get the gunicorn log in the log file

What I Did

Here is my code:

def get_logger():
    from spa_manager import spa_config
    logger_format = spa_config["LOGGER_FORMAT"]
    logger_abs_path = spa_config["LOGGER_ABS_PATH"]
    logzero.logfile(logger_abs_path, maxBytes=5*1024*1024, backupCount=10)
 # I setup sqlalchemy logger to record SQL info. It works.
    logzero.setup_logger(name="sqlalchemy.engine", logfile=logger_abs_path, formatter=logging.Formatter(spa_config["LOGGER_FORMAT"]))
# Here I tried to setup gunicorn log , not work.
    logzero.setup_logger(name="gunicorn.error", logfile=logger_abs_path, formatter=logging.Formatter(spa_config["LOGGER_FORMAT"]))
    formatter = logging.Formatter(logger_format)
    logzero.formatter(formatter)
    return logger

log content when subprocess.Popen another Python code file

  • logzero version: 1.5.0
  • Python version: 3.6.5
  • Operating System: Windows 7 Professional

Similar issues: #57 #222

Description

In code file pgm_a.py, I use subprocess.Popen to execute python.exe with code file pgm_b.py. Both pgm_a.py and pgm_b.py use logzero (default logger with logfile setup).

The log file pgm_b.log for pgm_b.py looks fine.

The log file pgm_a.log for pgm_a.py includes two copies of log content for pgm_b.py, which is not I expected.

My understanding is, default logger configuration have log content to standard output (screen) and output to file with same content. Even log content of pgm_b.py were generated by another python.exe executed from subprocess.Popen, logzero still collect them (both of them) into pgm_a.log.

What I Did

I tried to set up logger for pgm_b.py using

mylogger=logzero.setup_logger(name="mylogger", logfile=mylog, disableStderrLogger=True)

It looks mylogger has different data structure than logger_default, which may affect other part of code.

[I 190806 17:31:43 process:613] General information:
    
    CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
    C
    C    COMPUTERNAME: ********
    C
    CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
    
[I 190806 17:31:43 process:210]  NOTICE:::*** Processing Started for Client 000.
    
[D 190806 17:31:43 process:430] Start sending email with Subject: NOTICE:::*** Processing Started for Client 000....
[D 190806 17:31:43 process:435] Sent email successfully
    
[I 190806 17:31:43 process:247] Start 1-th Python process pgn_b.py test 3 arg.
[D 190806 17:31:43 process:464] ***\python.exe -B ***\pgm_b.py test 3 arg
[D 190806 17:31:43 process:475] 
[D 190806 17:31:43 process:477] '***'

    CMD.EXE was started with the above path as the current directory.

    UNC paths are not supported.  Defaulting to Windows directory.

    [I 190806 17:31:43 startup:10] AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

    [I 190806 17:31:43 startup:11] Auto code file: ***\startup.py

    [I 190806 17:31:43 startup:12] AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
[I 190806 17:31:43 process:479] python code file pgm_a.py result is '***'

    CMD.EXE was started with the above path as the current directory.

    UNC paths are not supported.  Defaulting to Windows directory.

    [I 190806 17:31:43 startup:10] AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

    [I 190806 17:31:43 startup:11] Auto code file: ***\startup.py

    [I 190806 17:31:43 startup:12] AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
[I 190806 17:31:43 process:260] result:NO Issues:
    
[I 190806 17:31:43 process:363] *** pgm_a.py finished at 20190806 17:31

Is there a way in logger_default to switch disableStderrLogger to be True/False directly, instead of using logzero.setup_logger?

logzero is listed in the openSUSE packages but can't seem to install them

As noted in #21, logzero is listed in the openSUSE packages:

I tried in Docker with openSUSE 42.2, but can't seem to install the packages:

# zypper install python2-logzero
Loading repository data...
Reading installed packages...
'python2-logzero' not found in package names. Trying capabilities.
No provider of 'python2-logzero' found.

@sebix any idea?

upload on conda-forge

Hi @metachris, I was wondering if you were interested in uploading the package on conda-forge, which, as you probably know, is a widespread package managing system. If you agree, I can prepare the feedstock recipe.

setup_logger() with level set cannot be changed

  • logzero version: 1.5.0
  • Python version: 3.7.7
  • Operating System: MacOS 10.14.6

Description

I'm using a logging instance of loguru and recognized that this instance does not display messages of a lower value than originally set with level, even though .setLevel has set the new the level. See example below.

What I Did

>>> from logzero import setup_logger
>>> import logging
>>> logfix = setup_logger(level=logging.INFO)
>>> logfix.debug("I'm a debug message")  # expected
>>> logfix.info("I'm an info message")  # expected
[I 200312 21:04:09 <stdin>:1] I'm an info message
>>> logfix.setLevel(logging.DEBUG)
>>> logfix.level
10
>>> logfix.debug("I'm a debug message!")  # NOT expected
>>> logfix.info("I'm an info message!")
[I 200312 21:04:54 <stdin>:1] I'm an info mesasge!
>>> logfix2 = setup_logger()
>>> logfix2.setLevel(logging.INFO)
>>> logfix2.debug("Debug")
>>> logfix2.info("Info")
[I 200312 21:05:38 <stdin>:1] Info
>>> logfix2.setLevel(logging.DEBUG)
>>> logfix2.debug("Debug")
[D 200312 21:05:51 <stdin>:1] Debug
>>> logfix2.info("Info")
[I 200312 21:05:54 <stdin>:1] Info
>>> logfix2.level
10

Color support for Windows

I assume you're aware due to the try/except on the import, Windows versions of Python do not ship with the curses module. While there are ways to get a Windows-compatible curses module, it's not a reasonable proposition when there are tried-and-trued alternatives to colored output for Python.

Most apps and packages use colorama for colored output, including some colored logging packages that exist.

It's nice that logzero still works fine on Windows. But, colored output is certainly an attractive feature, so I hope you'll consider changing the method by which output is colorized to be cross-platform out-of-the-box.

Thanks for your time and effort.

Suggestion/Question - Rotating Logs

Does this module support rotating log files?
For what I've seen, logzero doesn't provide functionality to rotate logs, which will result in enormous log files, with enough time.
My production environments usually keep 7 rotating log files, one for each day of the week, which prevents the log-explosion issue.

Inconsistent output in console and logfile.

  • logzero version: 1.5.0
  • Python version: 3.6.8
  • Operating System: Windows 10

Description

I have ran below code block with updated data formatting. When executing the code block, the data formatting have been updated in console, but the logfile which have been written still show the default formatting. I tried to get it done with another code block (code block-2). It shows updated date formatting in console as well as logfile. But in logfile it prints extra character for color which I dont want.

What I Did

Code Block - 1

import logzero
from logzero import logger

log_format = '%(color)s[%(asctime)s %(module)s:%(lineno)d]%(end_color)s %(message)s'
formatter = logzero.LogFormatter(fmt=log_format, datefmt='%d-%m-%Y %H:%M:%S')
logzero.setup_default_logger(formatter=formatter)

logzero.logfile('tp.txt')

logger.info("Hello 1")
logger.info("Hello 2")
logger.info("Hello 3")
logger.info("Hello 4")
Console Output

[25-03-2020 22:36:56 tp:19] Hello 1
[25-03-2020 22:36:56 tp:20] Hello 2
[25-03-2020 22:36:56 tp:21] Hello 3
[25-03-2020 22:36:56 tp:22] Hello 4

Logfile Output

[I 200325 22:36:56 tp:19] Hello 1
[I 200325 22:36:56 tp:20] Hello 2
[I 200325 22:36:56 tp:21] Hello 3
[I 200325 22:36:56 tp:22] Hello 4

Code Block - 2

import logzero

log_format = '%(color)s[%(asctime)s %(module)s:%(lineno)d]%(end_color)s %(message)s'
formatter = logzero.LogFormatter(fmt=log_format, datefmt='%d-%m-%Y %H:%M:%S')

logger_1 = logzero.setup_logger(logfile='tp.txt', formatter=formatter)

logger_1.info("Hello 1")
logger_1.info("Hello 2")
logger_1.info("Hello 3")
logger_1.info("Hello 4")
Console Output

[25-03-2020 22:39:29 tp:17] Hello 1
[25-03-2020 22:39:29 tp:18] Hello 2
[25-03-2020 22:39:29 tp:19] Hello 3
[25-03-2020 22:39:29 tp:20] Hello 4

Logfile Output

�[32m[25-03-2020 22:39:29 tp:17]�[39m Hello 1
�[32m[25-03-2020 22:39:29 tp:18]�[39m Hello 2
�[32m[25-03-2020 22:39:29 tp:19]�[39m Hello 3
�[32m[25-03-2020 22:39:29 tp:20]�[39m Hello 4

[Suggestion/Discussion] Support for `logging.getLogger(__name__)`

This isn't an issue, and not necessarily a feature request, but more of a request for feedback.

💡 tldr: I propose a refactor that puts most of logzero into a class implementing the interface expected by logging.setLoggerClass and reduce setup_logger() to a function that instantiates, configures and returns an instance of that class. This is to permit libraries unaware of logzero to benefit from all that makes logzero great but using the defacto standard pattern of logger = logging.getLogger(__name__). But please also read the last line. :)

If I'm writing an application where the logging is under my control, including in libraries I wrote, logzero is a beautiful solution. But consider the following situations:

  • I write a library that I depend on but others might want to also.
  • I depend on external libraries who have no idea about my application or its logging.

In these cases the recommended pattern is for code to call logging.getLogger(__name__), where the stdlib logging library will return a logger likely configured by the parent application.

My idea is to implement this pattern but also leverage the sane and beautiful defaults of Logzero and the very easy implementation.

Now, you know more about logging than I do, Chris, but it seems passing an appropriately implemented Logger class to logging.setLoggerClass(klass) would achieve this. In the following I will call that class Klass both as the metavar for a class and to acknowledge your home in Austria, but it could be called logzero.DefaultLogger or something.

It seems there are three options:

  1. Refactor logzero so it continues to do exactly what it does as well as it does but also offers the same default setup as a Klass that implements the interface described in the link above, offering the logzero experience to a wider set of use-cases.
  2. Fork logzero entirely, copying and pasting the details necessary to implement my idea in a new project. This would mean limited hassle for you if you aren't interested, but means manual work to keep your improvements merged in; it would also mean yet another logging library that wouldn't be as discoverable as this.
  3. Refactor logzero's code to encapsulate more things like the default formatter, default handlers etc in a way that offers an API for a wrapper project to provide a Klass, or for an advanced user to implement themselves. If this is the solution you may as well just do 1) imho.

In the current Logzero implementation, while some things like the LogFormatter from Tornado are written in classes that could be imported and reused in other ways, a lot of logic is in functions like setup_logger() which provides the documented Logzero interface but also handles setting up the instances the Logzero Way. I think those tasks should be separated.

Tricky bits:

  • The interface setLoggerClass defines: the constructor of Klass may only accept a name. However most configuration on logzero is done by calling module-level functions. If the defaults were implemented on the Klass and the config functions continued to manipulate the default logzero.logger, then the only problem would be finding the right way for a class-based user to achieve beautiful logzero results with logzero ease where configuration is needed. My suggestion is that the module-level config functions be implemented as methods on the Klass which update a number of class-level variables, and the module interface reduced to wrappers that call these methods on logzero.logger which becomes an instance of Klass.

I realise that this proposal would require a substantial rewrite of logzero, but on the other hand it's not a big file and it's mostly just a refactor and testing. On the other hand, I think there's an opportunity to maintain the current interface and expose the benefits of Logzero to a much wider set of use-cases which need the standard logging pattern but would love the ease and beauty of the Logzero interface and defaults.

Happy to hear your thoughts. If this doesn't appeal, I might attempt to implement this myself to demonstrate it and we can look at ways to collaborate after that if I can prove it's workable.

An alternative: just monkeypatch logging.getLogger in the parent app to logzero.setup_logger and be done with it. I don't know if that's a genius idea or a risky hack tbh.

Colors for extra levels

Hi, it is nice. And yes, it is really important to say, that logging is behind. My questions:

1/ how is it possible to have green color for all INFO levels (11-20)?

2/ Colors are also in a logfile, would it be possible to have colors on the screen but not in the file (for later parsing)?

Json Formatter overridden by _get_json_formatter

  • logzero version: 1.7.0
  • Python version: 3.7.9
  • Operating System: Windows 10

Description

Thanks for the great library!
I was setting up a custom JSON formatter for logging a specific json message (using a custom json default), however this was stymied through

_formatter = _get_json_formatter(json_ensure_ascii) if json else formatter or LogFormatter()

    _formatter = _get_json_formatter(json_ensure_ascii) if json else formatter or LogFormatter()

Is this intended behaviour (happy to override the formatter in the handler after creating?

Otherwise would suggest checking if isinstance(formatter, JsonFormatter)?

VS Code intellisense stops working from Pylance 2022.2.4

  • logzero version: 1.7.0
  • Python version: 3.8.10 64-bit
  • Operating System: Windows 10

Description

This is an intellisense issue with pylance via VS Code.
One of the changes in pylance 2022.2.4 causes logzero.logger intellisense to stop working
i.e. logger.debug is not identified

Intellisense in pylance 2022.2.3 does still function with logzero

This does not appear to cause any issues with code running, it is purely a IDE issue.

I'm not sure there's much else to add, but let me know if there's anything else I can provide.

Is there a way to use use "logging.setLoggerClass"

  • logzero version: logzero==1.5.0
  • Python version: Python 3.7.1
  • Operating System: Mac OS 10.14

Description

Is there a way to use setLoggerClass like in this SO Answer? https://stackoverflow.com/a/37025517/1913888

What I Did

When logging errors, I'd like to accumulate them in a global ERRORS list.

From reading the code, I'm not sure how to set the logger class. I didn't see logging.Logger being subclassed.

Your help is much appreciated.

Great Library BTW

Thanks

[Feature Request] Handling multiple arguments and non-string arguments

  • logzero version: 1.5
  • Python version: 3.8
  • Operating System: Ubuntu 20.04

Description

Would be nice if logzero could handle multiple arguments and non-string arguments(typecasting it to string internally). Ex:
logger.debug("Value of variable is: ", a)

What I currently do instead: Force everything to be an f-string, i.e.
logger.debug(f"Value of variable is: {a}")

If compatibility with Python versions before 3.6 (when f-strings were introduced) has to be maintained, then str.format can be internally used instead. Ex:
logger.debug("Value of variable is: {}".format(a))

Possible approach

Rather than setting up an instance of logging.getLogger(), we can setup an instance of a custom logging class. This class can inherit from logging.Logger, with the debug, info, warning, error and critical functions overriden to handle any number of arguments (using **args for instance).

Ex for overriding logging.Logger's functions: https://stackoverflow.com/a/37025517

I am willing to assist in development of this, if it seems alright @metachris 😄

virtualenv and/or OSX unable to load module

  • logzero version: 1.2.0
  • Python version: 2.7.10
  • Operating System: Mac Sierra 10.12.5

$ system_profiler SPSoftwareDataType
Software:

System Software Overview:

  System Version: macOS 10.12.5 (16F73)
  Kernel Version: Darwin 16.6.0
  Boot Volume: Macintosh HD
  Boot Mode: Normal
  Computer Name: REMOVED
  User Name: REMOVED
  Secure Virtual Memory: Enabled
  System Integrity Protection: Enabled
  Time since boot: 3 days 7:22

Description

Using virtualenvwrapper I can't seem to load logzero. Unsure of direct issue

$ mkvirtualenv foo
New python executable in /Users/REMOVED/.virtualenvs/foo/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /Users/REMOVED/.virtualenvs/foo/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/REMOVED/.virtualenvs/foo/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/REMOVED/.virtualenvs/foo/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/REMOVED/.virtualenvs/foo/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/REMOVED/.virtualenvs/foo/bin/get_env_details


(foo)$ pip install logzero
Collecting logzero
  Using cached logzero-1.2.0-py2.py3-none-any.whl
Installing collected packages: logzero
Successfully installed logzero-1.2.0

$ ls -ld /Users/REMOVED/.virtualenvs/foo/lib/python2.7/site-packages/logzero
drwxr-xr-x  4 REMOVED  group  136 Jul  7 15:20 /Users/gmerrall/.virtualenvs/foo/lib/python2.7/site-packages/logzero

(foo)$ python
Python 2.7.10 (default, Feb  7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> import sys
>>> import pprint
>>> pprint.pprint(sys.path)
['',
 '/Users/REMOVED/.virtualenvs/foo/lib/python27.zip',
 '/Users/REMOVED/.virtualenvs/foo/lib/python2.7',
 '/Users/REMOVED/.virtualenvs/foo/lib/python2.7/plat-darwin',
 '/Users/REMOVED/.virtualenvs/foo/lib/python2.7/plat-mac',
 '/Users/REMOVED/.virtualenvs/foo/lib/python2.7/plat-mac/lib-scriptpackages',
 '/Users/REMOVED/.virtualenvs/foo/lib/python2.7/lib-tk',
 '/Users/REMOVED/.virtualenvs/foo/lib/python2.7/lib-old',
 '/Users/REMOVED/.virtualenvs/foo/lib/python2.7/lib-dynload',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/Users/REMOVED/.virtualenvs/foo/lib/python2.7/site-packages']

>>> from logzero import logger
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "logzero.py", line 1, in <module>
    from logzero import logger
ImportError: cannot import name logger

How to show output logzero's log in pytest

  • logzero version: 1.5
  • Python version: 3.6.5
  • Operating System: win7

Description

I want to show log which generated by logzero into pytest's html report file.
But, only the log use logging have been showed.

What I Did

My log has two different formatter:

  1. default formatter : just use logging.info() directly
  2. add an extra parameter in formatter(which i use logzero)
class Device(object):
    def __init__(self,device):
        self.d=u2.connect(device)
        tformater=logzero.LogFormatter(fmt='%(asctime)s [%(deviceid)s]%(levelname)1.1s %(message)s (%(filename)s:%(lineno)s)',datefmt='%Y-%m-%d %H:%M:%S')
        tlog=logzero.setup_logger(level=logging.DEBUG,formatter=tformater)
        self.log=logging.LoggerAdapter(tlog, {"deviceid":device})

When I run pytest , two parts are all shows in console.
But, part 2 not show in pytest's report file

in pytest.ini file ,I only set log_cli=1

No Color for Critical Log Level

  • logzero version: 1.5.0
  • Python version: 2.7, 3.6
  • Operating System: Windows 7

Description

I Have a python application that is logging at the CRITICAL level and there is no color associated with that log level.

What I Did

logger.critical(msg)

Does not use nice color in Jupyter

  • logzero version: 1.5.0
  • Python version: 3.6
  • Operating System: Linux

Description

Logzero is really neat and it would be great if one could make full use of it in Jupyter notebook.
Unfortunately it does not recognize the color capability and the output shows no color formatting.

Two things would solve this:

  • easy way to switch to STDOUT (without losing the formatter)
  • enforcing TTY mode since apparently Jupyter notebook/lab can show color but does not announce that

What I Did

Do in Jupyter notebook (conda install notebook; jupyter notebook) or Jupyter lab.

from logzero import logger
logger.error("TEXT")

color in filelog is in a mess

i guess we should split the filelogger to use another formatter that not use color, or it will be a mess.

�[36m[D 210715 10:47:45 main:20]�[39m hello world
�[36m[D 210715 10:47:58 main:20]�[39m hello world
�[36m[D 210715 10:47:59 main:20]�[39m hello world

Logfile JSON encode

  • logzero version: 1.6.2
  • Python version: 3.8
  • Operating System: Ubuntu 20.04

Description

logger.json(True)
I cant encode in UTF-8 , my special characters, like Ç , ç , ã , é and others, on file appear \x0231 etc .

logfile.log

logzero in multiple files using import

  • logzero version: 1.6.3
  • Python version: 3.8.5
  • Operating System: Windows 10 (20H2 19042.630)

Description

Hello!
I'm having a little problem using logzero um more than one program. I have a main program (main_logzero.py) and it imports another program (import_logzero.py).
Both pyhon files has the handle for logzero, and each one with the respective logfile.
But, when I execute the main_logzero.py, it only logs in to the main_logzero.log and the import_logzero.log is empty.

As you can see in the main_logzero.log, it's logging:

[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!

But it's in the wrong file (it should be at import_logzero.log - that's empty)...

Am I doing something wrong with the logzero?

What I Did

C:\Users\igorv\logzero>dir
 O volume na unidade C não tem nome.
 O Número de Série do Volume é 6E10-B93F

 Pasta de C:\Users\igorv\logzero

03/12/2020  12:08    <DIR>          .
03/12/2020  12:08    <DIR>          ..
03/12/2020  11:56               195 import_logzero.py
03/12/2020  11:56               241 main_logzero.py
03/12/2020  12:08    <DIR>          old


               2 arquivo(s)            436 bytes
               3 pasta(s)   315.415.105.536 bytes disponíveis

C:\Users\igorv\logzero>python --version
Python 3.8.5

C:\Users\igorv\logzero>python main_logzero.py
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 0 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 1 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 2 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 3 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 4 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 5 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 6 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 7 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 8 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 9 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 10 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 11 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 12 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 13 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 14 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 15 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 16 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 17 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 18 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 19 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 20 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 21 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 22 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 23 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 24 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 25 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 26 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 27 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 28 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 29 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 30 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 31 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 32 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 33 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 34 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 35 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 36 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 37 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 38 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 39 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 40 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 41 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 42 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 43 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 44 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 45 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 46 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 47 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 48 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 49 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 50 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 51 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 52 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 53 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 54 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 55 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 56 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 57 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 58 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 59 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 60 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 61 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 62 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 63 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 64 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 65 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 66 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 67 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 68 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 69 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 70 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 71 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 72 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 73 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 74 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 75 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 76 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 77 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 78 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 79 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 80 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 81 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 82 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 83 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 84 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 85 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 86 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 87 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 88 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 89 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 90 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 91 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 92 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 93 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 94 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 95 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 96 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 97 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 98 - 0
[I 201203 12:09:13 import_logzero:6] import_logzero - execution OK!
[I 201203 12:09:13 main_logzero:8] main_logzero: 99 - 0

C:\Users\igorv\logzero>dir
 O volume na unidade C não tem nome.
 O Número de Série do Volume é 6E10-B93F

 Pasta de C:\Users\igorv\logzero

03/12/2020  12:09    <DIR>          .
03/12/2020  12:09    <DIR>          ..
03/12/2020  12:09                 0 import_logzero.log
03/12/2020  11:56               195 import_logzero.py
03/12/2020  12:09            12.590 main_logzero.log
03/12/2020  11:56               241 main_logzero.py
03/12/2020  12:08    <DIR>          old
03/12/2020  12:09    <DIR>          __pycache__
               4 arquivo(s)         13.026 bytes

               4 pasta(s)   315.415.023.616 bytes disponíveis

C:\Users\igorv\logzero>

logzero.zip

Setting a loglevel for logfiles

Hi,

I would like to set the logging level for a logfile to DEBUG but leave the logging level
for the console log at INFO, to log debug information to the logfile without cluttering the console.
For example by defining a custom logger via

logzero.setup_logger(logfile="custom_logfile.log", level=logging.INFO, fileLoglevel=logging.DEBUG).

This does not work as I expected. After some testing I came to the conclusion that
the loglevel set via fileLoglevel can not be lower (only higher) than the loglevel set via level.
If a lower level is set via fileLoglevel it gets overwritten by level.

Is there a specific reason for this behavior?

Raising and Logging exception

  • logzero version: 1.3.0
  • Python version: 3.6
  • Operating System: Ubuntu

Description

I am using logzero and pytest. When an exception occur, I would like to be able to catch it in the log, but also to test that it was raised in my unittest. Currently, the only way I managed to do this is to catch the exception, log it and raise it again. That doesn't feel like the right way (maybe it is).

Do you have a leaner way to recommend?

What I Did

# in main.py
    if publisher:
        try:
            timezone = config.TIMEZONES[publisher]
        except KeyError as e:
            logger.exception({
                "error": e,
                "message": f"Missing timezone ID for publisher: {publisher}"
            })
            raise KeyError

Thanks for the great package, a lot simpler than anything else I have experienced for logging. #

Usage with multiprocessing and single rotated logfile

  • logzero version: 1.5.0
  • Python version: 3.6.5
  • Operating System: Ubuntu 16.04

Description

I'm trying to use logzero in a multiprocessing context using a single rotated logfile.
I obtain errors from the Python logging module that moving files fails.

What I Did

I created a MWE here including all instructions to set up and run it.

If my approach is valid, I see a clash with logzero's claim to feature 'Multiple loggers can write to the same logfile (also across multiple Python files)'.
I'm not entirely sure whether this is not actually a limitation of Python's internal logging module, please point out if so :)

Rotating params for `setup_logger`

It would be great to have there maxBytes and backupCount params, maybe with file prefix. Also looks like log prefix in logfile param is redundant.

in logfile() fuction, filename arg type error?

  • logzero version:1.3.0
  • Python version:3.5.2
  • Operating System:ubuntu 16.04

Description

in logfile() fuction, filename arg type error?Should it be string?

:arg int filename: Filename of the logfile. Set to None to disable logging to the logfile.

What I Did

change the type of filename to string.

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

Readme should explain relationship with logging module

  • logzero version: N/A
  • Python version: N/A
  • Operating System: N/A

Description

This is some friendly feedback on my first impression about reading about logzero. I thought it was a competitor to Python's excellent logging module, rather than an introduction/stepping-stone.

I had delve quite deep to find that it is a front-end to it, which means all the power of logging is available to the user as they become more familiar with it, and their project grows.

I suggest you make this clearer, earlier in the Readme/Docs. It might help prevent questions like #8, too, as people realise there is plenty of functionality waiting for them behind the curtain.

Good luck with the project.

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.