Skip to content

Commit 400504b

Browse files
authored
Merge pull request #2 from fosslight/develop
Add common constant variables.
2 parents 5aa5dc7 + c9192d8 commit 400504b

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# FOSSLight Util
22

3-
<img src="https://img.shields.io/badge/license-Apache--2.0-orange.svg" alt="FOSSLight Util is released under the Apache-2.0." /> <img src="https://img.shields.io/badge/pypi-v1.0-brightgreen.svg" alt="Current python package version." /> <img src="https://img.shields.io/badge/python-3.6+-blue.svg" />
3+
<img src="https://img.shields.io/pypi/l/fosslight_util" alt="FOSSLight Util is released under the Apache-2.0." /> <img src="https://img.shields.io/pypi/v/fosslight_util" alt="Current python package version." /> <img src="https://img.shields.io/pypi/pyversions/fosslight_util" />
44

55
It is a package that supports common utils used by FOSSLight Scanner.
66

77
## Features
88
1. It simplifies the logger setup.
99
2. It easily outputs csv file and excel file in OSS Report format.
1010
3. It provides a simple function to create a text file.
11+
4. It defines common constant variables.
1112

1213
[or]: http://collab.lge.com/main/x/xDHlFg
1314

@@ -73,6 +74,16 @@ def test():
7374
success, error_msg = write_txt_file("test_result/txt/test.txt",
7475
"Testing - Writing text in a file.")
7576
```
77+
78+
### 4. Load common constant (tests/_print_log_with_another_logger.py)
79+
```
80+
import fosslight_util.constant as constant
81+
82+
83+
logger = logging.getLogger(constant.LOGGER_NAME)
84+
logger.warning("Get a logger after init_log is called once.")
85+
```
86+
7687
## 👏 How to report issue
7788

7889
Please report any ideas or bugs to improve by creating an issue in [fosslight_util repository][cl]. Then there will be quick bug fixes and upgrades. Ideas to improve are always welcome.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
if __name__ == "__main__":
1414
setup(
1515
name='fosslight_util',
16-
version='1.0',
16+
version='1.0.1',
1717
package_dir={"": "src"},
1818
packages=find_packages(where='src'),
1919
description='FOSSLight Util',

src/fosslight_util/set_log.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
import logging
77
import os
88
from pathlib import Path
9+
from . import constant as constant
910

1011

1112
def init_log(log_file, create_file=True):
1213

13-
logger = logging.getLogger('fosslight')
14+
logger = logging.getLogger(constant.LOGGER_NAME)
1415
if not logger.hasHandlers():
1516
log_level = logging.WARNING
1617
formatter = logging.Formatter('%(message)s')

tests/_print_log_with_another_logger.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,10 @@
33
# Copyright (c) 2021 LG Electronics Inc.
44
# SPDX-License-Identifier: Apache-2.0
55
import logging
6+
import fosslight_util.constant as constant
67

78

89
def print_log_another_logger():
9-
logger = logging.getLogger('ANOTHER_LOGGER_TEST')
10-
11-
log_level = logging.WARNING
12-
formatter = logging.Formatter('%(message)s')
13-
14-
console = logging.StreamHandler()
15-
console.setLevel(log_level)
16-
console.setFormatter(formatter)
17-
console.propagate = False
18-
logger.addHandler(console)
10+
logger = logging.getLogger(constant.LOGGER_NAME)
1911

2012
logger.warning("Print log by using anther logger")

0 commit comments

Comments
 (0)