Skip to content

Commit 459496b

Browse files
authored
Merge pull request #212 from lukpueh/fix-logging
Configure basic top-level logger
2 parents 2f2dfa9 + 7f06845 commit 459496b

17 files changed

+20
-35
lines changed

securesystemslib/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import logging
2+
3+
# Configure a basic 'securesystemslib' top-level logger with a StreamHandler
4+
# (print to console) and the WARNING log level (print messages of type
5+
# warning, error or critical). This is similar to what 'logging.basicConfig'
6+
# would do with the root logger. All 'securesystemslib.*' loggers default to
7+
# this top-level logger and thus may be configured (e.g. formatted, silenced,
8+
# etc.) with it. It can be accessed via logging.getLogger('securesystemslib').
9+
logger = logging.getLogger(__name__)
10+
logger.setLevel(logging.WARNING)
11+
logger.addHandler(logging.StreamHandler())

securesystemslib/ecdsa_keys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666

6767
_SUPPORTED_ECDSA_SCHEMES = ['ecdsa-sha2-nistp256']
6868

69-
logger = logging.getLogger('securesystemslib_ecdsa_keys')
69+
logger = logging.getLogger(__name__)
7070

7171

7272
def generate_public_and_private(scheme='ecdsa-sha2-nistp256'):

securesystemslib/exceptions.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@
2525
from __future__ import division
2626
from __future__ import unicode_literals
2727

28-
import logging
29-
3028
import six
3129

32-
logger = logging.getLogger('securesystemslib.exceptions')
3330

3431

3532
class Error(Exception):

securesystemslib/hash.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,13 @@
3030
from __future__ import division
3131
from __future__ import unicode_literals
3232

33-
import logging
3433
import hashlib
3534

3635
import six
3736

3837
import securesystemslib.exceptions
3938
import securesystemslib.formats
4039

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

4441
DEFAULT_CHUNK_SIZE = 4096
4542
DEFAULT_HASH_ALGORITHM = 'sha256'

securesystemslib/interface.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@
4848

4949
import six
5050

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

5453
try:
5554
from colorama import Fore
@@ -73,7 +72,7 @@
7372

7473
def _prompt(message, result_type=str):
7574
"""
76-
Non-public function that prompts the user for input by logging 'message',
75+
Non-public function that prompts the user for input by printing 'message',
7776
converting the input to 'result_type', and returning the value to the
7877
caller.
7978
"""

securesystemslib/keys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
'rsa-pkcs1v15-sha512',
103103
]
104104

105-
logger = logging.getLogger('securesystemslib_keys')
105+
logger = logging.getLogger(__name__)
106106

107107

108108
def generate_rsa_key(bits=_DEFAULT_RSA_KEY_BITS, scheme='rsassa-pss-sha256'):

securesystemslib/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
import six
4141

42-
logger = logging.getLogger('securesystemslib_util')
42+
logger = logging.getLogger(__name__)
4343

4444

4545
def get_file_details(filepath, hash_algorithms=['sha256']):

tests/check_public_interfaces.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
import inspect
3636
import json
37-
import logging
3837
import os
3938
import shutil
4039
import sys
@@ -50,9 +49,6 @@
5049
import securesystemslib.keys
5150

5251

53-
logger = logging.getLogger('securesystemslib_check_public_interfaces')
54-
55-
5652

5753
class TestPublicInterfaces(unittest.TestCase):
5854

tests/test_ecdsa_keys.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,12 @@
2727

2828
import unittest
2929
import os
30-
import logging
3130

3231
import securesystemslib.exceptions
3332
import securesystemslib.formats
3433
import securesystemslib.ecdsa_keys
3534
import securesystemslib.rsa_keys
3635

37-
logger = logging.getLogger('securesystemslib_test_ecdsa_keys')
3836

3937
public, private = securesystemslib.ecdsa_keys.generate_public_and_private()
4038
FORMAT_ERROR_MSG = 'securesystemslib.exceptions.FormatError raised. Check object\'s format.'

tests/test_ed25519_keys.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@
2727

2828
import unittest
2929
import os
30-
import logging
3130

3231
import securesystemslib.exceptions
3332
import securesystemslib.formats
3433
import securesystemslib.ed25519_keys
3534

36-
logger = logging.getLogger('securesystemslib.test_ed25519_keys')
3735

3836
public, private = securesystemslib.ed25519_keys.generate_public_and_private()
3937
FORMAT_ERROR_MSG = 'securesystemslib.exceptions.FormatError raised. Check object\'s format.'

tests/test_exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
import securesystemslib.exceptions
3232

33-
logger = logging.getLogger('test_exceptions')
33+
logger = logging.getLogger(__name__)
3434

3535
class TestExceptions(unittest.TestCase):
3636
def setUp(self):

tests/test_hash.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636

3737
import six
3838

39-
logger = logging.getLogger('securesystemslib.test_hash')
39+
logger = logging.getLogger(__name__)
4040

4141

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

4545

4646
class TestHash(unittest.TestCase):

tests/test_interface.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import os
2929
import time
3030
import datetime
31-
import logging
3231
import tempfile
3332
import json
3433
import shutil
@@ -49,8 +48,6 @@
4948

5049
import six
5150

52-
logger = logging.getLogger('securesystemslib_test_interface')
53-
5451

5552

5653
class TestInterfaceFunctions(unittest.TestCase):

tests/test_keys.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,12 @@
2626
from __future__ import unicode_literals
2727

2828
import unittest
29-
import logging
30-
3129

3230
import securesystemslib.exceptions
3331
import securesystemslib.formats
3432
import securesystemslib.keys
3533
import securesystemslib.ecdsa_keys
3634

37-
logger = logging.getLogger('securesystemslib_test_keys')
38-
3935
KEYS = securesystemslib.keys
4036
FORMAT_ERROR_MSG = 'securesystemslib.exceptions.FormatError was raised!' + \
4137
' Check object\'s format.'

tests/test_rsa_keys.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@
2626
from __future__ import unicode_literals
2727

2828
import unittest
29-
import logging
3029

3130
import securesystemslib.exceptions
3231
import securesystemslib.formats
3332
import securesystemslib.keys
3433
import securesystemslib.rsa_keys
3534

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

3937
public_rsa, private_rsa = securesystemslib.rsa_keys.generate_rsa_public_and_private()
4038
FORMAT_ERROR_MSG = 'securesystemslib.exceptions.FormatError raised. Check object\'s format.'

tests/test_schema.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@
2727

2828
import unittest
2929
import re
30-
import logging
3130

3231
import securesystemslib.exceptions
3332
import securesystemslib.schema as SCHEMA
3433

35-
logger = logging.getLogger('securesystemslib.test_schema')
3634

3735

3836
class TestSchema(unittest.TestCase):

tests/test_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
import six
4343

44-
logger = logging.getLogger('securesystemslib_test_util')
44+
logger = logging.getLogger(__name__)
4545

4646

4747
class TestUtil(unittest_toolbox.Modified_TestCase):

0 commit comments

Comments
 (0)