Skip to content

Commit 317db4b

Browse files
committed
Add function for log item
1 parent d2bbe8b commit 317db4b

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ XlsxWriter
22
pandas
33
xlrd
44
openpyxl
5-
progress
5+
progress
6+
PyYAML

src/fosslight_util/set_log.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import logging
77
import os
88
from pathlib import Path
9+
import pkg_resources
10+
import sys
11+
import platform
912
from . import constant as constant
1013

1114

@@ -35,3 +38,20 @@ def init_log(log_file, create_file=True):
3538
logger.propagate = False
3639

3740
return logger
41+
42+
43+
def init_log_item(main_package_name="", path_to_analyze= ""):
44+
45+
_PYTHON_VERSION = sys.version_info[0]
46+
_result_log = {
47+
"Tool Info": main_package_name,
48+
"Python version": _PYTHON_VERSION,
49+
"OS": platform.system()+" "+platform.release(),
50+
}
51+
if main_package_name != "":
52+
pkg_version = pkg_resources.get_distribution(main_package_name).version
53+
_result_log["Tool Info"] = main_package_name +" v."+pkg_version
54+
if path_to_analyze != "":
55+
_result_log["Path to analyze"] = path_to_analyze
56+
57+
return _result_log

tests/test_log.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22
# -*- coding: utf-8 -*-
33
# Copyright (c) 2021 LG Electronics Inc.
44
# SPDX-License-Identifier: Apache-2.0
5-
5+
import yaml
66
from fosslight_util.set_log import init_log
7+
from fosslight_util.set_log import init_log_item
78
from _print_log import print_log
89
from _print_log_with_another_logger import print_log_another_logger
910

1011
def main():
1112
logger = init_log("test_result/log_file1.txt")
1213
logger.warning("TESTING LOG - from 1st Module")
1314

15+
result_log = init_log_item("fosslight_util")
16+
_str_final_result_log = yaml.safe_dump(result_log, allow_unicode=True)
17+
logger.warning(_str_final_result_log)
18+
1419
print_log()
1520
print_log_another_logger()
1621

0 commit comments

Comments
 (0)