Skip to main content

Log and Print

PyPI version License Downloads

A simple logging package that helps you to log what is happening in your application.

Installation

You can install Log and Print using pip:

pip install logandprint

Usage

To start logging it is as simple as importing the logandprint object and issuing the logging commands:

write, info, error, success, warning, debug

To logging a message to the log:

import logandprint as log

log.write("This is a common log message")
log.info("This is log information, it appears blue in the terminal")
log.error("This is an error message, it appears red in the terminal")
log.success("This is a success message, it appears green in the terminal")
log.warning("This is a warning message, it appears yellow in the terminal")
log.debug("This is a debug message, it appears white in the terminal")

The write, info, error, success, warning methods accept two parameters, the message and the console flag (boolean) to display or not the message in the terminal.

In the debub method, messages will only be displayed in the terminal if debug mode is active log.debugMode(True)

setLogFile

By default, the log is saved in the log.log file in the current directory. But you can change the log file by using the setLogFile function.

log.setLogFile("./logs/myLogFile.log")

setMaxFileSize

By default, the log file is rotated once it reaches 2,000,000 bytes (2MB), or when the day changes. You can change the maximum size (in bytes) with setMaxFileSize.

log.setMaxFileSize(10000000)  # 10MB

setBackupCount

When the log file is rotated, by default 1 backup is kept (myLogFile.log.bak1). You can change how many backups are kept with setBackupCount. Older backups are shifted (.bak1 -> .bak2, and so on) and the oldest one beyond the configured count is discarded.

log.setBackupCount(3)  # keeps myLogFile.log.bak1, .bak2 and .bak3

Set it to 0 to disable backups entirely: the log file is simply cleared on rotation instead of being kept, which is the fastest option if you don't care about old logs.

log.setBackupCount(0)

debugMode

The log packet will not be printed to the console. You can change this by setting debugMode to True.

log.debugMode(True)

To stop printing to the console, change the debugMode setting to False. Don't worry, the log file will still be writing.

log.debugMode(False)

enable

To disable the log you can call the enable function and set it to False.

log.enable(False)

And to enable it again you can call the enable function and set it to True.

log.enable(True)

export_to_csv

You can export the log to a csv file by calling the export_to_csv function.

log.export_to_csv("./logs/myLogFile.csv")

Author

  • Guilherme Saldanha

Copyright

This software is free to use and distribute. You can use it for any purpose, but please give credit to the original author.

For more info see LICENSE file.

Download files

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

Source Distribution

logandprint-1.3.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logandprint-1.3.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file logandprint-1.3.0.tar.gz.

File metadata

  • Download URL: logandprint-1.3.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.15

File hashes

Hashes for logandprint-1.3.0.tar.gz
Algorithm Hash digest
SHA256 681791464a50e64827aba5bab420a1430de1c313479e8ddec672f52c0036a954
MD5 6474e6ae2710014e6936ae80c01f14fc
BLAKE2b-256 391909789989b9dfe58de8c5cda956cee31a91aac3c599ddec593a951b04535c

See more details on using hashes here.

File details

Details for the file logandprint-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: logandprint-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.15

File hashes

Hashes for logandprint-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b1e9c3c197b844132f2ed844edf0303fc40be031087960f6294f0a19098d79a
MD5 5f4b64ac89c16387b3e5e7f0f32f24b6
BLAKE2b-256 8248a5d5e54dd07620b0b35e0dae34e48aec3daa8ff3fa856e123ed783ca3198

See more details on using hashes here.

Release history Release notifications | RSS feed

1.3.1

2 files

This release

1.3.0 This release

2 files

1.2.3

2 files

1.2.2

2 files

1.2

2 files

1.1

2 files

1.0.1

2 files

1.0.0

2 files

0.0.3

2 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