efk-log


Nameefk-log JSON
Version 1.0.1 PyPI version JSON
download
home_page
Summary
upload_time2023-11-29 08:36:06
maintainer
docs_urlNone
authorlishulong
requires_python>=3.7,<4.0
license
keywords json-log efk elk
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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')
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "efk-log",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "json-log,efk,elk",
    "author": "lishulong",
    "author_email": "lishulong.never@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/58/36/0a06a8af45c6d15347f3a8f0773dcdb3ac6d13d077c2a58168f210b6069c/efk_log-1.0.1.tar.gz",
    "platform": null,
    "description": "# Efk-log\n\n## Quick start\n\n> Called from where the project was launched.\n\n## Install\n`pip install efk-log==0.31` : no trace-code\n`pip install efk-log==0.5.0` : add trace-code\n\n\n\n\n### En\n\n1. Logs in json format are easily collected in es and can be easily indexed on top of kibana for related fields.\n\n2. Note that it is important to avoid index value conflicts, as different value types for the same index name can cause conflicts.\n\n3. 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.\n\n   1. file_path=None\n\n   2. supervisor-related parameters are sliced to avoid large log files.\n\n      ```\n      stdout_logfile_maxbytes = 50MB   ; max # logfile bytes b4 rotation (default 50MB)\n      stdout_logfile_backups = 10 ; # of stdout logfile backups (default 10)\n      stdout_logfile = /data/logs/efk-log/efk-log.log\n      ```\n\n### Zh\n\n1. json \u683c\u5f0f\u7684\u65e5\u5fd7 \u65b9\u4fbf\u6536\u96c6\u5230es\u4e2d\u53ef\u65b9\u4fbf\u5bf9\u76f8\u5173\u5b57\u6bb5\u5728kibana\u4e0a\u9762\u521b\u5efa\u7d22\u5f15\n\n2. \u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8981\u907f\u514d\u7d22\u5f15\u503c\u7684\u51b2\u7a81\uff0c\u76f8\u540c\u7684\u7d22\u5f15\u540d\uff0c\u6570\u503c\u7c7b\u578b\u4e0d\u540c\u5c31\u4f1a\u9020\u6210\u51b2\u7a81\n\n3. \u591a\u8fdb\u7a0b\u542f\u52a8 \u670d\u52a1\u65f6\u5019\u914d\u5408 supervisor \u7684\u65e5\u5fd7\u529f\u80fd\u4f7f\u7528\uff0c\u4f7f\u7528supervisor \u5b88\u62a4gunicorn \u542f\u52a8\u7684\u670d\u52a1\u8fdb\u7a0b\n\n   1. file_path=None\n\n   2. supervisor \u76f8\u5173\u53c2\u6570 \u8fdb\u884c\u5207\u5206\uff0c\u907f\u514d\u65e5\u5fd7\u6587\u4ef6\u592a\u5927\n\n      ```\n      stdout_logfile_maxbytes = 50MB   ; max # logfile bytes b4 rotation (default 50MB)\n      stdout_logfile_backups = 10 ; # of stdout logfile backups (default 10)\n      stdout_logfile = /data/logs/efk-log/efk-log.log\n      ```\n\n\n\n### Flask \n\n```\nLogJsonFormat(file_path=None, console=True, project='efk-log')\n```\n\n### Celery\n\n```\nfrom celery.signals import setup_logging\n\n@setup_logging.connect\ndef set_log(*args, **kwargs):\n    LogJsonFormat(file_path=None, console=True, project='celery-prd')\n```\n\n\n\n### Demo\n\n```\nfrom efk_log import LogJsonFormat\n\nif __name__ == '__main__':\n    LogJsonFormat(file_path=None, console=True, project='efk-log')\n\n    import logging\n\n    LOGGER = logging.getLogger(__name__)\n\n    LOGGER.info('get user info', extra={'metrics': {\n        'cid': 'xxxxxx'\n    }})\n\n    try:\n        2 / 0\n    except Exception as e:\n        LOGGER.exception('except...', exc_info=e)\n\n    LOGGER.error('error')\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "",
    "version": "1.0.1",
    "project_urls": null,
    "split_keywords": [
        "json-log",
        "efk",
        "elk"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c92564d48b060bd85654d975374e9dac987c059cba9b1594e9e4072f59a40015",
                "md5": "71abec1e2b9f3272773129ced39d6531",
                "sha256": "c479d6a9f611ae54fa853d20021b393eb6bfb1ae1d6b55c6bd20eb31fa245f11"
            },
            "downloads": -1,
            "filename": "efk_log-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "71abec1e2b9f3272773129ced39d6531",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 6132,
            "upload_time": "2023-11-29T08:36:03",
            "upload_time_iso_8601": "2023-11-29T08:36:03.878862Z",
            "url": "https://files.pythonhosted.org/packages/c9/25/64d48b060bd85654d975374e9dac987c059cba9b1594e9e4072f59a40015/efk_log-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "58360a06a8af45c6d15347f3a8f0773dcdb3ac6d13d077c2a58168f210b6069c",
                "md5": "741093b0ee4eec1f627a60a1c12c0f10",
                "sha256": "65e20652c7356c7d47b479f68158057c9b48450343cd73184eeacb6f6c3c2a95"
            },
            "downloads": -1,
            "filename": "efk_log-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "741093b0ee4eec1f627a60a1c12c0f10",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 5319,
            "upload_time": "2023-11-29T08:36:06",
            "upload_time_iso_8601": "2023-11-29T08:36:06.167423Z",
            "url": "https://files.pythonhosted.org/packages/58/36/0a06a8af45c6d15347f3a8f0773dcdb3ac6d13d077c2a58168f210b6069c/efk_log-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-29 08:36:06",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "efk-log"
}
        
Elapsed time: 3.24118s