-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlog.py
69 lines (56 loc) · 1.58 KB
/
log.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
64
65
66
67
68
69
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# log.py: display log messages
#
# Copyright (C) 2014 Politecnico di Torino, Italy
# TORSEC group -- http://security.polito.it
#
# Author: Roberto Sassu <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see
# <http://www.gnu.org/licenses/>.
import sys
verbose_mode = False
fdlog = None
# TODO: make a class?
def set_verbose_mode(mode):
global verbose_mode
verbose_mode = mode
def log_init(logfile = None):
global fdlog
if fdlog != None:
return
if logfile == None:
fdlog = sys.stdout
else:
try:
fdlog = open(logfile, 'wc')
except:
sys.stdout('Error opening %s' %(logfile))
sys.exit(2)
def log_end():
if fdlog != None and fdlog != sys.stdout:
fdlog.close()
def log_message(message = None):
try:
fdlog.write(message)
fdlog.write('\n')
except:
pass
def log_info(message = None):
if verbose_mode == False:
return
log_message('Info: ' + message)
def log_error(message = None):
log_message('Error: ' + message)