Package: loggingsfactory
LOGGINGSFACTORYInstallationpip install loggingsfactoryUsageImportfromloggingsfactory.loggingimportLoggersInitializationLoguruMethod 1loggers=Loggers(appname="myapp")Method 2loggers=Loggers(appname="myapp",debug=True)Method 3: not required, but can be done if auto switching of logger type is required for different environmentsloggers=Loggers(appname="myapp",debug=True,host="https://elasticsearch.com:9201",index="appindex",username="user1"pw="userpw")Elasticsearchloggers=Loggers(appname="myapp",debug=False,host="https://elasticsearch.com:9201",index="appindex",username="user1"pw="userpw")AsyncElasticsearchloggers=Loggers(appname="myapp",debug=False,useasync=True,host="https://elasticsearch.com:9201",index="appindex",username="user1"pw="userpw")Log usageLoguru & ElasticsearchUsing default logging datafunction name will be the function that is calling the logdeftest_log():loggers.log("info","log data"){
    "log": "log data",
    "version": "1.0",
    "logger_level": "INFO",
    "functional_name": "test_log",
    "app_name": "myapp",
    "timestamp": "2020-01-01T00:00:00.000Z",
}Using custom function namedeftest_log():loggers.log("info","log data","somefunctionname"){
    "log": "log data",
    "version": "1.0",
    "logger_level": "INFO",
    "functional_name": "somefunctionname",
    "app_name": "myapp",
    "timestamp": "2020-01-01T00:00:00.000Z",
}Using custom log data formatcustom_log_data={"custom_log":"this is a custom log"}deftest_log():loggers.log("info",custom_log_data,None,True){
    "custom_log": "this is a custom log"
}Using default logging data with custom date formatdate="2022/04/27"deftest_log():loggers.log("info","log data",None,False,date){
    "log": "log data",
    "version": "1.0",
    "logger_level": "INFO",
    "functional_name": "test_log",
    "app_name": "myapp",
    "timestamp": "2022/04/27",
}Loguru & AsyncElasticsearchUsing default logging datafunction name will be the function that is calling the logasyncdeftest_log():loggers.async_log("info","log data"){
    "log": "log data",
    "version": "1.0",
    "logger_level": "INFO",
    "functional_name": "test_log",
    "app_name": "myapp",
    "timestamp": "2020-01-01T00:00:00.000Z",
}Using custom function nameasyncdeftest_log():loggers.async_log("info","log data","somefunctionname"){
    "log": "log data",
    "version": "1.0",
    "logger_level": "INFO",
    "functional_name": "somefunctionname",
    "app_name": "myapp",
    "timestamp": "2020-01-01T00:00:00.000Z",
}Using custom log data formatcustom_log_data={"custom_log":"this is a custom log"}asyncdeftest_log():loggers.async_log("info",custom_log_data,None,True){
    "custom_log": "this is a custom log"
}Using default logging data with custom date formatdate="2022/04/27"asyncdeftest_log():loggers.async_log("info","log data",None,False,date){
    "log": "log data",
    "version": "1.0",
    "logger_level": "INFO",
    "functional_name": "test_log",
    "app_name": "myapp",
    "timestamp": "2022/04/27",
}Query usageElasticsearchUsing default query payloaddefget_data():returnloggers.query()Using custom query payloadcustom_payload={"query":{"bool":{"filter":[{"bool":{"should":[{"match_phrase":{"app_name.keyword":"myapp"}}],"minimum_should_match":1,}},{"range":{"timestamp":{"gte":"2021-09-24T02:58:43.647Z","lte":"2022-09-24T02:58:43.647Z","format":"strict_date_optional_time",}}},]}}}defget_data():returnloggers.query(custom_payload)AsyncElasticsearchUsing default query payloadasyncdefget_data():returnawaitloggers.async_query()Using custom query payloadcustom_payload={"query":{"bool":{"filter":[{"bool":{"should":[{"match_phrase":{"app_name.keyword":"myapp"}}],"minimum_should_match":1,}},{"range":{"timestamp":{"gte":"2021-09-24T02:58:43.647Z","lte":"2022-09-24T02:58:43.647Z","format":"strict_date_optional_time",}}},]}}}asyncdefget_data():returnawaitloggers.async_query(custom_payload)SQL Query usageElasticsearch & AsyncElasticsearchUsing query payloadsupports only synchronousquery_statement="SELECT * FROM appindex"defget_data():returnloggers.sql_query(query_statement)