-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappSimples.py
24 lines (21 loc) · 873 Bytes
/
appSimples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# this is a simple application that just writes to a log file.
# the objective is just to produce a log to test another solution that consumes logs (cloudwatch agent and cloudwatch logs).
# keywords: log, logfile, cloudwatch, cloudwatch agent, cloudwatch logs
# .
import random
import time
from datetime import date
from datetime import datetime
# this loop writes to the log every 1 second
while True:
now = datetime.now()
with open('appSimples.log', 'a') as f: # this is the log file
f.write('appSimples: ' + str(now.strftime("%d/%m/%Y %H:%M:%S")) + ' logging... OK\n')
n = random.randint(1,1000) # out of every 10 tries, one will be an error logging
if n%10 == 0:
f.write('appSimples: ' + str(now.strftime("%d/%m/%Y %H:%M:%S")) + ' ERRO: SE FERROU\n')
f.close()
del(now)
del(f)
del(n)
time.sleep(1)