Package: logEZ
logEZMake logging easy in your applications! Use this simple library to easily use logs in any of your applications.InstallationpipinstalllogEZHow to usefromlogEZimportMyLoggerlogger=MyLogger()More inSample AppMyLoggerclassTheinitmethod of the MyLogger class takes four optional arguments:log_file_namelogging_leveldisable_console_logsdisable_file_logsThe default values are:log_file_name="logEZ.log",logging_level="INFO",disable_console_logs=False,disable_file_logs=Falselog_file_name: Specify the file name of your log file here.logging_level: Specify the default logging level of your logs. It can beINFO,DEBUG,WARNING,ERROR, orCRITICAL.disable_console_logs: Disable the console logging of your logs, if set toTrue.disable_file_logs: Disable the file logging of your logs, if set toTrue.MyLoggermethodsOnce you have initialized a MyLogger object, you can use the following methods:setLoggingLevel(level: str): Change the logging level after initializingMyLogger(). (Refer to logging_level underMyLoggerclassfor levels.)debug(inString: str): Log aDEBUGlevel message. Accepts a string input.info(inString: str): Log anINFOlevel message. Accepts a string input.warning(inString: str): Log aWARNINGlevel message. Accepts a string input.error(inString: str, exc_info: Optional[bool] = False): Log anERRORlevel message. Accepts a string input. Ifexc_infois set to True, it appends the complete execution information along with the log string.critical(inString: str, exc_info: Optional[bool] = False): Log aCRITICALlevel message. Accepts a string input. Ifexc_infois 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.Usingexc_infoto send complete execution informationTheexc_infoparameter is an optional argument available in theerrorandcriticalmethods of theMyLoggerclass. When set toTrue, 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 theexc_infoparameter with myError andcriticalmethods:fromlogEZimportMyLoggerlogger=MyLogger()defdivide(a,b):try:result=a/bexceptZeroDivisionErrorase:logger.myError(f"An error occurred while dividing{a}by{b}",exc_info=True)returnNonereturnresultdivide(10,0)In this example, we have adividefunction that takes two numbers as arguments and attempts to perform a division operation. If aZeroDivisionErrorexception is raised, theerrormethod is called with theexc_infoparameter set toTrue. 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-2314:35:28-root:ERROR:Anerroroccurredwhiledividing10by0Traceback(mostrecentcalllast):File"example.py",line7,individeresult=a/b
ZeroDivisionError:divisionbyzeroSimilarly, you can use theexc_infoparameter with thecriticalmethod 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: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.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.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:Configuration from file supportLog rotation functionalitySupport for custom log handlersColored console logsEnhanced context information in log messagesImproved exception handling and loggingIntegrated performance metricsAdvanced filtering capabilitiesAsynchronous logging supportBetter documentation and examplesWe'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 atgehlotkunal@outlook.comor 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 LogUnreleased[0.1.0]UpdatedRefactored 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 mainMyLoggerclass.handlers.py: Contains handlers for logging to files and consoles.formatters.py: Contains the log formatter used for log messages.Updated the__init__.pyfile to import necessary components for easier library usage.Enhanced the library with docstrings for better documentation and understanding.Updated theREADME.mdfile to provide clearer instructions on how to use the library, including examples and explanations of the new features.Improved thesetup.pyfile to adhere to the latest Python norms and standards.Addednoxas a development dependency to simplify the development workflow.[0.0.3] - 2022-05-08UpdatedUpdated 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-08FixedFixing project directory name[0.0.1] - 2022-05-08AddedFirst ReleaseRemovedRemovedrequirements.txtRemovedloggingfrominstall_requires