What is Logging?

Logging is the output of your system. It let’s you know when something goes wrong with your system and it is not working as expected. It might have a problem connecting to the database or may just be throwing an exception which you haven’t thought of.

In addition the log shows the system is working properly. It shows that the systems functionalities are working and everything is working as expected. Both parts enabling the developers and maintainers to easily debug.

The stack

In this case we’ll be using EFK(Elastic Fluentd and Kibana) Fluentd being the agent forwarding the logs to elastic and Kibana the visualizer.

The application will be a python app. All of the the components can be run in Docker containers but that isn’t a must.


Logging in Python

Python has a built in library called logging, this library is very simple to use. You can choose the level of logging the format of the log and the handler(which is essentially where the logs will go to e.g. a file).

A code snippet like this:

import logging

def main():
    logging.basicConfig(level="INFO")
    logging.info("Hey I'm a logger!")

if __name__ == '__main__':
    main()

#logging #kibana #fluentd #elasticsearch #python

Python logs — a json’s journey to Elasticsearch
10.60 GEEK