Skip to main content

a simple python logger that logs to file and stdout

Project description

bestlog

version license python_version coverage

this is a simple python logger that logs to file and stdout

I originally wanted to call it 'easylog' but there is already a package with that name on pypi

Install

$ pip install bestlog

Using

from bestlog import logger
import logging

log = logger.get("test")
# or
log = logging.getLogger("test")

def main():
    log.info("what the fuck")

if __name__ == '__main__':
    logger.init("test")
    main()

output:

[2022-11-16 21:37:06,032][INFO]: what the fuck

you can find log file in the 'logs' folder of the current directory, one log file per day

Advance

from bestlog import logger
import logging

logger.default_log_path = "/var/log/test/"
logger.default_log_level = logging.DEBUG
logger.default_backup_days = 30

log = logger.get("test")

def main():
    log.debug("what the fuck")

if __name__ == '__main__':
    logger.init("test")
    main()

you can specify the path to save the log file

you can set how many days the log file will be retained, default 0 is unlimited

With tag

from bestlog import logger

class Worker:
    def __init__(self, name):
        self.name = name
        self.log = logger.get("test", name)

    def do_something(self):
        self.log.info("hello")

def main():
    worker1 = Worker("bob")
    worker2 = Worker("jack")
    worker1.do_something()
    worker2.do_something()

if __name__ == '__main__':
    logger.init("test", tag = True)
    main()

output:

[2022-11-16 21:42:49,469][INFO][bob]: hello
[2022-11-16 21:42:49,470][INFO][jack]: hello

you can distinguish between the logs of different workers based on their tag

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

bestlog-1.2.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file bestlog-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: bestlog-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for bestlog-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e168d95221182b4785d8ad08950b34312faf36a2c52322008f5abb46c6c1dbfb
MD5 7b5dd5ca67d4bbfb44d0a31691a0e36d
BLAKE2b-256 f454d2863a3a2af37fac46023460b5608f3ee120938ceae1946ecd6eb46682d7

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