Single entry into log setup.

pull/760/head
jMyles 2019-02-14 12:26:21 -07:00
parent 3204427d4e
commit fd435c1a32
7 changed files with 51 additions and 19 deletions

View File

@ -38,9 +38,6 @@ TEACHER_URI = f'127.0.0.1:11500'
def spin_up_federated_ursulas(quantity: int = FLEET_POPULATION):
# Logger
globalLogPublisher.addObserver(SimpleObserver())
# Ports
starting_port = DEMO_NODE_STARTING_PORT
ports = list(map(str, range(starting_port, starting_port + quantity)))

View File

@ -16,16 +16,24 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
import click
import click
from twisted.logger import Logger
from twisted.logger import globalLogPublisher
from constant_sorrow import constants
from constant_sorrow.constants import TEMPORARY_DOMAIN
from nucypher.characters.lawful import Ursula
from nucypher.cli import moe, ursula, status, alice
from nucypher.cli.config import echo_version, nucypher_click_config
from nucypher.cli.painting import BANNER
from nucypher.cli.painting import BANNER, paint_configuration, paint_known_nodes
from nucypher.cli.processes import UrsulaCommandProtocol
from nucypher.config.characters import UrsulaConfiguration
from nucypher.config.constants import DEFAULT_CONFIG_ROOT
from nucypher.utilities.logging import GlobalConsoleLogger
GlobalConsoleLogger.start_if_not_started()
#
# Common CLI
#
@click.group()
@click.option('--version', help="Echo the CLI version", is_flag=True, callback=echo_version, expose_value=False, is_eager=True)

View File

@ -15,8 +15,6 @@ from nucypher.network.middleware import RestMiddleware
from nucypher.network.nodes import FleetStateTracker
from nucypher.utilities.logging import SimpleObserver
globalLogPublisher.addObserver(SimpleObserver())
class MonitoringTracker(FleetStateTracker):
def record_fleet_state(self, *args, **kwargs):
@ -62,6 +60,7 @@ class Moe(Character):
@click.option('--ws-port', help="The host port to run websocket network services on", type=NETWORK_PORT, default=9000)
@click.option('--dry-run', '-x', help="Execute normally without actually starting the node", is_flag=True)
def moe(teacher_uri, min_stake, network, ws_port, dry_run, http_port):
"""
"Moe" NuCypher node monitor CLI.
"""

View File

@ -47,7 +47,7 @@ from nucypher.config.constants import DEFAULT_CONFIG_ROOT
from nucypher.utilities.logging import (
logToSentry,
getJsonFileObserver,
SimpleObserver)
SimpleObserver, GlobalConsoleLogger)
@click.command()
@ -127,7 +127,7 @@ def ursula(click_config,
click_config.log_to_sentry = False
click_config.log_to_file = True
globalLogPublisher.removeObserver(logToSentry) # Sentry
globalLogPublisher.addObserver(SimpleObserver(log_level_name='debug')) # Print
GlobalConsoleLogger.set_log_level("debug")
elif quiet:
globalLogPublisher.removeObserver(logToSentry)

View File

@ -306,6 +306,8 @@ class NucypherKeyring:
_private_key_serializer = _PrivateKeySerializer()
__DEFAULT_TLS_CURVE = ec.SECP384R1
log = Logger("keys")
class KeyringError(Exception):
pass
@ -461,7 +463,9 @@ class NucypherKeyring:
return self.is_unlocked
key_data = _read_keyfile(keypath=self.__root_keypath, deserializer=self._private_key_serializer)
try:
self.log.info("Unlocking keyring.")
derived_key = derive_key_from_password(password=password.encode(), salt=key_data['master_salt'])
self.log.info("Finished unlocking.")
except CryptoError:
raise
else:
@ -577,6 +581,8 @@ class NucypherKeyring:
# Derive Wrapping Keys
password_salt, encrypting_salt, signing_salt, delegating_salt = (os.urandom(32) for _ in range(4))
cls.log.info("About to derive key from password.")
derived_key_material = derive_key_from_password(salt=password_salt, password=password.encode())
encrypting_wrap_key = _derive_wrapping_key_from_key_material(salt=encrypting_salt, key_material=derived_key_material)
signature_wrap_key = _derive_wrapping_key_from_key_material(salt=signing_salt, key_material=derived_key_material)

View File

@ -29,6 +29,7 @@ from zope.interface import provider
import nucypher
from nucypher.config.constants import USER_LOG_DIR
from twisted.logger import globalLogPublisher
def initialize_sentry(dsn: str):
@ -66,17 +67,39 @@ def getTextFileObserver(name="ursula.log", path=USER_LOG_DIR):
class SimpleObserver:
def __init__(self, log_level_name="info"):
self.log_level = LogLevel.levelWithName(log_level_name)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@provider(ILogObserver)
def __call__(self, event):
if event['log_level'] >= self.log_level:
if event['log_level'] >= GlobalConsoleLogger.log_level:
event['log_format'] = event['log_format']
print(formatEvent(event))
def logToSentry(event):
class GlobalConsoleLogger:
log_level = LogLevel.levelWithName("info")
started = False
@classmethod
def set_log_level(cls, log_level_name):
cls.log_level = LogLevel.levelWithName(log_level_name)
if not cls.started:
cls.start()
@classmethod
def start(cls):
globalLogPublisher.addObserver(SimpleObserver())
cls.started = True
@classmethod
def start_if_not_started(cls):
if not cls.started:
cls.start()
def logToSentry(cls, event):
# Handle Logs...
if not event.get('isError') or 'failure' not in event:

View File

@ -20,7 +20,7 @@ from twisted.logger import globalLogPublisher
from nucypher.cli.config import NucypherClickConfig
#
from nucypher.utilities.logging import SimpleObserver
from nucypher.utilities.logging import SimpleObserver, GlobalConsoleLogger
# Logger Configuration
#
@ -52,5 +52,4 @@ def pytest_collection_modifyitems(config, items):
if "slow" in item.keywords:
item.add_marker(skip_slow)
log_level_name = config.getoption("--log-level", "info", skip=True)
observer = SimpleObserver(log_level_name)
globalLogPublisher.addObserver(observer)
GlobalConsoleLogger.set_log_level(log_level_name)