-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_debug.py
67 lines (53 loc) · 1.54 KB
/
print_debug.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
54
55
56
57
58
59
60
61
62
63
import logging
import logging.handlers
import datetime
import time
from logging.handlers import RotatingFileHandler
import glob
import my_subprocess_run
import multiprocessing
def my_compress(filename):
search=filename + "*[0-9]"
list=glob.glob(search)
elements=len(list)
#print(list)
#print ("len", elements)
base="gzip -f "
q=multiprocessing.Queue()
for x in list:
cmd=base + x
my_subprocess_run.run_cmd(cmd)
#print(cmd)
return(list)
# source: https://stackoverflow.com/questions/9106795/python-logging-and-rotating-files
def log_setup(filename):
#log_handler = logging.handlers.WatchedFileHandler(filename)
size=30 * 1024 * 1024 # 30MB
log_handler = RotatingFileHandler(filename, maxBytes=size, backupCount=10)
formatter = logging.Formatter(
'%(asctime)s program_name [%(process)d]: %(message)s',
'%b %d %H:%M:%S')
#formatter.converter = time.gmtime # if you want UTC time
#formatter.converter = time.localtime()
log_handler.setFormatter(formatter)
logger = logging.getLogger()
logger.addHandler(log_handler)
logger.setLevel(logging.DEBUG)
def my_debug(s,v):
date = datetime.datetime.now()
total=70
l=len(s)
s1=s
v1=v
for x in range (0,total - l):
s=s+" "
#s=str(date)+ " " + s +":"
s= s +": "
logging.info(s+str(v))
if __name__ == "__main__":
filename="testlog"
log_setup(filename)
print_debug("this is a sample message with Value","1234")
# compress
filename="/mnt/ramdisk/jk_pylon.log"
my_compress(filename)