Logging handler to send logs to your OpenSearch cluster with bulk SSL. Forked from https://github.com/logzio/logzio-python-handler
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
2.9 KiB

9 years ago
  1. # Logz.io python handler
  2. Python handler that sends logs in bulk over https to logz.io. The handler use an internal buffer, and you can choose the drain timeout, and the number of messages to hold in queue before drain. Everything is working in threads, and they would exit after completing draining all the logs if the main program exits.
  3. **This is BETA. We currently use this handler internally. We will provide tests soon.**
  4. ## Installation
  5. ```bash
  6. pip install logzio-python-handler
  7. ```
  8. ## Python configuration
  9. #### Config File
  10. ```
  11. [handlers]
  12. keys=LogzioHandler
  13. [handler_LogzioHandler]
  14. class=logzio.handler.LogzioHandler
  15. formatter=jsonFormat
  16. args=('token', 10, 20)
  17. [formatters]
  18. keys=jsonFormat
  19. [loggers]
  20. keys=root
  21. [logger_root]
  22. handlers=LogzioHandler
  23. level=INFO
  24. [formatter_jsonFormat]
  25. format={ "loggerName":"%(name)s", "functionName":"%(funcName)s", "lineNo":"%(lineno)d", "levelName":"%(levelname)s", "message":"%(message)s"}
  26. ```
  27. *args=() arguments, by order*
  28. - Your logz.io token
  29. - Number of logs to keep in buffer before draining
  30. - Time to wait before draining, regardless of the previouse setting
  31. - Log type, for searching in logz.io (defaults to "python")
  32. #### Code Example
  33. ```python
  34. import logging
  35. import logging.config
  36. # Say i have saved my configuration under ./myconf.conf
  37. logging.config.fileConfig('myconf.conf')
  38. logger = logging.getLogger('superAwesomeLogzioLogger')
  39. logger.info('Test log')
  40. logger.warn('Warning')
  41. try:
  42. 1/0
  43. except:
  44. logger.exception("Supporting exceptions too!")
  45. ```
  46. ## Django configuration
  47. ```
  48. LOGGING = {
  49. 'version': 1,
  50. 'disable_existing_loggers': False,
  51. 'formatters': {
  52. 'verbose': {
  53. 'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
  54. },
  55. 'json': {
  56. 'format': '{ "loggerName":"%(name)s", "functionName":"%(funcName)s", "lineNo":"%(lineno)d", "levelName":"%(levelname)s", "message":"%(message)s"}'
  57. }
  58. },
  59. 'handlers': {
  60. 'console': {
  61. 'class': 'logging.StreamHandler',
  62. 'level': 'DEBUG',
  63. 'formatter': 'verbose'
  64. },
  65. 'logzio': {
  66. 'class': 'logzio.handler.LogzioHandler',
  67. 'level': 'INFO',
  68. 'formatter': 'json',
  69. 'token': 'token',
  70. 'logs_drain_count': 10,
  71. 'logs_drain_timeout': 5,
  72. 'logzio_type': "django"
  73. },
  74. },
  75. 'loggers': {
  76. 'django': {
  77. 'handlers': ['console', ],
  78. 'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO')
  79. },
  80. 'appname': {
  81. 'handlers': ['console', 'logzio'],
  82. 'level': 'INFO'
  83. }
  84. }
  85. }
  86. ```
  87. *Change*
  88. - token - Your logzio token
  89. - logs_drain_count - Number of logs to keep in buffer before draining
  90. - logs_drain_timeout - Time to wait before draining, regardless of the previouse setting
  91. - logzio_type - Log type, for searching in logz.io (defaults to "python")
  92. - appname - Your django app