Package: iilog-pckg
iilog is an alternative library tologgingiilog provides a little more comfortable logging experience.
It is my (@kyasuda516) own reconfiguration of Python's stdliblogging.FeaturesA solution for those who feel slightly dissatisfied with the usability of the built-in logging library.Logger instances can be created in a way that is very similar to using thelogging.basicConfigfunction.The usage of accessing the root logger is designed to be as invisible as possible.InstallationYou can install iilog withpython-mpipinstalliilog-pckgOtherwise, you can install directly from the github repo usingpython-mpipinstallgit+https://github.com/kyasuda516/iilog-pckg.gitExample UsageSimple examplesample.py:fromiilog.loggersimportLoggerimportiilog# define loggerslogger1=Logger(filename='myapp.log',filemode='w',encoding='UTF-8')importsyslogger2=Logger(format=r'%(asctime)s%(levelname)-8s%(name)-15s%(message)s',datefmt=r'%Y-%m-%d%H:%M:%S',stream=sys.stdout,level=iilog.env.WARNING)formatter=iilog.formatters.Formatter(iilog.formatters.BASIC_FORMAT)handler=iilog.handlers.RotatingFileHandler(filename='dev.log',maxBytes=256,backupCount=3)handler.setFormatter(formatter)logger3=Logger(handlers=[handler])# logginglogger1.warning('Watch out!')logger1.info('I told you so')logger2.warning('Watch out!')logger2.info('I told you so')logger3.error('An unknown error occured.')logger3.error('An unknown error occured.')logger3.error('An unknown error occured.')logger3.error('An unknown error occured.')logger3.error('An unknown error occured.')The results are as follows:$pythonsample.py2023-07-0102:03:04WARNINGiilog.loggers.Logger.i1Watchout!

$catmyapp.log
Watchout!
Itoldyouso

$catdev.log
ERROR:iilog.loggers.Logger.i2:Anunknownerroroccured.

$catdev.log.1
ERROR:iilog.loggers.Logger.i2:Anunknownerroroccured.
ERROR:iilog.loggers.Logger.i2:Anunknownerroroccured.
ERROR:iilog.loggers.Logger.i2:Anunknownerroroccured.
ERROR:iilog.loggers.Logger.i2:Anunknownerroroccured.For more detailsTheiilog.loggers.Loggerconstructor works in much the same way as thelogginglibrary'sbasicConfigfunction. The following is the description oflogging.basicConfig()'s parameters taken from the official documentation and added with strikethrough decoration according to the unique specification:filename– Specifies that aFileHandlerbe created, using the specified filename, rather than aStreamHandler.filemode– Iffilenameis specified, open the file in thismode. Defaults to'a'.format– Use the specified format string for the handler. Defaults to attributeslevelname,nameandmessageseparated by colons.datefmt– Use the specified date/time format, as accepted bytime.strftime().style– Ifformatis specified, use this style for the format string. One of'%','{'or'$'forprintf-style,str.format()orstring.Templaterespectively. Defaults to'%'.level– Set therootlogger level to the specifiedlevel.stream– Use the specified stream to initialize theStreamHandler. Note that this argument is incompatible withfilename- if both are present, aValueErroris raised.handlers– If specified, this should be an iterable of already created handlers to add to therootlogger. Any handlers which don’t already have a formatter set will be assigned the default formatter created in this function. Note that this argument is incompatible withfilenameorstream- if both are present, aValueErroris raised.force– If this keyword argument is specified as true, any existing handlers attached to the root logger are removed and closed, before carrying out the configuration as specified by the other arguments.encoding– If this keyword argument is specified along withfilename, its value is used when theFileHandleris created, and thus used when opening the output file.errors– If this keyword argument is specified along withfilename, its value is used when theFileHandleris created, and thus used when opening the output file. If not specified, the value ‘backslashreplace’ is used. Note that ifNoneis specified, it will be passed as such toopen(), which means that it will be treated the same as passing ‘errors’.Also, theiilog.formatters.Formatter,iilog.filters.Filter,iilog.handlers.FileHandler,iilog.handlers.StreamHandlerclasses and so on, which you should use when specifyinghandlers, are exactly the same as defined in thelogginglibrary.Example of loading a config fileconfig.yml:version:1formatters:simple:format:'%(asctime)s-%(name)s-%(levelname)s-%(message)s'handlers:console:class:logging.StreamHandlerlevel:DEBUGformatter:simplestream:ext://sys.stdoutloggers:foobarExample:level:DEBUGhandlers:-consolepropagate:nosample2.py:importiilogiilog.env.set_config(filename='config.yml',encoding='UTF-8')logger=iilog.env.get_logger('foobarExample')logger.info('I told you so')The results are as follows:$pythontest.py2023-07-0102:03:04,005-foobarExample-INFO-ItoldyousoFor more detailsTakes the logging configuration from a file or dictionary. The parameters are as follows:filename– Use the specified filename to read the logging configuration from the file.fileformat– Iffilenameis specified, read it as a file written in this format. Accepts either'yaml'or'json'. If not specified, it will be determined based onfilename's extension.encoding– If this keyword argument is specified along withfilename, its value is used when opening the file.config– Takes the logging configuration from the specified dictionary, as accepted by thelogging.configmodule'sdictConfig(). Note that this argument is incompatible withfilenameorconfig- if both are present, aValueErroris raised.For any grammar or examples not listed here, please refer to the documentation (sorry, currently under construction).LicenseThis software is released under the MIT License, see LICENSE.