Skip to main content

Logging for microservices

Project description

Purpose

This log module can be used in microservices on JS and Python to write common (combined, or single) log file and also to notify administrator about errors. The module provides similar format for different microservices and single configuration point (environment variables) that can be useful on server with SaaS b ased on different microservices.

How to use

Configuration in code

In code it's recommended to set module name with a call: log.set_module_name(name).

Session identificator (sid)

Sid is any (optional) string that can identify the session.

Log format

Any message has common format like: [module][datetime] level [sid] message Where:

  • module - configurable name
  • datetime - date and time of log call by format YYYY-MM-DD hh:mm:ss.ms
  • level - level of message, INFO, WARN, ERROR (and internal *CRITICAL* for logger internal errors)
  • sid - Session identificator (can be undefined/None)

Logging (by levels)

To log any message use following functions by appropriate levels (sid is optional argument):

  • log.info(message, sid)
  • log.warn(message, sid)
  • log.error(message, sid)

Levels "info" and "warn" logged into stdout and log file only but level "error" also generates e-mail and Telegram message.

External configuration

The logger configured with environment variables. Additionally to always enabled stdout/stderr you can enable up to three channels for logging by following variables:

  • Log all levels of messages to file (can be used from different processes in parallel)
    • LOG_FILENAME=<Filename for .log in HOME folder>
  • Send e-mail per each error level message (with call stack)
    • SENDER_GMAIL=<Your Gmail proxy account to send e-mails>
    • SENDER_GMAIL_PASSWORD=<Your Gmail proxy account app password> - see how to configure Gmail app password
    • ADMIN_EMAIL=<Admin e-mail to get critical error messages>
  • Send Telegram notification per each error-level message (with call stack) - see how to get Telegram the Bot Token and the Chat ID
    • TELEGRAM_BOT_TOKEN=<Your Telegram bot token>
    • TELEGRAM_CHAT_ID=<The chat ID to send messages>

Integration

Recommended way for integration is to use it as git submodule - to update it for your requirements.

import log

const log = require('@gpuprog/log/log')

Development

cd log

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

gpuprog-log-1.1.2.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

gpuprog_log-1.1.2-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file gpuprog-log-1.1.2.tar.gz.

File metadata

  • Download URL: gpuprog-log-1.1.2.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.12

File hashes

Hashes for gpuprog-log-1.1.2.tar.gz
Algorithm Hash digest
SHA256 68303b9d477c53e24e22cb57422dd253ceb0e5bce4a6db2b45a71d6bf331d7b9
MD5 e24ccb6572da1bd3f727b8448609f332
BLAKE2b-256 bf2911a0497906b8976e8a6f337b1313c9a4a1976e168bac1503e0be8e426929

See more details on using hashes here.

File details

Details for the file gpuprog_log-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: gpuprog_log-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.12

File hashes

Hashes for gpuprog_log-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 878b3a3de2a63ba360ac6ce14590ad9fc249510082d7a58a6beb870b537be109
MD5 b45b3c94ddb3802143b5b8def918a11f
BLAKE2b-256 1a1c6ab151f226efad715908f13404b7dbd8ba2b5d242fa8713423c1528456e6

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