Skip to main content

Greendeck-Logging:

Greendeck ![logging]

Install from pip

https://pypi.org/project/greendeck-logging/

pip install greendeck-logging

This library can be used for save the critical log, message, info data for your internal services in elasticsearch and create a nice visualization through kibana. For creating visualization in kibana you can refer this documentation

if you don't have elasticsearch and kibana you can refer this blog

How to use?

import the library
from greendeck_logging import GdLogging
from greendeck_logging import GdLoggingStack

There are Two ways to save the log data, by bulk (GdLoggingStack) and one by one ( GdLogging)

If you want to save the log in memory as stack and send data after process completes, use GdLoggingStack. It saves the log messages in stack and send to elastic search on calling push method.

Variables to connect elasticsearch to store the log data

LOG_ECS_HOST =  < YOUR_LOG_ECS_HOST >
LOG_ECS_INDEX = < LOG_ECS_INDEX >
LOG_ECS_TYPE = < LOG_ECS_TYPE >
service_name = < service_name >

if elasticsearch requires username and password to connect, provide in LOG_ECS_HOST in a standard format like https://username:password@elasticsearch_host:port_no Eg : https://admin:admin123@127.0.0.0:9200/

Some Default Values are :

LOG_ECS_INDEX = gdlogging, LOG_ECS_TYPE = '_doc'

if you want save data in other index name instead of gdlogging , assign LOG_ECS_INDEX = "your index name"

GdLoggingStack : Send the bulk log data to elasticsearch

from greendeck_logging import GdLoggingStack
gdl_stack = GdLoggingStack(LOG_ECS_HOST = LOG_ECS_HOST,
                          service_name = service_name  
                          LOG_ECS_INDEX = "gdlogging",
                          LOG_ECS_TYPE = "_doc",
                          )

**default value: LOG_ECS_INDEX = 'gdlogging', LOG_ECS_TYPE = '_doc',

**LOG_ECS_TYPE and SERVICE_NAME are required field

Methods and their functionality

There are following function for capturing the events

  • For capturing Error message and info of the error due to which occur ,
    gdl_stack.error("your message", info = {}, value = 1)
    default, value = 1, info = {} # info can be dictionary

  • To save Debug message and send the object as info
    gdl_stack.debug("your debug message", info = {}, value = 1)

  • To increament the response status of the services like 200, 404 etc
    gdl_stack.counter_message(message, info = {}, value = 1)
    default, value = 1

  • To increment the message for a particular website ( It can be your unique identifier depending on requirement )
    gdl_stack.counter_website(website, message, info = {}, value = 1)
    default, value = 1

  • clear the stack
    gdl_stack.clear()

  • total element in stack
    gdl_stack.count()

  • show the first element in the stack
    gdl_stack.show_one()

  • show all elements in the stack
    gdl_stack.show()

  • push all elements to elastic search
    gdl_stack.push()

** Don't forget to push the element to elastic search at end of your stack, use gdl_stack.push() for update the data in elastic search

GdLogging : It updates one element at a time

from greendeck_logging import GdLogging
gdl = GdLogging(LOG_ECS_HOST = LOG_ECS_HOST,
                          service_name = service_name  
                          LOG_ECS_INDEX = "gdlogging",
                          LOG_ECS_TYPE = "_doc",
                          )

**default value: LOG_ECS_INDEX = 'gdlogging', LOG_ECS_TYPE = '_doc',

Usage and functionality

There are following function for capturing the events

  • For capturing Error message and info due to which occur
    gdl.error("your message", info = {}, value = 1)
    default, value = 1 , info = {}

  • For capturign Debug message
    gdl.debug("your message", info = {}, value = 1) default, value = 1

  • To increament the response status of the services like 200, 404 etc
    gdl.counter_message(message, info = {}, value = 1)
    default, value = 1

  • To increment the message for a particular website ( It can be your unique identifier depending on requirement )
    gdl.counter_website(website, message, info = {}, value = 1)
    default, value = 1

Example of the object which will save into the elastic search

     "_index" : "gd_logging",
        "_type" : "_doc",
        "_id" : "0TASCGsBFBI3I7B8680B",
        "_score" : 2.3312538,
        "_source" : {
          "service_name" : "class_service",
          "log_type" : "info",
          "created_at" : "2019-05-30T14:59:45.452035",
          "meta" : {
            "file_name" : "service.py",
            "user_name" : "user",
            "system_name" : "user-300-15ISK",
            "os_name" : "Linux"
          },
          "counter_status" : {  
            "message" : "response status",
            "counter_type" : "status",
            "counter_name" : "201",
            "counter_value" : 1
          }
        }
      }

Release files for greendeck-logging 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for greendeck-logging 0.2.0
File Size Uploaded
greendeck-logging-0.2.0.tar.gz 5.2 kB Details

Release files / greendeck-logging-0.2.0.tar.gz

Download URL greendeck-logging-0.2.0.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1584597e2463d9f39cce425f9c0caf34ac9e8189e8014def3176544c6ca41082
BLAKE2b-256 checksum
How to use checksums
8964a39f4fe693cae1d379c4e132c5600390449734ac8532ff8fe74348690499
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.6.9

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 release file

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

3 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page