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.

111 lines
3.2 KiB

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