Skip to main content

Logtube Python SDK

Project description

logtube-python

logtube python sdk

设置

from src import logtube

logtube.setup({
    # 项目名,唯一标识一个项目
    "project": "eshop-id-service",
    # 环境名,用以区分不同环境
    "env": "dev",
    # 命令行输出
    "console": {
        "topics": ["*", "-debug"]  # 输出除了 debug 之外的所有主题
    },
    # 文件输出
    "file": {
        "topics": ["*", "-debug"],  # 输出除了 debug 之外的所有主题
        "dir": "logs",  # 设置日志输出的根目录
        "subdirs": {  # 设置子目录
            "xlog": ["*", "-debug"]  # 非调试日志输出到 `xlog` 子目录,其他日志进入 `others` 子目录
        }
    }
})

一般日志输出

第一个参数为关键字,可以用于为日志输出打一个关键字,鉴于日志量过大,info 日志必须通过关键字检索

from src import logtube

logtube.debug("关键字", "文本")
logtube.info("关键字", "文本")
logtube.warn("关键字", "文本")
logtube.error("关键字", "文本")
logtube.fatal("关键字", "文本")

Job 工具

针对任务类型的日志,Logtube 提供了工具类

from src import logtube

j = logtube.job()
j.set_job_name("sleep-job-1m")  # 设置任务名,用于区分一类任务
j.set_job_id("xxxxx-xxxxx-xxxxx-xxxxx")  # 设置任务编号,用于追踪同一个任务
j.add_keyword("hello")  # 可以增加关键字
j.add_extra("key", "val")  # 可以增加附属键值对
j.mark_start()  # 标记任务开始

# ... 此处为耗时很久的业务代码

j.mark_end(True, "任务成功")  # 标记任务结束和任务结果,True 为成功,可以额外添加任意纯文本
# committer.mark_end(False, "任务失败,因为 xxx.xxxx")

许可证

Guo Y.K., MIT License

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

logtube-1.0.1.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

logtube-1.0.1-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file logtube-1.0.1.tar.gz.

File metadata

  • Download URL: logtube-1.0.1.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for logtube-1.0.1.tar.gz
Algorithm Hash digest
SHA256 637ab76e290c5147fa3b5a32c39713eb65651c0540865d5b599068230b9ac880
MD5 cb310eb3c234017a6057529040dd2bc5
BLAKE2b-256 e76f807937843c7b38bb7e41fc9c47557df54a524a1fb3442421fe51e07ad17a

See more details on using hashes here.

File details

Details for the file logtube-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: logtube-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for logtube-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 01da644159acfe5704a8b9ff48f1e7f9254176e754f43d816dde14afb5431cf5
MD5 c7b014a05596e2b77446c9799aaab854
BLAKE2b-256 a61816da1959c79aa8b62739a7e6818b7ca900b1f47348571e3b9194217702b3

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