Skip to content

Commit

Permalink
#26 - cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsasha committed Dec 11, 2018
1 parent 0d923a6 commit fd5e592
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
21 changes: 18 additions & 3 deletions docs/usage/configuration.rst
Expand Up @@ -15,7 +15,7 @@ Example configuration file
.. highlight:: yaml
:linenothreshold: 5

This sample shows the hierarchy of all configuration options::
This sample shows most configuration options::

irrd:
database_url: 'postgresql://localhost:5432/irrd'
Expand Down Expand Up @@ -44,6 +44,10 @@ This sample shows the hierarchy of all configuration options::
from: example@example.com
smtp: localhost

log:
logfile_path: /var/log/irrd/irrd.log
loglevel: DEBUG

sources_default:
- AUTHDATABASE
- MIRROR-SECOND
Expand Down Expand Up @@ -93,7 +97,8 @@ This sample shows the hierarchy of all configuration options::
Loading and reloading
---------------------

The configuration is loaded when IRRd starts. If the configuration is invalid, the daemon will refuse to start.
The configuration is loaded when IRRd starts. The path to the config file is read from the ``IRRD_CONFIG_PATH``
environment variable. If the configuration is invalid, the daemon will refuse to start.
While running, the configuration can be reloaded by sending a `SIGHUP` signal. Most settings will take effect
immediately, but some require a full restart. If a `SIGHUP` is sent and the new configuration is invalid,
errors will be written to the logfile, but IRRd will keep running with the last valid configuration.
Expand Down Expand Up @@ -238,10 +243,20 @@ Sources
other details. Every ``import_timer``, the entire database will be reloaded from the full copies.
Journals can not be generated.

.. note::

Source names are case sensitive and must be an exact match to ``sources_default``, and the source
attribute value in any objects imported from files or NRTM. E.g. if ``sources.EXAMPLE`` is defined,
and ``sources_default`` contains ``example``, this is a configuration error. If an object is
encountered with ``source: EXAMPLe``, it is rejected and an error is logged.


Logging
~~~~~~~
* ``log.destination``: the full path where the logfile will be written.
* ``log.logfile_path``: the full path where the logfile will be written. IRRd will attempt to create the file if it
does not exist. If the file is removed, e.g. by a log rotation process, IRRd will create a new file in the same
location, and continue writing to that file. Timestamps in logs are always in UTC, regardless of local machine
timezone.
|br| **Default**: not defined, logs will be sent to the console
|br| **Change takes effect**: after full IRRd restart.
* ``log.level``: the loglevel, one of `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL`. The recommended level is `INFO`.
Expand Down
15 changes: 6 additions & 9 deletions irrd/conf/__init__.py
Expand Up @@ -25,20 +25,15 @@
'verbose': {
'format': '%(asctime)s irrd[%(process)d]: [%(name)s#%(levelname)s] %(message)s'
},
'simple': {
'format': '%(levelname)s %(name)s: %(message)s'
},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'verbose'
},
'file': {
'class': 'logging.NullHandler',
}
},
'loggers': {
# Tune down some very loud and not very useful loggers from libraries.
'passlib.registry': {
'level': 'INFO',
'propagate': True,
Expand All @@ -53,7 +48,7 @@
},
'': {
'handlers': ['console'],
'level': 'DEBUG',
'level': 'INFO',
'propagate': True,
},
}
Expand All @@ -68,7 +63,7 @@ class ConfigurationError(ValueError):
pass


# Testing overrides can be set to a DottedDict, and is used
# testing_overrides can be set to a DottedDict, and is used
# to override settings while testing, using the config_override
# fixture.
testing_overrides = None
Expand All @@ -85,6 +80,7 @@ class Configuration:
def __init__(self):
"""
Load the default config and load and check the user provided config.
If a logfile was specified, direct logs there.
"""
default_config_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'default_config.yaml')
default_config_yaml = yaml.safe_load(open(default_config_path))
Expand All @@ -95,13 +91,14 @@ def __init__(self):
raise ConfigurationError(f'Errors found in configuration, unable to start: {errors}')
self._commit_staging()

log_filename = self.get_setting_live('log.destination')
log_filename = self.get_setting_live('log.logfile_path')
if log_filename:
LOGGING['handlers']['file'] = {
'class': 'logging.handlers.WatchedFileHandler',
'filename': log_filename,
'formatter': 'verbose',
}
# noinspection PyTypeChecker
LOGGING['loggers']['']['handlers'] = ['file']
logging.config.dictConfig(LOGGING)

Expand Down

0 comments on commit fd5e592

Please sign in to comment.