Skip to main content

Log Data Integration with ELK

Below is the technical implementation of Logs.
1

Add “Logger Util” created to your project and import into your program.

Python

from logger import api_logger or import logging

Java

or import org.slf4j.Logger; // for direct object usage
2

Initialize the 'logger_sdk' with service and environment details

Follow lower case for Environment, servicename, Service Name: {productname}–{be/ai/fe}–{environment}.

Python

Java

3

Basic Logging

  • Use “Context” for adding the details related to the function(like API, method, backend data), and runtime details etc.
  • Extra entity to store supplementary or additional information specific to the event or operation being logged.like task completion, or process, user specific detalis etc..
  • Python

    Java

    4

    Decorator for logging function duration

    Python

    Java

    5

    Error Logging

    Incase if the application deployed using kubernaties, and logs are logged into standard output so below steps and log directory paths may not necessary for now. Also, you may need to enable configuration for to write logs to stdout/stderr.

    Python

    Java

    Reference Notes:
  • Added the log structure which can be used common for API/Backend/database by passing relavent details like for context, extra sub-entities.
  • Added log structures specific for API/Backend/database.