Skip to main content

Efk-log

Quick start

Called from where the project was launched.

Install

pip install efk-log==0.31 : no trace-code pip install efk-log==0.5.0 : add trace-code

En

  1. Logs in json format are easily collected in es and can be easily indexed on top of kibana for related fields.

  2. Note that it is important to avoid index value conflicts, as different value types for the same index name can cause conflicts.

  3. Use the supervisor to guard the service processes started by gunicorn when starting a multi-process service, in conjunction with the supervisor's logging feature.

    1. file_path=None

    2. supervisor-related parameters are sliced to avoid large log files.

      stdout_logfile_maxbytes = 50MB   ; max # logfile bytes b4 rotation (default 50MB)
      stdout_logfile_backups = 10 ; # of stdout logfile backups (default 10)
      stdout_logfile = /data/logs/efk-log/efk-log.log
      

Zh

  1. json 格式的日志 方便收集到es中可方便对相关字段在kibana上面创建索引

  2. 需要注意的是,要避免索引值的冲突,相同的索引名,数值类型不同就会造成冲突

  3. 多进程启动 服务时候配合 supervisor 的日志功能使用,使用supervisor 守护gunicorn 启动的服务进程

    1. file_path=None

    2. supervisor 相关参数 进行切分,避免日志文件太大

      stdout_logfile_maxbytes = 50MB   ; max # logfile bytes b4 rotation (default 50MB)
      stdout_logfile_backups = 10 ; # of stdout logfile backups (default 10)
      stdout_logfile = /data/logs/efk-log/efk-log.log
      

Flask

LogJsonFormat(file_path=None, console=True, project='efk-log')

Celery

from celery.signals import setup_logging

@setup_logging.connect
def set_log(*args, **kwargs):
    LogJsonFormat(file_path=None, console=True, project='celery-prd')

Demo

from efk_log import LogJsonFormat

if __name__ == '__main__':
    LogJsonFormat(file_path=None, console=True, project='efk-log')

    import logging

    LOGGER = logging.getLogger(__name__)

    LOGGER.info('get user info', extra={'metrics': {
        'cid': 'xxxxxx'
    }})

    try:
        2 / 0
    except Exception as e:
        LOGGER.exception('except...', exc_info=e)

    LOGGER.error('error')

Metadata

Release files for efk-log 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for efk-log 1.0.1
File Size Uploaded Provenance Actions
efk_log-1.0.1.tar.gz 5.3 kB Without provenance Details for efk_log-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for efk-log 1.0.1
File Interpreter ABI Platform Actions
efk_log-1.0.1-py3-none-any.whl Python 3 none any Details for efk_log-1.0.1-py3-none-any.whl

Total release size: 11.5 kB

Release files / efk_log-1.0.1.tar.gz

Download URL efk_log-1.0.1.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
65e20652c7356c7d47b479f68158057c9b48450343cd73184eeacb6f6c3c2a95
BLAKE2b-256 checksum
How to use checksums
58360a06a8af45c6d15347f3a8f0773dcdb3ac6d13d077c2a58168f210b6069c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.9.6 Darwin/22.6.0

Release files / efk_log-1.0.1-py3-none-any.whl

Download URL efk_log-1.0.1-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c479d6a9f611ae54fa853d20021b393eb6bfb1ae1d6b55c6bd20eb31fa245f11
BLAKE2b-256 checksum
How to use checksums
c92564d48b060bd85654d975374e9dac987c059cba9b1594e9e4072f59a40015
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.9.6 Darwin/22.6.0

Security for efk-log 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page