Package: janus-logging
janus-loggingsync and async logging within one logger instance.Installationpipinstalljanus-loggingUsageDefaultimportasyncioimportloggingimportsysimportjanus_loggingdefthreaded(sync_log,counter:int):foriinrange(counter):sync_log.info('s-Hello #%s'%i)sync_log.info('s-Finished #%s'%counter)asyncdefasync_coro(async_log,counter:int):foriinrange(counter):awaitasync_log.info('aio-Hello #%s'%i)awaitasync_log.info('aio-Finished #%s'%counter)#counter=4name='my_janus_logger'level=logging.DEBUGstream=sys.stdoutloop=asyncio.get_event_loop()#logger=janus_logging.JanusLogger(name=name,level=level,loop=loop,stream=stream)loop.run_until_complete(asyncio.gather(loop.run_in_executor(None,threaded,logger.logger_sync(),counter),async_coro(logger.logger_async(),counter)))logger.shutdown()##loop.close()The output of above will look like:s-Hello#0s-Hello#1s-Hello#2aio-Hello#0s-Hello#3s-Finished#4aio-Hello#1aio-Hello#2aio-Hello#3aio-Finished#4Please note, that the output might be different on your instance.JSONSimply usefixtures.importasyncioimportloggingimportsysimportjanus_loggingdefthreaded(sync_log,counter:int):foriinrange(counter):sync_log.info('s-Hello #%s'%i,extra=dict(counter=i,log_type='sync',log_status='in progress'))sync_log.info('s-Finished #%s'%counter,extra=dict(total=counter,log_type='sync',log_status='finished'))asyncdefasync_coro(async_log,counter:int):foriinrange(counter):awaitasync_log.info('aio-Hello #%s'%i,extra=dict(counter=i,log_type='async',log_status='in progress'))awaitasync_log.info('aio-Finished #%s'%counter,extra=dict(total=counter,log_type='async',log_status='finished'))#counter=4name='my_janus_logger'level=logging.DEBUGstream=sys.stdoutloop=asyncio.get_event_loop()#logger=janus_logging.JanusLogger(name=name,level=level,loop=loop,fixture=janus_logging.fixture_json,stream=stream,extra=dict(bla='blabla'))loop.run_until_complete(asyncio.gather(loop.run_in_executor(None,threaded,logger.logger_sync(logger_name='logger_sync'),counter),async_coro(logger.logger_async(logger_name='logger_async'),counter)))logger.shutdown()##loop.close()The output of above will look like:{"level":"INFO","msg":"s-Hello #0","log_type":"sync","bla":"blabla","logger_name":"logger_sync","counter":0,"log_status":"in progress","logged_at":"2019-09-27T12:00:02.517101+02:00","line_numer":35,"function":"threaded","file_path":"demo_janus_log.py"}{"level":"INFO","msg":"aio-Hello #1","log_type":"async","logged_at":"2019-09-27T12:00:02.518000+02:00","line_number":60,"function":"info","file_path":"/home/madkote/janus-logging/janus_logging/__init__.py","bla":"blabla","logger_name":"logger_async","counter":1,"log_status":"in progress"}...CustomIf a custom logger, formatter, handler are required, then create customfixturesand pass them to theJanusLogger.deffixture_custom(name:str,level:int,loop:loop:asyncio.AbstractEventLoop,**kwargs)->logging.Logger:...return...logger=janus_logging.JanusLogger(...,fixture=fixture_custom,...)DevelopmentIssues and suggestions are welcome throughissuesChanges1.3.2 (2020-11-25)Cleanup, remove dependency fromaiologger, which has too many issues right now.1.3.1 (2020-02-05)Cleanupadd missing parameter forformatter1.3.0 (2020-01-31)CleanupFix duplicate handlers1.2.1 (2019-11-19)Fixshutdown()1.2.0 (2019-10-04)ExecutorbasedAsyncLoggerAdapterdue to issues withaiologger==0.4.01.1.1 (2019-10-01)FixSyncJsonFormatter1.1.0 (2019-09-27)AddAsyncNullHandler1.0.0 (2019-09-27)Initial release