|
1 | 1 | # This is an example project of Logtail python integration
|
2 |
| -# This project shocases how to use Logtail in your python projects |
3 |
| -# For more infromation please visit https://github.com/logtail/logtail-python |
| 2 | +# This project showcases how to use Logtail in your python projects |
| 3 | +# For more information please visit https://github.com/logtail/logtail-python |
4 | 4 |
|
5 | 5 | # SETUP
|
6 | 6 |
|
7 |
| -# Import Logtail client library and deault logging library |
| 7 | +# Import Logtail client library and default logging library |
8 | 8 | from logtail import LogtailHandler
|
9 | 9 | import logging
|
10 | 10 | import sys
|
|
21 | 21 | logger = logging.getLogger(__name__)
|
22 | 22 | logger.handlers = []
|
23 | 23 | logger.setLevel(logging.DEBUG) # Set minimal log level
|
24 |
| -logger.addHandler(handler) # asign handler to logger |
| 24 | +logger.addHandler(handler) # assign handler to logger |
25 | 25 |
|
26 | 26 | # LOGGING EXAMPLE
|
27 |
| -# Following code shocases logger usage |
| 27 | +# Following code showcases logger usage |
28 | 28 |
|
29 | 29 | # Send debug log using the debug() method
|
30 | 30 | logger.debug('I am using Logtail!')
|
31 | 31 |
|
32 | 32 | # Send info level log about interesting events using the info() method
|
33 | 33 | logger.info('I love Logtail!')
|
34 | 34 |
|
35 |
| -# Send warning level log about warrying events using the warning() method |
36 |
| -# You can also add ecustom structured information to the log by passing it as a second argument |
| 35 | +# Send warning level log about worrying events using the warning() method |
| 36 | +# You can also add custom structured information to the log by passing it as a second argument |
37 | 37 | logger.warning('Log structured data', extra={
|
38 | 38 | 'item': {
|
39 | 39 | 'url': "https://fictional-store.com/item-123",
|
|
42 | 42 | })
|
43 | 43 |
|
44 | 44 | # Send error level log about errors in runtime using the error() method
|
45 |
| -logger.error('Oops! An error occured!') |
| 45 | +logger.error('Oops! An error occurred!') |
46 | 46 |
|
47 |
| -# Send critical level log about critical events in runtume using the critical() method |
| 47 | +# Send critical level log about critical events in runtime using the critical() method |
48 | 48 | logger.critical('Its not working, needs to be fixes ASP!')
|
49 | 49 |
|
50 | 50 | # Send exception level log about errors in runtime using the exception() method
|
51 | 51 | # Error level log will be sent. Exception info is added to the logging message.
|
52 | 52 | # This method should only be called from an exception handler.
|
53 | 53 | try:
|
54 |
| - nonexisting_function() # Calling nonexisting function |
| 54 | + nonexisting_function() # Calling non-existing function |
55 | 55 | except Exception as Argument:
|
56 | 56 | logger.exception("Error occurred while calling non-existing function") # Additional info will be added
|
57 | 57 | # OUTPUT:
|
|
0 commit comments