You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Version 3.0.0 of this project ends support for Python 2.7, 3.3, and 3.4. We recommend migrating your projects to Python 3.5 or newer as soon as possible. We'll be happy to answer any questions you have in [a GitHub issue](https://github.com/logzio/logzio-python-handler/issues).
9
+
Version 3.0.0 of this project ends support for Python 2.7, 3.3, and 3.4. We recommend migrating your projects to Python
10
+
3.5 or newer as soon as possible. We'll be happy to answer any questions you have
11
+
in [a GitHub issue](https://github.com/logzio/logzio-python-handler/issues).
10
12
11
13
Thanks! <br>
12
14
The Logz.io Integrations team
@@ -15,31 +17,38 @@ The Logz.io Integrations team
15
17
16
18
This is a Python handler that sends logs in bulk over HTTPS to Logz.io.
17
19
The handler uses a subclass named LogzioSender (which can be used without this handler as well, to ship raw data).
18
-
The LogzioSender class opens a new Thread, that consumes from the logs queue. Each iteration (its frequency of which can be configured by the logs_drain_timeout parameter), will try to consume the queue in its entirety.
20
+
The LogzioSender class opens a new Thread, that consumes from the logs queue. Each iteration (its frequency of which can
21
+
be configured by the logs_drain_timeout parameter), will try to consume the queue in its entirety.
19
22
Logs will get divided into separate bulks, based on their size.
20
-
LogzioSender will check if the main thread is alive. In case the main thread quits, it will try to consume the queue one last time, and then exit. So your program can hang for a few seconds, until the logs are drained.
21
-
In case the logs failed to be sent to Logz.io after a couple of tries, they will be written to the local file system. You can later upload them to Logz.io using curl.
22
-
23
+
LogzioSender will check if the main thread is alive. In case the main thread quits, it will try to consume the queue one
24
+
last time, and then exit. So your program can hang for a few seconds, until the logs are drained.
25
+
In case the logs failed to be sent to Logz.io after a couple of tries, they will be written to the local file system.
26
+
You can later upload them to Logz.io using curl.
23
27
24
28
## Installation
29
+
25
30
```bash
26
31
pip install logzio-python-handler
27
32
```
28
33
29
-
If you'd like to use [Trace context](#trace-context), you need to install the OpenTelemetry logging instrumentation dependency by running the following command:
34
+
If you'd like to use [Trace context](#trace-context), you need to install the OpenTelemetry logging instrumentation
- Log type, for searching in logz.io (defaults to "python")
84
-
- Time to sleep between draining attempts (defaults to "3")
85
-
- Logz.io Listener address (defaults to "https://listener.logz.io:8071")
86
-
- Debug flag. Set to True, will print debug messages to stdout. (defaults to "False")
87
-
- Backup logs flag. Set to False, will disable the local backup of logs in case of failure. (defaults to "True")
88
-
- Network timeout, in seconds, int or float, for sending the logs to logz.io. (defaults to 10)
89
-
- Retries number (retry_no, defaults to 4).
90
-
- Retry timeout (retry_timeout) in seconds (defaults to 2).
91
-
92
-
Please note, that you have to configure those parameters by this exact order.
93
-
i.e. you cannot set Debug to true, without configuring all of the previous parameters as well.
99
+
100
+
- Your logz.io token
101
+
- Log type, for searching in logz.io (defaults to "python")
102
+
- Time to sleep between draining attempts (defaults to "3")
103
+
- Logz.io Listener address (defaults to "https://listener.logz.io:8071")
104
+
- Debug flag. Set to True, will print debug messages to stdout. (defaults to "False")
105
+
- Backup logs flag. Set to False, will disable the local backup of logs in case of failure. (defaults to "True")
106
+
- Network timeout, in seconds, int or float, for sending the logs to logz.io. (defaults to 10)
107
+
- Retries number (retry_no, defaults to 4).
108
+
- Retry timeout (retry_timeout) in seconds (defaults to 2).
109
+
110
+
Please note, that you have to configure those parameters by this exact order.
111
+
i.e. you cannot set Debug to true, without configuring all of the previous parameters as well.
94
112
95
113
#### Dict Config
114
+
96
115
```python
97
116
LOGGING= {
98
117
'version': 1,
@@ -125,24 +144,33 @@ LOGGING = {
125
144
}
126
145
}
127
146
```
147
+
128
148
Replace:
149
+
129
150
* <<LOGZIO-TOKEN>> - your logz.io account token.
130
-
* <<LOGZIO-URL>> - logz.io url, as described [here](https://docs.logz.io/user-guide/accounts/account-region.html#regions-and-urls).
151
+
* <<LOGZIO-URL>> - logz.io url, as
152
+
described [here](https://docs.logz.io/user-guide/accounts/account-region.html#regions-and-urls).
153
+
131
154
#### Serverless platforms
132
155
133
-
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.
134
-
**Note:** For the LogzioFlusher to work properly, you'll need to make sure that the Logz.io. handler is added to the root logger. See the configuration above for an example.
156
+
If you're using a serverless function, you'll need to import and add the LogzioFlusher annotation before your sender
157
+
function. To do this, in the code sample below, uncomment the `import` statement and the `@LogzioFlusher(logger)`
158
+
annotation line.
159
+
**Note:** For the LogzioFlusher to work properly, you'll need to make sure that the Logz.io. handler is added to the
160
+
root logger. See the configuration above for an example.
135
161
136
162
#### Dynamic Extra Fields
163
+
137
164
If you prefer, you can add extra fields to your logs dynamically, and not pre-defining them in the configuration.
138
165
This way, you can allow different logs to have different extra fields.
139
-
Example in the code below.
166
+
Example in the code below.
140
167
141
168
#### Code Example
142
169
143
170
```python
144
171
import logging
145
172
import logging.config
173
+
146
174
# If you're using a serverless function, uncomment.
logger.error("Error test log") # Outputs: {"message":"Error test log","foo":"bar","counter":1,"err_msg":"Failed to run due to exception.","status_code":500}
178
-
206
+
logger.error(
207
+
"Error test log") # Outputs: {"message":"Error test log","foo":"bar","counter":1,"err_msg":"Failed to run due to exception.","status_code":500}
208
+
179
209
# If you'd like to remove filters from future logs using the logger.removeFilter option:
logger.debug("Debug test log") # Outputs: {"message":"Debug test log","foo":"bar","counter":1}
211
+
logger.debug("Debug test log") # Outputs: {"message":"Debug test log","foo":"bar","counter":1}
182
212
183
213
```
184
214
185
215
#### Extra Fields
186
-
In case you need to dynamic metadata to a speific log and not [dynamically to the logger](#dynamic-extra-fields), other than the constant metadata from the formatter, you can use the "extra" parameter.
187
-
All key values in the dictionary passed in "extra" will be presented in Logz.io as new fields in the log you are sending.
216
+
217
+
In case you need to dynamic metadata to a speific log and not [dynamically to the logger](#dynamic-extra-fields), other
218
+
than the constant metadata from the formatter, you can use the "extra" parameter.
219
+
All key values in the dictionary passed in "extra" will be presented in Logz.io as new fields in the log you are
220
+
sending.
188
221
Please note, that you cannot override default fields by the python logger (i.e. lineno, thread, etc..)
- Changed log levels on `_flush_queue()` method (@hilsenrat)
322
359
323
360
- 2.0.15
324
361
- Added flusher decorator for serverless platforms(@mcmasty)
325
-
- Add support for `python3.7` and `python3.8`
362
+
- Add support for `python3.7` and `python3.8`
326
363
327
-
- 2.0.13
364
+
- 2.0.13
328
365
- Add support for `pypy` and `pypy3`(@rudaporto-olx)
329
-
- Add timeout for requests.post() (@oseemann)
366
+
- Add timeout for requests.post() (@oseemann)
330
367
- 2.0.12 - Support disable logs local backup
331
368
- 2.0.11 - Completely isolate exception from the message
332
369
- 2.0.10 - Not ignoring formatting on exceptions
@@ -340,11 +377,12 @@ LOGGING = {
340
377
- 2.0.2 - Support for formatted messages (Thanks @johnraz!)
341
378
- 2.0.1 - Added __all__ to __init__.py, so support * imports
342
379
- 2.0.0 - Production, stable release.
343
-
-*BREAKING* - Configuration option logs_drain_count was removed, and the order of the parameters has changed for better simplicity. Please review the parameters section above.
344
-
- Introducing the LogzioSender class, which is generic and can be used without the handler wrap to ship raw data to Logz.io. Just create a new instance of the class, and use the append() method.
380
+
-*BREAKING* - Configuration option logs_drain_count was removed, and the order of the parameters has changed for
381
+
better simplicity. Please review the parameters section above.
382
+
- Introducing the LogzioSender class, which is generic and can be used without the handler wrap to ship raw data to
383
+
Logz.io. Just create a new instance of the class, and use the append() method.
0 commit comments