Greendeck-Logging:
Install from pip
https://pypi.org/project/greendeck-logging/
pip install greendeck-logging
How to use ?
import the library
import greendeck_logging
There are Two class GdLoggingStack, and GdLogging
If you want to save the log in memory as stack and send data after complete the process, you can use GdLoggingStack for sending a bulk data
Declare Variables
LOG_ECS_HOST = < YOUR_LOG_ECS_HOST >
LOG_ECS_INDEX = < LOG_ECS_INDEX >
LOG_ECS_TYPE = < LOG_ECS_TYPE >
service_name = < service_name >
username = < YOUR_USERNAME >
password = < YOUR_PASSWORD >
Here default values are
LOG_ECS_INDEX = gdlogging, LOG_ECS_TYPE = '_doc' , username = None , password = None
GdLoggingStack
Send the log data in bulk
gdl_stack = GdLoggingStack( LOG_ECS_HOST,
LOG_ECS_INDEX,
LOG_ECS_TYPE,
SERVICE_NAME,
username,
password )
**default value: LOG_ECS_INDEX = 'gdlogging', LOG_ECS_TYPE = '_doc', username = None, password = None
Usage and functionality
There are following function for capturing the events
-
For Error
gdl_stack.error("your message")
-
For Debug
gdl_stack.debug("your message")
-
For Counter Status
gdl_stack.counter_message(message, value)
default value = 1 -
counter_website
gdl_stack.counter_website(website_id, message, value)
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 element in the stack
gdl_stack.show()
-
push all element to elastic search
gdl_stack.push()
GdLogging It update one element at a time
gdl = GdLogging( LOG_ECS_HOST,
LOG_ECS_INDEX,
LOG_ECS_TYPE,
SERVICE_NAME,
username,
password )
**default value: LOG_ECS_INDEX = 'gdlogging', LOG_ECS_TYPE = '_doc', username = None, password = None
Usage and functionality
There are following function for capturing the events
-
For Error
gdl.error("your message")
-
For Debug
gdl.debug("your message")
-
For Counter Status
gdl.counter_message(message, value)
default value = 1 -
counter_website
gdl.counter_website(website_id, message, value)
default value = 1
Example of the object which will save into the elastic search
"_index" : "gd_log",
"_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
}
}
}