Skip to main content

logEZ

Make logging easy in your applications! Use this simple library to easily use logs in any of your applications.

Installation

pip install logEZ

How to use

from logEZ import MyLogger

logger = MyLogger()

More in Sample App

MyLogger class

The init method of the MyLogger class takes four optional arguments:

  • log_file_name
  • logging_level
  • disable_console_logs
  • disable_file_logs

The default values are:

log_file_name="logEZ.log",
logging_level="INFO",
disable_console_logs=False,
disable_file_logs=False
  • log_file_name: Specify the file name of your log file here.
  • logging_level: Specify the default logging level of your logs. It can be INFO, DEBUG, WARNING, ERROR, or CRITICAL.
  • disable_console_logs: Disable the console logging of your logs, if set to True.
  • disable_file_logs: Disable the file logging of your logs, if set to True.

MyLogger methods

Once you have initialized a MyLogger object, you can use the following methods:

  • setLoggingLevel(level: str): Change the logging level after initializing MyLogger(). (Refer to logging_level under MyLogger class for levels.)
  • debug(inString: str): Log a DEBUG level message. Accepts a string input.
  • info(inString: str): Log an INFO level message. Accepts a string input.
  • warning(inString: str): Log a WARNING level message. Accepts a string input.
  • error(inString: str, exc_info: Optional[bool] = False): Log an ERROR level message. Accepts a string input. If exc_info is set to True, it appends the complete execution information along with the log string.
  • critical(inString: str, exc_info: Optional[bool] = False): Log a CRITICAL level message. Accepts a string input. If exc_info is set to True, it appends the complete execution information along with the log string.
  • myExcept(inString: str): Log an exception message. Accepts a string input.

Using exc_info to send complete execution information

The exc_info parameter is an optional argument available in the error and critical methods of the MyLogger class. When set to True, it appends the complete execution information, including the traceback, along with the log message. This can be particularly useful when debugging errors or critical issues that require detailed information about the context in which they occurred.

Here's an example of how to use the exc_info parameter with myError and critical methods:

from logEZ import MyLogger

logger = MyLogger()

def divide(a, b):
    try:
        result = a / b
    except ZeroDivisionError as e:
        logger.myError(f"An error occurred while dividing {a} by {b}", exc_info=True)
        return None
    return result

divide(10, 0)

In this example, we have a divide function that takes two numbers as arguments and attempts to perform a division operation. If a ZeroDivisionError exception is raised, the error method is called with the exc_info parameter set to True. This will log the error message along with the complete execution information, including the traceback, making it easier to understand the context in which the error occurred.

The output of this code will be:

01-04-23 14:35:28 - root : ERROR : An error occurred while dividing 10 by 0
Traceback (most recent call last):
  File "example.py", line 7, in divide
    result = a / b
ZeroDivisionError: division by zero

Similarly, you can use the exc_info parameter with the critical method if you want to log critical messages with complete execution information.

Why use logEZ?

The logEZ library provides a simplified interface to work with the standard logging module in Python. While it does not introduce any new functionality or significant improvements over the built-in logging module, it may be helpful for developers who want a more straightforward, easy-to-use API for common logging tasks.

Advantages of logEZ:

  1. Simplified initialization: The logEZ library makes it easier to set up logging with default values and simple customization options. You can easily configure log file names, logging levels, and toggle console or file logging with just a few parameters.
  2. Unified logging methods: The logEZ library offers a single class, MyLogger, with methods for different logging levels (debug, info, warning, error, critical), making it more convenient to use compared to the standard logging module, which requires calling separate functions for each logging level.
  3. Easier traceback logging: The logEZ library provides the exc_info parameter for error and critical level logs, making it more straightforward to include traceback information when logging exceptions.

However, for more advanced logging use cases or if you require fine-grained control over your logging configuration, the built-in logging module offers more comprehensive features and flexibility. If you are already familiar with the standard logging module, you may not find logEZ to be significantly more helpful.

In summary, the logEZ library can be useful for developers looking for a simpler and more accessible interface for basic logging tasks. However, it might not offer substantial advantages over the built-in logging module for more experienced users or advanced logging scenarios.

What's next?

We have some exciting plans for the future development of logEZ, and we're always looking for ways to make it even more useful for our users. Here's a list of features we're considering adding:

  1. Configuration from file support
  2. Log rotation functionality
  3. Support for custom log handlers
  4. Colored console logs
  5. Enhanced context information in log messages
  6. Improved exception handling and logging
  7. Integrated performance metrics
  8. Advanced filtering capabilities
  9. Asynchronous logging support
  10. Better documentation and examples

We're open to contributions! If you'd like to help implement any of these features or have suggestions for improvements, please feel free to reach out to us. You can contact us at gehlotkunal@outlook.com or connect with us on Twitter at @ZackCodesAI.

We're looking forward to collaborating with the community to make logEZ an even more valuable and versatile logging library for Python developers!

Change Log

Unreleased

[0.1.0]

Updated

  • Refactored the code to adhere to PEP8 standards for better readability and maintainability.
  • Added type hints to function signatures for improved code comprehension and editor support.
  • Improved exception handling with more specific exceptions and error messages.
  • Modularized the code into separate files for better organization and extensibility:
    • mylogger.py: Contains the main MyLogger class.
    • handlers.py: Contains handlers for logging to files and consoles.
    • formatters.py: Contains the log formatter used for log messages.
  • Updated the __init__.py file to import necessary components for easier library usage.
  • Enhanced the library with docstrings for better documentation and understanding.
  • Updated the README.md file to provide clearer instructions on how to use the library, including examples and explanations of the new features.
  • Improved the setup.py file to adhere to the latest Python norms and standards.
  • Added nox as a development dependency to simplify the development workflow.

[0.0.3] - 2022-05-08

Updated

  • Updated code with method name fix and logging level method.
  • Added "How to use" with complete method definition in README.md

[0.0.2] - 2022-05-08

Fixed

  • Fixing project directory name

[0.0.1] - 2022-05-08

Added

  • First Release

Removed

  • Removed requirements.txt
  • Removed logging from install_requires

Metadata

Release files for logEZ 0.1.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 logEZ 0.1.0
File Size Uploaded
logEZ-0.1.0.tar.gz 7.0 MB Details

Built distribution (wheel)

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

Total release size: 7.0 MB

Release files / logEZ-0.1.0.tar.gz

Download URL logEZ-0.1.0.tar.gz
Size 7.0 MB
Tags Source
SHA-256 checksum
How to use checksums
8744802ae309a905fbd60b4b79f4f576de958685d15833f0c6274d0c11e741ce
BLAKE2b-256 checksum
How to use checksums
d44a1a78fa74a44175bc6e7167d4bf6103c68521712131b883d58ba5f435a100
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.0

Release files / logEZ-0.1.0-py3-none-any.whl

Download URL logEZ-0.1.0-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
04db8cc570224e7c84215607817c9e1c9df768e87df11c35b71a96fe3d3ac7d9
BLAKE2b-256 checksum
How to use checksums
07e353aff3adf165197c34ec93c2cb0232a92ffd7ca0644645e8eac3e2a65c65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.0

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

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