All Projects → metachris → Logzero

metachris / Logzero

Licence: mit
Robust and effective logging for Python 2 and 3.

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to Logzero

Logger Telegram Backend
A logger backend for Telegram
Stars: ✭ 13 (-98.67%)
Mutual labels:  logging
Rsyslog
An R interface to syslog, the POSIX system logger API
Stars: ✭ 21 (-97.85%)
Mutual labels:  logging
Escriba
📜 Logging on steroids
Stars: ✭ 30 (-96.93%)
Mutual labels:  logging
Eliot
Eliot: the logging system that tells you *why* it happened
Stars: ✭ 874 (-10.54%)
Mutual labels:  logging
Belogging
Easy and opinionated logging configuration for Python apps
Stars: ✭ 20 (-97.95%)
Mutual labels:  logging
Adenium
Adenium Normalizer
Stars: ✭ 29 (-97.03%)
Mutual labels:  logging
Pylogging
🏉 Python Logging Library
Stars: ✭ 9 (-99.08%)
Mutual labels:  logging
Lumberjack
A terminal-ui log watcher written in Go using the Flux architecture
Stars: ✭ 31 (-96.83%)
Mutual labels:  logging
Cartus
A structured logging abstraction with multiple backends.
Stars: ✭ 21 (-97.85%)
Mutual labels:  logging
Dotlog
Simple and easy go log framework
Stars: ✭ 30 (-96.93%)
Mutual labels:  logging
Loggingprint
Swift logging only when in Debug mode.
Stars: ✭ 14 (-98.57%)
Mutual labels:  logging
Humblelogging
HumbleLogging is a lightweight C++ logging framework. It aims to be extendible, easy to understand and as fast as possible.
Stars: ✭ 15 (-98.46%)
Mutual labels:  logging
Nim Morelogging
Logging library for Nim
Stars: ✭ 29 (-97.03%)
Mutual labels:  logging
Trail
Trail is a simple logging system for Java and Android. Create logs using the same API and the library will detect automatically in which platform the code is running.
Stars: ✭ 13 (-98.67%)
Mutual labels:  logging
Testlogcollectors
A framework for capturing log statements during tests. Compatible with most popular logging frameworks. Works with JUnit and TestNG
Stars: ✭ 31 (-96.83%)
Mutual labels:  logging
Fluentd
Log shipping mechanism for Deis Workflow
Stars: ✭ 10 (-98.98%)
Mutual labels:  logging
Logging
Easy setup of clojure.tools.logging w/ SLF4j, plus request correlation
Stars: ✭ 21 (-97.85%)
Mutual labels:  logging
Loglevelnext
A modern logging library for Node.js that provides log level mapping to the console
Stars: ✭ 33 (-96.62%)
Mutual labels:  logging
Nlog.xlogger
A C# .NET class library that extends NLog.Logger to provide additional functionality for tracing the entry and exit, arbitrary checkpoints, exceptions and stack traces within methods.
Stars: ✭ 31 (-96.83%)
Mutual labels:  logging
Lme
An npm package to simply and beautifully log to console.
Stars: ✭ 29 (-97.03%)
Mutual labels:  logging

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].