Skip to content

Commit 500699c

Browse files
committed
Change log level by message
1 parent 1fdfe3e commit 500699c

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

src/fosslight_source/convert_scancode.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
logger = logging.getLogger(constant.LOGGER_NAME)
2222
_PKG_NAME = "fosslight_source"
23-
_ERROR_PREFIX = "* Error : "
2423

2524

2625
def convert_json_to_excel(scancode_json, excel_name):
@@ -52,40 +51,40 @@ def convert_json_to_excel(scancode_json, excel_name):
5251
file_list, key=lambda row: (''.join(row.licenses)))
5352
sheet_list["SRC_" + file_name] = [scan_item.get_row_to_print() for scan_item in file_list]
5453
except Exception as ex:
55-
pass
54+
logger.warn("Error parsing "+file+":"+str(ex))
5655

5756
success_to_write, writing_msg = write_excel_and_csv(excel_name, sheet_list)
58-
logger.warn("* Writing excel :"+str(success_to_write)+ " "+writing_msg)
57+
logger.info("Writing excel :"+str(success_to_write)+ " "+writing_msg)
5958
if success_to_write:
6059
_result_log["OSS Report"] = excel_name+".xlsx"
6160

6261
except Exception as ex:
6362
success = False
64-
msg = _ERROR_PREFIX+str(ex)
63+
logger.warn(str(ex))
6564

6665
scan_result_msg = str(success)+" "+msg
6766
_result_log["Scan Result"] = scan_result_msg.strip()
6867

6968
try:
7069
_str_final_result_log = yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True)
71-
logger.warn("\n"+_str_final_result_log)
70+
logger.info(_str_final_result_log)
7271
except Exception as ex:
73-
logger.warn(_ERROR_PREFIX+"Failed to print result log. "+ str(ex))
72+
logger.warn("Failed to print result log.: "+ str(ex))
7473

7574
return file_list
7675

7776

7877
def get_detected_licenses_from_scancode(scancode_json_file):
7978
file_list = []
8079
try:
81-
logger.warn("Start parsing " + scancode_json_file)
80+
logger.info("Start parsing " + scancode_json_file)
8281
with open(scancode_json_file, "r") as st_json:
8382
st_python = json.load(st_json)
8483
rc, file_list, msg= parsing_file_item(st_python["files"])
85-
logger.warn("|---"+msg)
84+
logger.info("|---"+msg)
8685
except Exception as error:
87-
logger.warn(_ERROR_PREFIX+"Parsing -"+str(error))
88-
logger.warn("|---Number of files detected: " + str(len(file_list)))
86+
logger.warn("Parsing "+scancode_json_file+":"+str(error))
87+
logger.info("|---Number of files detected: " + str(len(file_list)))
8988
return file_list
9089

9190

src/fosslight_source/run_scancode.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
logger = logging.getLogger(constant.LOGGER_NAME)
2525
warnings.filterwarnings("ignore", category=FutureWarning)
2626
_PKG_NAME = "fosslight_source"
27-
_ERROR_PREFIX = "* Error : "
2827

2928

3029
def main():
@@ -99,7 +98,7 @@ def run_scan(path_to_scan, output_file_name="",
9998
output_json_pp=output_json_file,
10099
only_findings=True)
101100
if not rc:
102-
msg += _ERROR_PREFIX+"Source code analysis failed.\n"
101+
msg += "Source code analysis failed."
103102
success = False
104103
if results:
105104
sheet_list = {}
@@ -114,15 +113,16 @@ def run_scan(path_to_scan, output_file_name="",
114113

115114
success_to_write, writing_msg = write_excel_and_csv(
116115
output_file, sheet_list)
117-
logger.warn("* Writing excel :"+str(success_to_write)+ " "+writing_msg)
116+
logger.info("Writing excel :"+str(success_to_write)+ " "+writing_msg)
118117
if success_to_write:
119118
_result_log["OSS Report"] = output_file +".xlsx"
120119
except Exception as ex:
121120
success = False
122-
msg = _ERROR_PREFIX + str(ex)+"\n"
121+
msg = str(ex)
122+
logger.error("Analyze "+path_to_scan+":"+msg)
123123
else:
124124
success = False
125-
msg = _ERROR_PREFIX+"Check the path to scan. :" + path_to_scan+"\n"
125+
msg = "Check the path to scan. :" + path_to_scan
126126

127127
if not return_results:
128128
result_list = []
@@ -131,9 +131,9 @@ def run_scan(path_to_scan, output_file_name="",
131131
_result_log["Output Directory"] = output_dir
132132
try:
133133
_str_final_result_log = yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True)
134-
logger.warn("\n"+_str_final_result_log)
134+
logger.info(_str_final_result_log)
135135
except Exception as ex:
136-
logger.warn(_ERROR_PREFIX+"Failed to print result log. "+ str(ex))
136+
logger.warn("Failed to print result log. "+ str(ex))
137137
return success, _str_final_result_log, result_list
138138

139139

0 commit comments

Comments
 (0)