Skip to main content

A drop in logger configurable through environment variables

Project description

app-logger

This is a drop in logger that uses python-json-logger to log json to stdout and stderr appropriately. DEBUG and INFO go to stdout, WARNING, ERROR, CRITICAL go to stderr.

Configuration

All configuration is through environment variables, all have defaults so none are required.

LOGGER_NAME

What should the logger be called? Default will use the root logger. Using the default or root will log not only log statements from app_logger but also any statements from libraries you're using. Format: Just a regular string Default: root Example: mysweetapp

LOG_LEVELS

Used to set log levels. Can be used to set any log level you wish so you can selectively control logging. May be upper or lower case. Format: A comma separated string of key=value pairs Default: root=INFO Example: root=DEBUG,asyncio=INFO

LOG_FORMAT

Used to control the log format. Format: A log format string of log record attributes Default: `%(levelname)%(name)%(asctime)%(module)%(funcName)%(lineno)%(message)``

Usage

The logger initializes itself and makes itself available as a variable called app_logger. It's a regular python logger and can be used as such. Example app_logger.info("I always hated python logging but now it's easy and just works") Resulting log {"levelname": "INFO", "name": "root", "asctime": "2020-04-11 11:24:17,299", "module": "main", "funcName": "main", "lineno": 14, "message": "I always hated python logging but now it's easy and just works"}

Adding context

You can use the extra= feature of python-json-logger to add context to your messages. This makes it really easy to have logging that's easy to parse, search, learn, and alert on if you're using log aggregation. Example Given you have something that's a dictionary, you can include it in log statements without verbose string formatting. app_logger.error('Error handling message', extra=message) Resulting log {"levelname": "ERROR", "name": "root", "asctime": "2020-04-11 11:27:36,584", "module": "main", "funcName": "main", "lineno": 16, "message": "Error handling message", "guid": "7cc81eba-3bbc-4555-8fab-2a7556072f5d", "subject": "test"} You can see how easy it would be to find logs like this in kibana, and it's already in json format so it's easily indexable/searchable, including the context given via extra=

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

app-logger-0.1.2.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

app_logger-0.1.2-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file app-logger-0.1.2.tar.gz.

File metadata

  • Download URL: app-logger-0.1.2.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.0 CPython/3.7.4 Windows/10

File hashes

Hashes for app-logger-0.1.2.tar.gz
Algorithm Hash digest
SHA256 758bd7629303bb049d5bb31614f205aa9fccf6eaacf2c3964331b0ce636f969a
MD5 cbcbbe15b8cf72304848c3f0cdf8872d
BLAKE2b-256 d60a27bff0f496c5720415d2bd1dcd975075ec4239a2c66d7987c047b8cd9a50

See more details on using hashes here.

File details

Details for the file app_logger-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: app_logger-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.0 CPython/3.7.4 Windows/10

File hashes

Hashes for app_logger-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ac776d423e0c9182e8e96116480717b25b332d740b4a310af07d346d730d7cc4
MD5 a835731ac83e48771778e2b5718d20ce
BLAKE2b-256 8bf649112312da1d6cd811c7567e3571c7c6a8a53e8538c1e403dec6cf66b67e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page