Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging level for conan-center hook #280

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e51d6d5
#279 Add logging level for conan-center hook
uilianries Mar 11, 2021
1620811
#279 Logging level name for py2.7
uilianries Mar 11, 2021
2d2d654
Merge branch 'master' of https://github.com/conan-io/hooks into featu…
uilianries Apr 22, 2021
cfcabac
Merge branch 'master' into feature/log-level
uilianries Apr 28, 2021
545aff2
Update hooks/conan-center.py
uilianries Sep 14, 2021
dd4cbc4
Update hooks/conan-center.py
uilianries Sep 14, 2021
53045ab
Update hooks/conan-center.py
uilianries Sep 14, 2021
9988fb7
Merge branch 'master' into feature/log-level
uilianries Sep 14, 2021
badff93
Print warning when error occurs
uilianries Sep 14, 2021
0068ed2
Update hooks/conan-center.py
uilianries Sep 15, 2021
877bbbf
Update tests/test_hooks/conan-center/test_conan-center.py
uilianries Sep 15, 2021
afbf07d
Update tests/test_hooks/conan-center/test_conan-center.py
uilianries Sep 15, 2021
e6cff4f
Update tests/test_hooks/conan-center/test_conan-center.py
uilianries Sep 15, 2021
f646552
Update hooks/conan-center.py
uilianries Sep 15, 2021
9d856d9
Should not show warning for error level
uilianries Sep 20, 2021
fccb765
Fix pylint error message
uilianries Sep 20, 2021
aaa028b
Merge branch 'hotfix/recipe_linter_getvalue' into feature/log-level
uilianries Sep 20, 2021
7ec4281
Fix pylint out message
uilianries Sep 20, 2021
dee5b68
Pylint 2.11 is broken
uilianries Sep 20, 2021
c18b228
Rever recipe linter
uilianries Sep 20, 2021
fb78cd0
Use pylint lower than 2.11
uilianries Sep 20, 2021
3deb863
Merge branch 'master' into feature/log-level
SSE4 Feb 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,16 @@ variable ``CONAN_HOOK_ERROR_LEVEL``:
- ``CONAN_HOOK_ERROR_LEVEL=40`` it will raise if any error happen.
- ``CONAN_HOOK_ERROR_LEVEL=30`` it will raise if any error or warning happen.

If you want to decrease logging level, you can adjust it by the environment variable
``CONAN_HOOK_LOGGING_LEVEL``:

- ``CONAN_HOOK_LOGGING_LEVEL=40`` it will print out only error messages
- ``CONAN_HOOK_LOGGING_LEVEL=WARNING`` it will print out only warning and error messages

It accepts both logging level names and logging level code:
- ERROR: 40
- WARNING/WARN: 30
- INFO: 20

### [Attribute checker](hooks/attribute_checker.py)

Expand Down
18 changes: 14 additions & 4 deletions hooks/conan-center.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ def __init__(self, output, kb_id=None):
if self.kb_id:
self.kb_url = kb_url(self.kb_id)
self._error_level = int(os.getenv("CONAN_HOOK_ERROR_LEVEL", str(NOTSET)))
self._set_logging_level()

def _set_logging_level(self):
level = os.getenv("CONAN_HOOK_LOGGING_LEVEL", str(NOTSET))
name_level = {"ERROR": 40, "WARNING": 30, "WARN": 30, "INFO": 20, "DEBUG": 10, "NOTSET": 0}
self._logging_level = int(level) if level.isdigit() else name_level[level.upper()]
uilianries marked this conversation as resolved.
Show resolved Hide resolved

def _get_message(self, message):
if self._test_name:
Expand All @@ -76,22 +82,26 @@ def _get_message(self, message):
return message

def success(self, message):
self._output.success(self._get_message(message))
if self._logging_level < WARNING:
uilianries marked this conversation as resolved.
Show resolved Hide resolved
self._output.success(self._get_message(message))

def debug(self, message):
if self._error_level and self._error_level <= DEBUG:
self._error = True
self._output.debug(self._get_message(message))
if self._logging_level < INFO:
uilianries marked this conversation as resolved.
Show resolved Hide resolved
self._output.debug(self._get_message(message))

def info(self, message):
if self._error_level and self._error_level <= INFO:
self._error = True
self._output.info(self._get_message(message))
if self._logging_level < WARNING:
uilianries marked this conversation as resolved.
Show resolved Hide resolved
self._output.info(self._get_message(message))

def warn(self, message):
if self._error_level and self._error_level <= WARNING:
self._error = True
self._output.warn(self._get_message(message))
if self._logging_level < ERROR:
uilianries marked this conversation as resolved.
Show resolved Hide resolved
self._output.warn(self._get_message(message))

def error(self, message):
self._error = True
uilianries marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
39 changes: 39 additions & 0 deletions tests/test_hooks/conan-center/test_conan-center.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,3 +1044,42 @@ def package_info(self):
tools.save('conanfile.py', content=self.conanfile_header_only)
output = self.conan(['create', '.', 'name/version@user/test'])
self.assertIn("[LIBRARY DOES NOT EXIST (KB-H054)] OK", output)
self.assertNotIn('does not contain any library', output)

def test_logging_level(self):
conanfile = textwrap.dedent("""\
from conans import ConanFile
import os

class FoobarConan(ConanFile):
author = "Foobar"

def package(self):
pass
uilianries marked this conversation as resolved.
Show resolved Hide resolved
""")
tools.save('conanfile.py', content=conanfile)
output = self.conan(['create', '.', 'name/version@user/test'])
self.assertIn("ERROR: [PACKAGE LICENSE (KB-H012)]", output)
self.assertIn("WARN: [HEADER_ONLY, NO COPY SOURCE (KB-H005)]", output)
self.assertIn("[FPIC MANAGEMENT (KB-H007)] OK", output)

for level in ["INFO", "20"]:
uilianries marked this conversation as resolved.
Show resolved Hide resolved
with tools.environment_append({"CONAN_HOOK_LOGGING_LEVEL": level}):
output = self.conan(['create', '.', 'name/version@user/test'])
self.assertIn("ERROR: [PACKAGE LICENSE (KB-H012)]", output)
self.assertIn("WARN: [HEADER_ONLY, NO COPY SOURCE (KB-H005)]", output)
self.assertIn("[FPIC MANAGEMENT (KB-H007)] OK", output)

for level in ["Warning", "30"]:
with tools.environment_append({"CONAN_HOOK_LOGGING_LEVEL": level}):
output = self.conan(['create', '.', 'name/version@user/test'])
self.assertIn("ERROR: [PACKAGE LICENSE (KB-H012)]", output)
self.assertIn("WARN: [HEADER_ONLY, NO COPY SOURCE (KB-H005)]", output)
self.assertNotIn("[FPIC MANAGEMENT (KB-H007)] OK", output)

for level in ["error", "40"]:
with tools.environment_append({"CONAN_HOOK_LOGGING_LEVEL": level}):
output = self.conan(['create', '.', 'name/version@user/test'])
self.assertIn("ERROR: [PACKAGE LICENSE (KB-H012)]", output)
self.assertNotIn("WARN: [HEADER_ONLY, NO COPY SOURCE (KB-H005)]", output)
self.assertNotIn("[FPIC MANAGEMENT (KB-H007)] OK", output)