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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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