
Initial submission for a Python-based virtualbox installer for StarlingX Co-Authored-By: Ovidiu.Poncea <ovidiu.poncea@windriver.com> Co-Authored-By: Wei Zhou <wei.zhou@windriver.com> Co-Authored-By: William Jia <william.jia@windriver.com> Co-Authored-By: Sebastien Papineau <sebastien.papineau@windriver.com> Co-Authored-By: Timothy Mather <timothy.mather@windriver.com> Co-Authored-By: Paul Buzuloiu <paul.buzuloiu@windriver.com> DocImpact Story: 2005051 Task: 29552 Signed-off-by: Maria Yousaf <maria.yousaf@windriver.com> Change-Id: Iad5b6d8103886d7eeeab7bf2782eca4adb95e3e6
53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
#!/usr/bin/python3
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
|
|
import os
|
|
import datetime
|
|
import logging
|
|
from consts.env import LOGPATH
|
|
|
|
log_dir = ""
|
|
LOG = logging.getLogger()
|
|
|
|
def init_logging(lab_name, log_path=None):
|
|
global LOG, log_dir
|
|
if not log_path:
|
|
log_path = LOGPATH
|
|
lab_log_path = log_path + "/" + lab_name
|
|
|
|
# Setup log sub-directory for current run
|
|
current_time = datetime.datetime.now()
|
|
log_dir = "{}/{}_{}_{}_{}_{}_{}".format(lab_log_path,
|
|
current_time.year,
|
|
current_time.month,
|
|
current_time.day,
|
|
current_time.hour,
|
|
current_time.minute,
|
|
current_time.second)
|
|
if not os.path.exists(log_dir):
|
|
os.makedirs(log_dir)
|
|
|
|
LOG.setLevel(logging.INFO)
|
|
formatter = logging.Formatter("%(asctime)s: %(message)s")
|
|
log_file = "{}/install.log".format(log_dir)
|
|
handler = logging.FileHandler(log_file)
|
|
handler.setFormatter(formatter)
|
|
handler.setLevel(logging.INFO)
|
|
LOG.addHandler(handler)
|
|
handler = logging.StreamHandler()
|
|
handler.setFormatter(formatter)
|
|
LOG.addHandler(handler)
|
|
|
|
# Create symbolic link to latest logs of this lab
|
|
try:
|
|
os.unlink(lab_log_path + "/latest")
|
|
except:
|
|
pass
|
|
os.symlink(log_dir, lab_log_path + "/latest")
|
|
|
|
def get_log_dir():
|
|
return log_dir
|