Skip to content

Configure basic top-level logger #212

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

Merged
merged 5 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions securesystemslib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import logging

# Configure a basic 'securesystemslib' top-level logger with a StreamHandler
# (print to console) and the WARNING log level (print messages of type
# warning, error or critical). This is similar to what 'logging.basicConfig'
# would do with the root logger. All 'securesystemslib.*' loggers default to
# this top-level logger and thus may be configured (e.g. formatted, silenced,
# etc.) with it. It can be accessed via logging.getLogger('securesystemslib').
logger = logging.getLogger(__name__)
logger.setLevel(logging.WARNING)
logger.addHandler(logging.StreamHandler())
2 changes: 1 addition & 1 deletion securesystemslib/ecdsa_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

_SUPPORTED_ECDSA_SCHEMES = ['ecdsa-sha2-nistp256']

logger = logging.getLogger('securesystemslib_ecdsa_keys')
logger = logging.getLogger(__name__)


def generate_public_and_private(scheme='ecdsa-sha2-nistp256'):
Expand Down
3 changes: 0 additions & 3 deletions securesystemslib/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@
from __future__ import division
from __future__ import unicode_literals

import logging

import six

logger = logging.getLogger('securesystemslib.exceptions')


class Error(Exception):
Expand Down
3 changes: 0 additions & 3 deletions securesystemslib/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@
from __future__ import division
from __future__ import unicode_literals

import logging
import hashlib

import six

import securesystemslib.exceptions
import securesystemslib.formats

# Import securesystemslib logger to log warning messages.
logger = logging.getLogger('securesystemslib.hash')

DEFAULT_CHUNK_SIZE = 4096
DEFAULT_HASH_ALGORITHM = 'sha256'
Expand Down
5 changes: 2 additions & 3 deletions securesystemslib/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@

import six

# See 'log.py' to learn how logging is handled in securesystemslib.
logger = logging.getLogger('securesystemslib_interface')
logger = logging.getLogger(__name__)

try:
from colorama import Fore
Expand All @@ -73,7 +72,7 @@

def _prompt(message, result_type=str):
"""
Non-public function that prompts the user for input by logging 'message',
Non-public function that prompts the user for input by printing 'message',
converting the input to 'result_type', and returning the value to the
caller.
"""
Expand Down
2 changes: 1 addition & 1 deletion securesystemslib/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
'rsa-pkcs1v15-sha512',
]

logger = logging.getLogger('securesystemslib_keys')
logger = logging.getLogger(__name__)


def generate_rsa_key(bits=_DEFAULT_RSA_KEY_BITS, scheme='rsassa-pss-sha256'):
Expand Down
2 changes: 1 addition & 1 deletion securesystemslib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

import six

logger = logging.getLogger('securesystemslib_util')
logger = logging.getLogger(__name__)


def get_file_details(filepath, hash_algorithms=['sha256']):
Expand Down
4 changes: 0 additions & 4 deletions tests/check_public_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import inspect
import json
import logging
import os
import shutil
import sys
Expand All @@ -50,9 +49,6 @@
import securesystemslib.keys


logger = logging.getLogger('securesystemslib_check_public_interfaces')



class TestPublicInterfaces(unittest.TestCase):

Expand Down
2 changes: 0 additions & 2 deletions tests/test_ecdsa_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@

import unittest
import os
import logging

import securesystemslib.exceptions
import securesystemslib.formats
import securesystemslib.ecdsa_keys
import securesystemslib.rsa_keys

logger = logging.getLogger('securesystemslib_test_ecdsa_keys')

public, private = securesystemslib.ecdsa_keys.generate_public_and_private()
FORMAT_ERROR_MSG = 'securesystemslib.exceptions.FormatError raised. Check object\'s format.'
Expand Down
2 changes: 0 additions & 2 deletions tests/test_ed25519_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@

import unittest
import os
import logging

import securesystemslib.exceptions
import securesystemslib.formats
import securesystemslib.ed25519_keys

logger = logging.getLogger('securesystemslib.test_ed25519_keys')

public, private = securesystemslib.ed25519_keys.generate_public_and_private()
FORMAT_ERROR_MSG = 'securesystemslib.exceptions.FormatError raised. Check object\'s format.'
Expand Down
2 changes: 1 addition & 1 deletion tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

import securesystemslib.exceptions

logger = logging.getLogger('test_exceptions')
logger = logging.getLogger(__name__)

class TestExceptions(unittest.TestCase):
def setUp(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@

import six

logger = logging.getLogger('securesystemslib.test_hash')
logger = logging.getLogger(__name__)


if not 'hashlib' in securesystemslib.hash.SUPPORTED_LIBRARIES:
logger.warn('Not testing hashlib: could not be imported.')
logger.warning('Not testing hashlib: could not be imported.')


class TestHash(unittest.TestCase):
Expand Down
3 changes: 0 additions & 3 deletions tests/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import os
import time
import datetime
import logging
import tempfile
import json
import shutil
Expand All @@ -49,8 +48,6 @@

import six

logger = logging.getLogger('securesystemslib_test_interface')



class TestInterfaceFunctions(unittest.TestCase):
Expand Down
4 changes: 0 additions & 4 deletions tests/test_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,12 @@
from __future__ import unicode_literals

import unittest
import logging


import securesystemslib.exceptions
import securesystemslib.formats
import securesystemslib.keys
import securesystemslib.ecdsa_keys

logger = logging.getLogger('securesystemslib_test_keys')

KEYS = securesystemslib.keys
FORMAT_ERROR_MSG = 'securesystemslib.exceptions.FormatError was raised!' + \
' Check object\'s format.'
Expand Down
2 changes: 0 additions & 2 deletions tests/test_rsa_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@
from __future__ import unicode_literals

import unittest
import logging

import securesystemslib.exceptions
import securesystemslib.formats
import securesystemslib.keys
import securesystemslib.rsa_keys

from cryptography.hazmat.primitives import hashes
logger = logging.getLogger('securesystemslib.test_rsa_keys')

public_rsa, private_rsa = securesystemslib.rsa_keys.generate_rsa_public_and_private()
FORMAT_ERROR_MSG = 'securesystemslib.exceptions.FormatError raised. Check object\'s format.'
Expand Down
2 changes: 0 additions & 2 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@

import unittest
import re
import logging

import securesystemslib.exceptions
import securesystemslib.schema as SCHEMA

logger = logging.getLogger('securesystemslib.test_schema')


class TestSchema(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

import six

logger = logging.getLogger('securesystemslib_test_util')
logger = logging.getLogger(__name__)


class TestUtil(unittest_toolbox.Modified_TestCase):
Expand Down