Skip to main content

Stream Sage Logger for Python

Project description

STREAM SAGE PYTHON LOGGER

Log format

[<Date> <Time>][<logLevel>][<context>][<file>:<line>][<LoggerOptionalParams>] <message>

Date format: YYYY-MM-DD
Time format: HH:mm:ss

Logger output

[2022-04-15 12:06:34][info][Sample App][samle_file.py:1] Sample LOG message
[2022-04-15 03:06:00][info][Sample App][samle_file.py:1][messageId:some-message-id][domain:message-domain] Sample LOG message with additional params
[2022-04-15 12:06:34][error][Sample App][samle_file.py:1][customer:customer] Sample ERROR message with additional params
[2022-04-15 21:43:36][debug][Sample App][samle_file.py:1][debugLevel:5] Sample Debug message in debug level 5
[2022-04-15 10:20:28][debug][Sample App][samle_file.py:1][debugLevel:2] Sample Debug message in debug level 2

Installation

Add streamsage-python-logger==0.0.17 to requirements.txt or install via pip:

pip install streamsage-python-logger==0.0.17

Environments

Variable Description Default Supported
LOG_SDK_NO_COLOR Set to any value to disable logs colorizing - -
LOG_SDK_TRANSPORTS Comma separated list of log transporters that will be used by app. - fluent
LOG_SDK_SERVICE_NAME Service name that will be included in message payload. - -

Logger options:

Required:

  • context - The context of logger instance.

Optional:

  • level - Enable logger via passing a log level: fatal, error, warn, info, debug, trace or false if it should be disabled. Default: info Then, you can use following methods log(), fatal(), error(), warn(), info(), debug(), trace():
  • log() - displays message in given log level.
  • fatal() - displays message in fatal log level.
  • error() - displays message in error log level.
  • warn() - displays message in warn log level.
  • info() - displays message in info log level.
  • debug() - displays message in debug log level.
  • trace() - displays message in trace log level.

Available transports

Below has been describe all currently supported transport by the Logger.

Console

Notice: Console transport is always enabled.

Variable Description Default Supported
LOG_SDK_TRANSPORT_CONSOLE_LEVEL Logging level to console info fatal, error, warn, info, debug, trace

Fluent

Variable Description Default Supported
LOG_SDK_TRANSPORT_FLUENT_LEVEL Logging level to FluentD info fatal, error, warn, info, debug, trace
LOG_SDK_TRANSPORT_FLUENT_URL URL of the FluentD server - -
LOG_SDK_TRANSPORT_FLUENT_TIMEOUT Timeout for response from the FluentD server. 3000 -

Logger sample usage

Logger can be initialized by get_logger() method:

from streamsage_python_logger.streamsage_logger import get_logger

logger = get_logger("SomeApp")

for implementing logger with other libraries use LoggerConfig class with logging dictConfig e.g. on FastApi and uvicorn server:

import uvicorn
from fastapi import FastAPI
from logging.config import dictConfig
from streamsage_python_logger.streamsage_logger import LoggerConfig

app = FastAPI()

if __name__ == "__main__":
    uvicorn.run(app, host='0.0.0.0', port=8080,
                access_log=False,
                log_config=dictConfig(LoggerConfig(context='SomeApp').dict()),
                log_level='info')

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

streamsage_python_logger-0.0.18.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamsage_python_logger-0.0.18-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file streamsage_python_logger-0.0.18.tar.gz.

File metadata

File hashes

Hashes for streamsage_python_logger-0.0.18.tar.gz
Algorithm Hash digest
SHA256 0cd917c92841054d14d901724abb7c4461f8298f6836a26161086b222b48d4f9
MD5 b790882a8faac216aea3ae15909bab36
BLAKE2b-256 8d76fbf416af683b0c28d3c5d9110da394f60b840ccf9b828271ca69cac7c606

See more details on using hashes here.

File details

Details for the file streamsage_python_logger-0.0.18-py3-none-any.whl.

File metadata

File hashes

Hashes for streamsage_python_logger-0.0.18-py3-none-any.whl
Algorithm Hash digest
SHA256 734478c96bac3984cdc15ce657066a283c68bf2fd746370b1972c1485d23ba54
MD5 cb419a50124a03890f541b57e5ac0df2
BLAKE2b-256 3ed83637b43e0e9b74bfa96a2ee0e9e2da1b0fa8befe44e613cfb940ca080f4d

See more details on using hashes here.

Supported by

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