Skip to content

Commit c719cbb

Browse files
committed
Create cdr_parser.py
1 parent d888a77 commit c719cbb

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

cdr_parser.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import logging
2+
import time
3+
4+
from daemon import runner
5+
from mod_cdr_main import (
6+
initial_program_setup,
7+
do_main_program,
8+
program_cleanup,
9+
reload_program_config,
10+
)
11+
12+
class App():
13+
14+
def __init__(self):
15+
self.stdin_path = '/dev/null'
16+
self.stdout_path = '/dev/tty'
17+
self.stderr_path = '/dev/tty'
18+
self.pidfile_path = '/var/run/cdr_parser.pid'
19+
self.pidfile_timeout = 5
20+
21+
def run(self):
22+
logger.info("cdr_parser started")
23+
24+
while True:
25+
# Call Main Program
26+
do_main_program()
27+
28+
app = App()
29+
30+
logger = logging.getLogger(__name__)
31+
logger.setLevel(logging.DEBUG)
32+
33+
# Logger Console Handler
34+
ch = logging.StreamHandler() # StreamHandler logs to console
35+
ch.setLevel(logging.DEBUG)
36+
ch_format = logging.Formatter('%(asctime)s - %(message)s')
37+
ch.setFormatter(ch_format)
38+
logger.addHandler(ch)
39+
40+
# Logger File Handler
41+
fh = logging.FileHandler('/var/log/cdr_parser/{0}.log'.format(__name__))
42+
fh.setLevel(logging.INFO)
43+
fh_format = logging.Formatter('%(asctime)s - %(name)s - %(levelname)-8s - %(message)s')
44+
fh.setFormatter(fh_format)
45+
logger.addHandler(fh)
46+
47+
daemon_runner = runner.DaemonRunner(app)
48+
# Don't close logging files during daemonization
49+
daemon_runner.daemon_context.files_preserve=[fh.stream]
50+
daemon_runner.do_action()
51+
52+
logger.info("cdr_parser stopped")

0 commit comments

Comments
 (0)