Skip to content

Commit

Permalink
adjust log level and detail
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Kowalleck <[email protected]>
  • Loading branch information
jkowalleck committed Dec 15, 2023
1 parent fa93b55 commit e9f3e18
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
17 changes: 9 additions & 8 deletions cyclonedx_py/_internal/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def _validate(self, output: str) -> bool:
self._logger.warning('Validation skipped.')
return False

self._logger.info('Validating to schema: %s/%s', self._schema_version.to_version(), self._output_format.name)
self._logger.info('Validating result to schema: %s/%s', self._schema_version.to_version(), self._output_format.name)
from cyclonedx.validation import make_schemabased_validator

validation_error = make_schemabased_validator(
Expand All @@ -186,19 +186,20 @@ def _validate(self, output: str) -> bool:
).validate_str(output)
if validation_error:
self._logger.debug('Validation Errors: %r', validation_error.data)
self._logger.error('The output is invalid to schema '
self._logger.error('The result is invalid to schema '
f'{self._schema_version.to_version()}/{self._output_format.name}')
self._logger.error('Please report the issue and provide all input data to: '
'https://github.com/CycloneDX/cyclonedx-python/issues/new?'
'template=ValidationError-report.md&labels=ValidationError&title=%5BValidationError%5D')
self._logger.warning('Please report the issue and provide all input data to: '
'https://github.com/CycloneDX/cyclonedx-python/issues/new?'
'template=ValidationError-report.md&'
'labels=ValidationError&title=%5BValidationError%5D')
raise ValueError('result is schema-invalid')
self._logger.info('Valid.')
self._logger.debug('result is schema-valid')
return True

def _write(self, output: str, outfile: TextIO) -> int:
self._logger.info('Writing to: %s', outfile.name)
written = outfile.write(output)
self._logger.info('Wrote %i bytes to %s', written, outfile.name)
self._logger.debug('Wrote %i bytes to %s', written, outfile.name)
return written

def _make_output(self, bom: 'Bom') -> str:
Expand Down Expand Up @@ -242,7 +243,7 @@ def run(*, argv: Optional[List[str]] = None, **kwargs: Any) -> int:
return 1
del arg_parser, argv

ll = (logging.NOTSET, logging.WARNING, logging.INFO, logging.DEBUG)[min(3, args.pop('verbosity'))]
ll = (logging.WARNING, logging.INFO, logging.DEBUG)[min(2, args.pop('verbosity'))]
lh = logging.StreamHandler(sys.stderr)
lh.setLevel(ll)
lh.setFormatter(logging.Formatter('%(levelname)-8s | %(name)s > %(message)s'))
Expand Down
1 change: 1 addition & 0 deletions cyclonedx_py/_internal/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ def _add_ld(name: str, extras: Set[str]) -> Optional['Component']:
if _existed:
self._logger.debug('existing component: %r', le.component)
else:
self._logger.info('add component for package %r', name)
self._logger.debug('add component: %r', le.component)
le.added2bom = True
bom.components.add(le.component)
Expand Down
13 changes: 8 additions & 5 deletions cyclonedx_py/_internal/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,14 @@ def __call__(self, *, # type:ignore[override]

return self._make_bom(rc, rf)

def _make_bom(self, rc: Optional['Component'], rf: 'RequirementsFile') -> 'Bom':
def _make_bom(self, root_c: Optional['Component'], rf: 'RequirementsFile') -> 'Bom':
from .utils.bom import make_bom

bom = make_bom()
bom.metadata.component = root_c
self._logger.debug('root-component: %r', root_c)
self._add_components(bom, rf)
bom.metadata.component = rc

return bom

def _add_components(self, bom: 'Bom', rf: 'RequirementsFile') -> None:
Expand All @@ -174,9 +176,10 @@ def _add_components(self, bom: 'Bom', rf: 'RequirementsFile') -> None:

for requirement in rf.requirements:
component = self._make_component(requirement, index_url, extra_index_urls)
self._logger.debug('Add component: %r', component)
if not component.version:
self._logger.warning('Component has no pinned version: %r', component)
self._logger.info('add component for line %r', requirement.line)
self._logger.debug('add component: %r', component)
if not component.version and not requirement.is_url:
self._logger.warning('component has no pinned version: %r', component)
bom.components.add(component)

def __hashes4req(self, req: 'InstallRequirement') -> Generator['HashType', None, None]:
Expand Down

0 comments on commit e9f3e18

Please sign in to comment.