Skip to main content

StreamSage Python Logger

Project description

STREAM SAGE PYTHON LOGGER

Basic operation

Logger format

[<Date> <Time>][<logLevel>][<context>][<file>:<line>] <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

Installation

Add streamsage-python-logger to requirements.txt

streamsage-python-logger =< 0.1.0

or install via pip:

pip install streamsage-python-logger

Environment Variables

Variable Description Default Supported
LOG_SDK_CONTEXT Logger context NoneContextApp str
TRANSPORTS List of transports - fluent

Logger parameters and configuration:

Optional:

  • context - The context of logger instance. Can be specified via environment variables or the context parameter in the get_logger method

Levels:

Logging levels table

Level Numeric value
CRITICAL 50
ERROR 40
WARNING 30
INFO 20
DEBUG 10
TRACE 1
NOTSET 0

Default: info Then, you can use following methods log(), fatal(), error(), warning(), info(), debug(), trace():

  • log() - displays message in given log level.
  • fatal() - displays message in critical log level.
  • error() - displays message in error log level.
  • warning() - displays message in warning 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

Description of 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, WARNING, INFO, DEBUG, TRACE

Fluent

Variable Description Default Supported
LOG_SDK_TRANSPORT_FLUENT_LEVEL Logging level to FluentD INFO FATAL, ERROR, WARNING, 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. 3.0 -

Logger sample usage

Logger can be initialized by get_logger() method:

from streamsage_python_logger.streamsage_logger import get_logger

logger = get_logger(context='SomeApp')

logger.trace('Something has happened to log on TRACE level')
logger.debug('Something has happened to log on DEBUG level')
logger.info('Something has happened to log on INFO level')
logger.warning('Something has happened to log on DEBUG level')
logger.error('Something has happened to log on ERROR level')
logger.fatal('Something has happened to log on FATAL level')

logger.log(10, 'Something has happened to log on 10 level')

output:

[2022-08-17 11:50:29][TRACE][SomeApp][workshop.py:8] Something has happened to log on TRACE level
[2022-08-17 11:50:29][DEBUG][SomeApp][workshop.py:9] Something has happened to log on DEBUG level
[2022-08-17 11:50:29][INFO][SomeApp][workshop.py:10] Something has happened to log on INFO level
[2022-08-17 11:50:29][WARNING][SomeApp][workshop.py:11] Something has happened to log on DEBUG level
[2022-08-17 11:50:29][ERROR][SomeApp][workshop.py:12] Something has happened to log on ERROR level
[2022-08-17 11:50:29][CRITICAL][SomeApp][workshop.py:13] Something has happened to log on FATAL level
[2022-08-17 11:50:29][DEBUG][SomeApp][workshop.py:15] Something has happened to log on 10 level

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().dict()),
                log_level='info')

output:

SomeFlaskApp  | [2022-08-21 20:49:50][INFO][uvicorn.error][server.py:75] Started server process [11]
SomeFlaskApp  | [2022-08-21 20:49:50][INFO][uvicorn.error][on.py:45] Waiting for application startup.
SomeFlaskApp  | [2022-08-21 20:49:50][INFO][uvicorn.error][on.py:59] Application startup complete.
SomeFlaskApp  | [2022-08-21 20:49:50][INFO][uvicorn.error][server.py:206] Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit)

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.19.tar.gz (7.6 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.19-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for streamsage_python_logger-0.0.19.tar.gz
Algorithm Hash digest
SHA256 1514d06b488aad33241188aee853b70898f4f27c1b5adbd1e7806eaa2a1f63b6
MD5 cac6823c3927936165c33f0ee272646f
BLAKE2b-256 b868a04da9350a78e0468b1ac0fc2839c82196d865fb3ca10c686992c19edb02

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for streamsage_python_logger-0.0.19-py3-none-any.whl
Algorithm Hash digest
SHA256 a3399f730f5121d4f6f2a35551b616c05665a29b6cf6c99a55d805d67ca8f886
MD5 a4ac55920427559afc2f830af6a1eb91
BLAKE2b-256 9125c0ae2fed470d508ec5545c8e14bc350a2a70f6bcf4588896623f04f1a390

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