1.2.8 • Published 1 year ago

@gpuprog/log v1.2.8

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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.

  • Python: PyPi package - use pip install gpuprog-log

    import log

  • JS: NPM package - use npm i @gpuprog/log

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

Development

cd log

1.2.0

1 year ago

1.2.8

1 year ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.2.4

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago