Skip to main content

Logthon

A simple logger for Python

Getting Started

These instructions will install the logger to your machine.

Prerequisites

  • Python3
  • PIP3

Installation

pip3 install logthon

Usage

Import

Classic import

from logthon.logthon import Logthon as Logger

Logthon = Logger()

Save output on file

from logthon import Logthon as Logger

Logthon = Logger(save_log=True)

Save output on custom file

from logthon import Logthon as Logger

Logthon = Logger(save_log=True, filename='/path/to/file')

Define module name on log format

from logthon import Logthon as Logger

Logthon = Logger(module_name=__name__)  # or Logger(module_name='my.module.path')

# Example
Logthon.info('This is an info log')
# [2012-01-14 00:00:00] my.module.path - INFO: This is an info log

Info level

Logthon.info('This is an info log')
# [2012-01-14 00:00:00] INFO: This is an info log

Warn level

Logthon.warn('This is a warn log')
# [2012-01-14 00:00:00] WARN: This is a warn log

Error level

Logthon.error('This is an error log')
# [2012-01-14 00:00:00] ERROR: This is an error log

Success level

Logthon.success('This is a success log')
# [2012-01-14 00:00:00] SUCCESS: This is a success log

Critical level

Logthon.critical('This is a critical log')
# [2012-01-14 00:00:00] CRITICAL: This is a critical log

Debug level

Logthon.debug('This is a debug log')
# [2012-01-14 00:00:00] DEBUG: This is a debug log

Log and exit program with error code

You can log a message and exit the program defining optionally and error code.

# Default log level is CRITICAL
# Default error code is 1
Logthon.log_and_exit_with_code('This is a message')

Disable debug level log printing

logthon = Logthon(debug=False)
logthon.debug('This is a debug log')

# Nothing printed

If you want to define log level, you need to import level you want

from logthon.logthon import INFO_LEVEL
from logthon.logthon import WARN_LEVEL
from logthon.logthon import ERRO_LEVEL
from logthon.logthon import SUCC_LEVEL
from logthon.logthon import CRITICAL_LEVEL
from logthon.logthon import DEBUG_LEVEL

# e.g. we want to log with error level and exit
Logthon.log_and_exit_with_code('Log message', level=ERRO_LEVEL)

# e.g. we want to log with debug level and exit with code 5
Logthon.log_and_exit_with_code('Log message', level=DEBUG_LEVEL, error_code=5)

Log a prettified dictionary

You can log a message with a dictionary pretty printed

# Default log level is DEBUG 
Logthon.pretty_print('This is a message', {'key': 'word'})

If you want to define log level, you need to import level you want

from logthon.logthon import INFO_LEVEL
from logthon.logthon import WARN_LEVEL
from logthon.logthon import ERRO_LEVEL
from logthon.logthon import SUCC_LEVEL
from logthon.logthon import CRITICAL_LEVEL
from logthon.logthon import DEBUG_LEVEL

# e.g. we want to log with info level
Logthon.pretty_print('This is a message', {'key': 'word'}, level=INFO_LEVEL)

Contributing

Please read CONTRIBUTING.md for details on code of conduct, and the process for submitting pull requests.

License

This project is licensed under the GNU General Public License v3 (GPLv3), read LICENSE for details

Author

  • Giuseppe "mastrobirraio" Matranga - Initial work - Github

Release files for logthon 2.5.0

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

Source distribution (sdist)

Source distribution for logthon 2.5.0
File Size Uploaded
logthon-2.5.0.tar.gz 18.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for logthon 2.5.0
File Interpreter ABI Platform
logthon-2.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 35.4 kB

Release files / logthon-2.5.0.tar.gz

Download URL logthon-2.5.0.tar.gz
Size 18.0 kB
Tags Source
SHA-256 checksum
How to use checksums
be899b6f8f85d9d3502075b80a63a99fbe310edeefd7c5c4373495a28063b2c1
BLAKE2b-256 checksum
How to use checksums
8fc52a4ef3d74f490f7611040ede5b399aee494b8f0de5e61922684e8cb34e6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.6.14

Release files / logthon-2.5.0-py3-none-any.whl

Download URL logthon-2.5.0-py3-none-any.whl
Size 17.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
831222eaa8f83805bce4081ad117968d4434c1978a75120ec24705143a9873a8
BLAKE2b-256 checksum
How to use checksums
be64d2c740e072b40489d3c4548135796122c2f0df08372568942ed075d556bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.6.14

Release history Release notifications | RSS feed

This release

2.5.0 This release

2 release files

2.4.2

2 release files

2.3.0

1 release file

2.2.3

2 release files

2.2.2

2 release files

2.2.0

2 release files

2.1.5

2 release files

2.1.3

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.6.2

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.2.1

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

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