Package: pyEventLogger
pyEventLogger v1.1pyEventLogger is a simple Python Library for making customized Logs of certain events that occur in a program. The logs
can be fully customized and can be printed in colored format or can be stored in a file.Note: Your software or the console in which you are going to printcolored logsshould support the ANSI Escape
Sequences or thecolored logsfeature may not work!InstallationTo install this library, type:pipinstallpyEventLoggerin the Command Prompt or TerminalImportTo import this library, use the following code:frompyEventLoggerimportpyLoggerLogging Levels:There are 6 different types of logs in this library. In order of increasing importance, they are:DebugInfoWarningSuccessErrorCriticalPrint basic logs:Use the following program to print basic logs in the Console:frompyEventLoggerimportpyLogger# Import the librarylogger=pyLogger(colored_output=True)# Make an object of the pyLogger Class# Note: If your console doesn't support the ANSI Escape Sequences then use: colored_output=Falselogger.debug(message="This is Debug Message!")# Debug Loglogger.info(message="This is Information Message!")# Information Loglogger.warn(message="This is Warning Message!")# Warning Loglogger.success(message="This is Success Message!")# Success Loglogger.error(message="This is Error Message!")# Error Loglogger.critical(message="This is Critical Message!")# Critical LogThe pyLogger ClassParametersThe pyLogger Class has the following Parameters:colored_output--> Set it toTrueif you want colored outputprint_log--> Set it toTrueif you want your log to be printed out into the Consolemake_file--> Set it toTrueif you want your log to be stored in a filefile_name--> If you set themake_fileparameter toTrue, then you can use this parameter to change
the file namerewrite_file--> Set it toTrueif you want your log file to be rewritten after you run the programfile_logs--> If you want only the specified log messages in your file then pass this parameter with a list
containing the log types you want. Example: If you want only the errors and critical messages in file then you pass
the value of the parameter aspython ['ERROR', 'CRITICAL']Customizing the Logs:Customizing the Log text:To customize a log, use theformat_log(log_type, format_string)function. For example, if you want to customize
the log type of Debug, then use the following code:frompyEventLoggerimportpyLoggerlogger=pyLogger()debug_format_string="[log_type] [time] [message]"# Define a variable for the format stringlogger.format_log(log_type='DEBUG',format_string=debug_format_string)# Use this function to format a loglogger.debug(message="This is Debug Message!")See the above example. It has a variable calleddebug_format_stringwhich defines how the contents of the Log
should be.Rules for format strings:The format string should have a format like"[time] [log_type] [message]". Where the contents in the squared
braces[]will be replaced with the values of the parameters you pass to that function. You can give any number of
spaces you like between the contents. Example:"[log_type]     [time]      [message]". The log will be printed in the same format and also can be written in a
file in the same format.There are some special meanings to some parameters likelog_type. The program automatically adds the log type even
if the user doesn't pass that parameter's value to a function, also thetimeparameter will be given a default
value of the time that function is called.You can add any number of contents in a log. Example Code:frompyEventLoggerimportpyLoggerlogger=pyLogger()debug_format_string="[log_type] [time] [message] [file_name]"# Add a 'file_name' contentlogger.format_log(log_type='DEBUG',format_string=debug_format_string)logger.debug(message="This is Debug Message!",file_name="main.py")# Set a value to the added contentCustomizing the Log text color/style:To customize a log's color, use theformat_log_color(log_type, format_string)function. For example, if you want
to customize the log type of Debug, then use the following code:frompyEventLoggerimportpyLoggerlogger=pyLogger(colored_output=True)# Set the colored output to Truedebug_format_string="[log_type] [time] [file_name] [message]"# Define a variable for the format stringdebug_format_color="[bold cyan black] [normal yellow black] [italic magenta black] [normal white black]"# Define a variable for the format colorlogger.format_log(log_type='DEBUG',format_string=debug_format_string)# Format the loglogger.format_log_color(log_type='DEBUG',format_string=debug_format_color)# Format the colorlogger.debug(message="This is Debug Message!",file_name="main.py")In the above example, you can see that there is a variable defined for the log color.Rules for format color:The format of color string should be the same as text string.The contents should be seperated by space.The first content in square braces should be the text style likenormal,bold,italic,etc.The second content should be the text color and the third should be background color. You can also use HEX values for
colors too!These three elements should be seperated by a space.The first content will be the style for first item in log and so on...Changing the format of time:To change the format of time, use theformat_timevariable of thepyLoggerclass It should be in string
format and is the same format as used in Pythontime.strftime()function.Including error messages in error and critical log:To include the error messages along with the log message in error and critical logs, set theinclude_error_messageparameter of the error and critical functions toTrueExample Code:importtimeimportrandomfrompyEventLoggerimportpyLoggerlogger=pyLogger(colored_output=False,make_file=True,file_name='math',rewrite_file=True)logger.format_log(log_type="INFO",format_string="[time] [log_type] [message] [answer]")logger.format_log_color(log_type="INFO",format_string="[bold yellow black][bold magenta black][normal #FFFFFF black][italic green black]")whileTrue:try:logger.debug(message="Taking two random numbers...")n1=random.randint(-10,10)n2=random.randint(-10,10)logger.debug(message="Successfully found two random numbers!")logger.info(message=f"Two numbers are{n1}and{n2}")logger.debug(message="Starting operations with two numbers...")addition=n1+n2logger.info(message="Added two numbers:",answer=addition)subtraction=n2-n1logger.info(message="Subtracted two numbers:",answer=subtraction)multiplication=n1*n2logger.info(message="Multiplied two numbers:",answer=multiplication)division=n2/n1logger.info(message="Divided two numbers:",answer=division)logger.success(message="Successfully completed operations with two numbers!")exceptZeroDivisionError:logger.error(message="An Error Occurred!",include_error_message=True)time.sleep(10)ContributorsThanks to all the contributors(on github):Sid72020123Quantum-CodesChange Log:15/01/2022(v0.1) - First made this library and updated it15/01/2022(v0.1.2) - Updated and added many features21/01/2022(v0.5.0) - Updated and added some other features23/01/2022(v0.7) - Added Exceptions27/01/2022(v0.9) - Added features to error and critical logs28/01/2022(v1.0) - Added doc-strings to code29/01/2022(v1.0) - First Release!11/09/2022(v1.1) -  Added some new things! Thanks to Quantum-CodesThank You!