This repository has been archived by the owner on Mar 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
53 lines (39 loc) · 1.93 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
# -*- coding: utf-8 -*-
import logone
# Indicate `DEBUG` level (or higher) for the root logger
logone.set_level(level=logone.DEBUG)
# Now, we can log anything to the root logger
logone.debug('Quick zephyrs blow, vexing daft Jim')
logone.info('How quickly daft jumping zebras vex')
def main():
# Create a new logger if you do not want to use the root logger
logger = logone.get_logger('example')
logger.set_level(logone.DEBUG)
# Log something to the logger
logger.debug('Debug message')
logger.info('Info message')
logger.warning('Warn message')
# Set up the logger for logging `DEBUG` messages or higher to `example.log` file
# Learn more at: https://docs.python.org/3/library/logging.handlers.html#logging.handlers.TimedRotatingFileHandler
logger.use_file(enabled=True, file_name='logs/example.log', level=logone.DEBUG,
when='d', interval=1, backup_count=10)
# Set up the logger for logging `DEBUG` messages or higher to Loggly service in real-time
logger.use_loggly(enabled=True, level=logone.DEBUG,
loggly_token='YOUR-CUSTOMER-TOKEN', loggly_tag='Python,Example')
# Log something to the logger, file, and Loggly service
logger.error('Error message')
logger.critical('Critical message')
# Redirect stdout stream to the logger as `INFO` messages (for `print` function,...)
logger.redirect_stdout(enabled=True, log_level=logone.INFO)
# Redirect stderr stream to the logger as `ERROR` messages (for unexpected error,...)
logger.redirect_stderr(enabled=True, log_level=logone.ERROR)
# These will be written to stdout stream and then redirected to the logger
print('Jackdaws love my big sphinx of quartz')
value = 20
print('Value = ', value)
# ZeroDivisionError exception will be written to stderr stream and then redirected to the logger
value = 1 / 0
print(value)
if __name__ == '__main__':
main()