Browse Source

Fixed flusher for serverless (#50)

* Fixed flusher for serverless

* fixed flusher

* Update README.md

Co-Authored-By: Ido Halevi <32218210+idohalevi@users.noreply.github.com>

* Update README.md

Co-Authored-By: Stefan (Shalom) <imnotashrimp@users.noreply.github.com>

* Update README.md

Co-Authored-By: Stefan (Shalom) <imnotashrimp@users.noreply.github.com>

Co-authored-by: Stefan (Shalom) <imnotashrimp@users.noreply.github.com>
Co-authored-by: Ido Halevi <32218210+idohalevi@users.noreply.github.com>
opensearch
Miri 4 years ago
committed by GitHub
parent
commit
3efc0ff160
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 6 deletions
  1. +19
    -6
      README.md
  2. +20
    -0
      logzio/flusher.py

+ 19
- 6
README.md View File

@ -69,22 +69,31 @@ format={"additional_field": "value"}
Please note, that you have to configure those parameters by this exact order. Please note, that you have to configure those parameters by this exact order.
i.e. you cannot set Debug to true, without configuring all of the previous parameters as well. i.e. you cannot set Debug to true, without configuring all of the previous parameters as well.
#### Serverless platforms
If you're using a serverless function, you'll need to import and add the LogzioFlusher annotation before your sender function. To do this, in the code sample below, uncomment the `import` statement and the `@LogzioFlusher(logger)` annotation line.
#### Code Example #### Code Example
```python ```python
import logging import logging
import logging.config import logging.config
# If you're using a serverless function, uncomment.
# from logzio.flusher import LogzioFlusher
# Say i have saved my configuration under ./myconf.conf # Say i have saved my configuration under ./myconf.conf
logging.config.fileConfig('myconf.conf') logging.config.fileConfig('myconf.conf')
logger = logging.getLogger('superAwesomeLogzioLogger') logger = logging.getLogger('superAwesomeLogzioLogger')
logger.info('Test log')
logger.warn('Warning')
# If you're using a serverless function, uncomment.
# @LogzioFlusher(logger)
def my_func():
logger.info('Test log')
logger.warn('Warning')
try:
1/0
except:
logger.exception("Supporting exceptions too!")
try:
1/0
except:
logger.exception("Supporting exceptions too!")
``` ```
#### Extra Fields #### Extra Fields
@ -98,6 +107,7 @@ For example:
logger.info('Warning', extra={'extra_key':'extra_value'}) logger.info('Warning', extra={'extra_key':'extra_value'})
``` ```
## Django configuration ## Django configuration
``` ```
LOGGING = { LOGGING = {
@ -142,6 +152,7 @@ LOGGING = {
} }
``` ```
*Change* *Change*
- token - Your logzio token - token - Your logzio token
- url - Logz.io Listener address - url - Logz.io Listener address
@ -151,6 +162,8 @@ LOGGING = {
- appname - Your django app - appname - Your django app
## Release Notes ## Release Notes
- 2.0.14
- Added flusher decorator for serverless platforms(@mcmasty)
- 2.0.13 - 2.0.13
- Add support for `pypy` and `pypy3`(@rudaporto-olx) - Add support for `pypy` and `pypy3`(@rudaporto-olx)
- Add timeout for requests.post() (@oseemann) - Add timeout for requests.post() (@oseemann)


+ 20
- 0
logzio/flusher.py View File

@ -0,0 +1,20 @@
import functools
import logging
class LogzioFlusher(logging.Logger):
def __init__(self, logger):
self.logger = logger
def __call__(self, function):
@functools.wraps(function)
def wrapper(*args, **kwargs):
try:
return function(*args, **kwargs)
except Exception as e:
self.logger.exception('call failed: {}'.format(e))
raise
finally:
[h.flush() for h in self.logger.root.handlers]
return wrapper

Loading…
Cancel
Save