Package: loghandler
loghandlerEasy logging package for all your logging needs.FeaturesLog to multiple endpoints at onceSupport for STDOUT, Elasticsearch, Database (MySQL, PostgreSQL, SQLite), and more coming soon.Easy syntaxFail-over reporting (If one endpoint fails it will be reported to the other endpoints)InstallingInstall loghandler via pippipinstallloghandlerUsingIn your code import LogHandler and initalize it.fromloghandlerimportLogHandlerlogger=LogHandler({"log_level":"DEBUG","outputs":[{"type":"STDOUT"}]})You can now log messages to all your outputs via:logger.log('fatal',Exception("Something went HORRIBLY wrong"))EndpointsThe following endpoints are currently in the works and will be supported soon.logstashsentryGeneral ConfigurationAll endpoints accept a few global settings. They are shown below.log_level: For the output it's applied to, this will overrule the global configuration levelreport_error: If an output fails to send a message, this error will be reported to the other outputs, by default this is True. (It's not recommended to turn this off.)retry_after: Defines how long an output should wait before retrying, by default this is 15s (Defined in seconds)STDOUTTo use STDOUT as a log endpoint, add the following to your outputs array.{"type":"STDOUT"}ElasticsearchTo use elasticsearch as a log endpoint, add the following to your outputs array.{"type":"elasticsearch","config":{"hosts":["https://your-es-host.com:9243"],"ssl":True,"verify_certs":True,"refresh":"wait_for",# Must be either "true", "false" or "wait_for""index":"your-index",# Index will be created if it doesn't exist"api_key":("your-api-key-id","your-api-key-secret")}}Next time something is logged you should see something like the following under your index:{"_index":"logs","_type":"_doc","_id":"some-id","_score":1.0,"_source":{"timestamp":"2021-11-05T04:16:25.250206","level":"DEBUG","hostname":"YOUR-HOSTNAME","message":"division by zero","occurred_at":{"path":"/somepath/test.py","line":22}}}DatabaseTable StructureTable(db_config["table_name"],metadata,Column("id",Integer,primary_key=True),Column("message",Text),Column("level",String),Column("origin",String),Column("timestamp",DateTime),)sqliteTo use sqlite as a log endpoint, add the following to your outputs array.{"type":"sqlite","config":{"table_name":"logs",# Will be created if it doesn't exist"db_path":"/path/to/db.sqlite",# Will be created if it doesn't exist}}Next time something is logged you should see something like the following under your table:('division by zero','DEBUG','/somepath/test.py:31','2021-11-07 01:27:24.755989')mysqlTo use mysql as a log endpoint, add the following to your outputs array.{"type":"mysql","config":{"table_name":"logs","connection_string":"root:example@localhost:3306/example_db"}}Next time something is logged you should see something like the following under your table:division by zero | DEBUG | /somepath/test.py:22 | 2021-11-07 01:46:58pgsql (PostgreSQL)To use pgsql as a log endpoint, add the following to your outputs array.{"type":"pgsql","config":{"table_name":"logs","connection_string":"postgres:postgres@localhost:5432/example"}}Next time something is logged you should see something like the following under your table:division by zero | DEBUG | /somepath/test.py:22 | 2021-11-07 01:46:58