mirror of https://github.com/nucypher/nucypher.git
Single entry into log setup.
parent
3204427d4e
commit
fd435c1a32
|
@ -38,9 +38,6 @@ TEACHER_URI = f'127.0.0.1:11500'
|
||||||
|
|
||||||
def spin_up_federated_ursulas(quantity: int = FLEET_POPULATION):
|
def spin_up_federated_ursulas(quantity: int = FLEET_POPULATION):
|
||||||
|
|
||||||
# Logger
|
|
||||||
globalLogPublisher.addObserver(SimpleObserver())
|
|
||||||
|
|
||||||
# Ports
|
# Ports
|
||||||
starting_port = DEMO_NODE_STARTING_PORT
|
starting_port = DEMO_NODE_STARTING_PORT
|
||||||
ports = list(map(str, range(starting_port, starting_port + quantity)))
|
ports = list(map(str, range(starting_port, starting_port + quantity)))
|
||||||
|
|
|
@ -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 import moe, ursula, status, alice
|
||||||
from nucypher.cli.config import echo_version, nucypher_click_config
|
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.group()
|
||||||
@click.option('--version', help="Echo the CLI version", is_flag=True, callback=echo_version, expose_value=False, is_eager=True)
|
@click.option('--version', help="Echo the CLI version", is_flag=True, callback=echo_version, expose_value=False, is_eager=True)
|
||||||
|
|
|
@ -15,8 +15,6 @@ from nucypher.network.middleware import RestMiddleware
|
||||||
from nucypher.network.nodes import FleetStateTracker
|
from nucypher.network.nodes import FleetStateTracker
|
||||||
from nucypher.utilities.logging import SimpleObserver
|
from nucypher.utilities.logging import SimpleObserver
|
||||||
|
|
||||||
globalLogPublisher.addObserver(SimpleObserver())
|
|
||||||
|
|
||||||
|
|
||||||
class MonitoringTracker(FleetStateTracker):
|
class MonitoringTracker(FleetStateTracker):
|
||||||
def record_fleet_state(self, *args, **kwargs):
|
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('--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)
|
@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):
|
def moe(teacher_uri, min_stake, network, ws_port, dry_run, http_port):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
"Moe" NuCypher node monitor CLI.
|
"Moe" NuCypher node monitor CLI.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -47,7 +47,7 @@ from nucypher.config.constants import DEFAULT_CONFIG_ROOT
|
||||||
from nucypher.utilities.logging import (
|
from nucypher.utilities.logging import (
|
||||||
logToSentry,
|
logToSentry,
|
||||||
getJsonFileObserver,
|
getJsonFileObserver,
|
||||||
SimpleObserver)
|
SimpleObserver, GlobalConsoleLogger)
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
|
@ -127,7 +127,7 @@ def ursula(click_config,
|
||||||
click_config.log_to_sentry = False
|
click_config.log_to_sentry = False
|
||||||
click_config.log_to_file = True
|
click_config.log_to_file = True
|
||||||
globalLogPublisher.removeObserver(logToSentry) # Sentry
|
globalLogPublisher.removeObserver(logToSentry) # Sentry
|
||||||
globalLogPublisher.addObserver(SimpleObserver(log_level_name='debug')) # Print
|
GlobalConsoleLogger.set_log_level("debug")
|
||||||
|
|
||||||
elif quiet:
|
elif quiet:
|
||||||
globalLogPublisher.removeObserver(logToSentry)
|
globalLogPublisher.removeObserver(logToSentry)
|
||||||
|
|
|
@ -306,6 +306,8 @@ class NucypherKeyring:
|
||||||
_private_key_serializer = _PrivateKeySerializer()
|
_private_key_serializer = _PrivateKeySerializer()
|
||||||
__DEFAULT_TLS_CURVE = ec.SECP384R1
|
__DEFAULT_TLS_CURVE = ec.SECP384R1
|
||||||
|
|
||||||
|
log = Logger("keys")
|
||||||
|
|
||||||
class KeyringError(Exception):
|
class KeyringError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -461,7 +463,9 @@ class NucypherKeyring:
|
||||||
return self.is_unlocked
|
return self.is_unlocked
|
||||||
key_data = _read_keyfile(keypath=self.__root_keypath, deserializer=self._private_key_serializer)
|
key_data = _read_keyfile(keypath=self.__root_keypath, deserializer=self._private_key_serializer)
|
||||||
try:
|
try:
|
||||||
|
self.log.info("Unlocking keyring.")
|
||||||
derived_key = derive_key_from_password(password=password.encode(), salt=key_data['master_salt'])
|
derived_key = derive_key_from_password(password=password.encode(), salt=key_data['master_salt'])
|
||||||
|
self.log.info("Finished unlocking.")
|
||||||
except CryptoError:
|
except CryptoError:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
|
@ -577,6 +581,8 @@ class NucypherKeyring:
|
||||||
|
|
||||||
# Derive Wrapping Keys
|
# Derive Wrapping Keys
|
||||||
password_salt, encrypting_salt, signing_salt, delegating_salt = (os.urandom(32) for _ in range(4))
|
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())
|
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)
|
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)
|
signature_wrap_key = _derive_wrapping_key_from_key_material(salt=signing_salt, key_material=derived_key_material)
|
||||||
|
|
|
@ -29,6 +29,7 @@ from zope.interface import provider
|
||||||
|
|
||||||
import nucypher
|
import nucypher
|
||||||
from nucypher.config.constants import USER_LOG_DIR
|
from nucypher.config.constants import USER_LOG_DIR
|
||||||
|
from twisted.logger import globalLogPublisher
|
||||||
|
|
||||||
|
|
||||||
def initialize_sentry(dsn: str):
|
def initialize_sentry(dsn: str):
|
||||||
|
@ -66,17 +67,39 @@ def getTextFileObserver(name="ursula.log", path=USER_LOG_DIR):
|
||||||
|
|
||||||
class SimpleObserver:
|
class SimpleObserver:
|
||||||
|
|
||||||
def __init__(self, log_level_name="info"):
|
def __init__(self, *args, **kwargs):
|
||||||
self.log_level = LogLevel.levelWithName(log_level_name)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
@provider(ILogObserver)
|
@provider(ILogObserver)
|
||||||
def __call__(self, event):
|
def __call__(self, event):
|
||||||
if event['log_level'] >= self.log_level:
|
if event['log_level'] >= GlobalConsoleLogger.log_level:
|
||||||
event['log_format'] = event['log_format']
|
event['log_format'] = event['log_format']
|
||||||
print(formatEvent(event))
|
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...
|
# Handle Logs...
|
||||||
if not event.get('isError') or 'failure' not in event:
|
if not event.get('isError') or 'failure' not in event:
|
||||||
|
|
|
@ -20,7 +20,7 @@ from twisted.logger import globalLogPublisher
|
||||||
|
|
||||||
from nucypher.cli.config import NucypherClickConfig
|
from nucypher.cli.config import NucypherClickConfig
|
||||||
#
|
#
|
||||||
from nucypher.utilities.logging import SimpleObserver
|
from nucypher.utilities.logging import SimpleObserver, GlobalConsoleLogger
|
||||||
|
|
||||||
# Logger Configuration
|
# Logger Configuration
|
||||||
#
|
#
|
||||||
|
@ -52,5 +52,4 @@ def pytest_collection_modifyitems(config, items):
|
||||||
if "slow" in item.keywords:
|
if "slow" in item.keywords:
|
||||||
item.add_marker(skip_slow)
|
item.add_marker(skip_slow)
|
||||||
log_level_name = config.getoption("--log-level", "info", skip=True)
|
log_level_name = config.getoption("--log-level", "info", skip=True)
|
||||||
observer = SimpleObserver(log_level_name)
|
GlobalConsoleLogger.set_log_level(log_level_name)
|
||||||
globalLogPublisher.addObserver(observer)
|
|
||||||
|
|
Loading…
Reference in New Issue