Add an --error-log option to wescamp.py,
...which writes warnings and errors to a specified file
This commit is contained in:
parent
0f9b110d02
commit
18f765246e
1 changed files with 22 additions and 0 deletions
|
@ -406,6 +406,9 @@ if __name__ == "__main__":
|
|||
optionparser.add_option("-b", "--build-system",
|
||||
help = "Path to a github.com/wescamp/build-system checkout.")
|
||||
|
||||
optionparser.add_option("-e", "--error-log",
|
||||
help = "File to append errors and warnings to.")
|
||||
|
||||
options, args = optionparser.parse_args()
|
||||
|
||||
campaignd_configured = False
|
||||
|
@ -425,6 +428,25 @@ if __name__ == "__main__":
|
|||
format='[%(levelname)s] %(message)s',
|
||||
stream=sys.stdout)
|
||||
|
||||
if options.error_log:
|
||||
import time
|
||||
formatter = logging.Formatter(fmt="[%(levelname)s %(asctime)s]\n%(message)s")
|
||||
formatter.converter = time.gmtime
|
||||
handler = logging.FileHandler(options.error_log)
|
||||
handler.setLevel(logging.WARN)
|
||||
handler.setFormatter(formatter)
|
||||
record = logging.LogRecord(
|
||||
name = None,
|
||||
level = logging.INFO,
|
||||
pathname = '',
|
||||
lineno = 0,
|
||||
msg = "{0}\nwescamp.py run start\n".format("="*80),
|
||||
args = [],
|
||||
exc_info = None,
|
||||
)
|
||||
handler.emit(record)
|
||||
logging.getLogger().addHandler(handler)
|
||||
|
||||
server = "localhost"
|
||||
if(options.server != None):
|
||||
server = options.server
|
||||
|
|
Loading…
Add table
Reference in a new issue