-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
47 lines (40 loc) · 1.82 KB
/
app.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
#!/usr/bin/python
import datetime
import logging
import time
import os
import sys
import traceback
import random
import string
class BusyPod(object):
'''A simple Python class that's only purpose is to generate a ton of useless messages.
This can help deubgging logging systems, in particular OpenShift and Splunk.
'''
def __init__(self):
self.logger = logging.getLogger(__name__)
def main(self):
try:
#formatter = json_log_formatter.JSONFormatter()
#log_fmt = '%(asctime)-15s %(levelname)-8s %(message)s'
log_fmt = '%(message)s'
date_fmt = '%m-%d-%Y %H:%M:%S'
log_level = logging.INFO
if "LOG_TO_FILE" in os.environ:
log_path = os.environ.get('LOG_PATH', '/var/log/')
logging.basicConfig(filename=log_path + 'logs-a-lot.log', format=log_fmt, datefmt=date_fmt, level=log_level)
else:
logging.basicConfig(format=log_fmt, datefmt=date_fmt, level=log_level)
while True:
#datetime.datetime.now().strftime('%m-%d-%Y %H:%M:%S'),
message="{ \"message\":\"%s\", \"forward_message_to_splunk\":\"%s\", \"Severity\" : \"INFO\" }" % ( ''.join(random.SystemRandom().choice(string.digits + string.ascii_letters) for _ in range(random.randint(50, 200))), str(bool(random.getrandbits(1))).lower())
self.logger.info(message)
#time.sleep(random.randint(20, 40))
time.sleep(random.randint(1, 10))
except KeyboardInterrupt:
logging.critical("Terminating due to keyboard interrupt")
except:
logging.critical("Terminating due to unexpected error: %s", sys.exc_info()[0])
logging.critical("%s", traceback.format_exc())
if __name__ == "__main__":
BusyPod().main()