6 from utils.io
import open_file, EOL
7 from utils.error_handling
import Error
9 def log(msg, options=None):
10 """! @brief Write message into log file if any, or to standard output if verbose mode is on.
11 @param msg String to log.
12 @param options User options.
17 if options
is not None:
19 setattr(log,
"log_filename", options.log_filename)
20 setattr(log,
"verbose", options.verbose)
22 if log.log_filename
is not None:
23 log_file =
open_file(log.log_filename,
'w+')
28 if hasattr(log,
"log_filename")
and log.log_filename
is not None:
30 log_file =
open_file(log.log_filename,
'a')
36 elif hasattr(log,
"verbose")
and log.verbose:
38 except IOError
as exception:
39 raise Error(
"Cannot write into log file '%s'." % options.log_filename, exception)
def open_file
Open file in specified mode (automatically decode file in unicode).
def log
Write message into log file if any, or to standard output if verbose mode is on.