diff --git a/README.md b/README.md index 13725c8..b08c903 100644 --- a/README.md +++ b/README.md @@ -458,14 +458,15 @@ The idea behind this is three-fold: ### Using Environment Variables to configure logging handlers -NOTE: This is WIP, so things may break / be broken. To truly be able to use this feature, Wryte will have to support logger-name-based env vars (e.g. `WRYTE_HANDLERS_logger_name_*`). - -NOTE: DO NOT use this feature if you have multiple loggers in the same service unless you explicitly intend to have all loggers log to all handlers configured. +NOTE: This is WIP, so things may break / be broken. One of Wryte's goals is to provide a simple way to configure loggers. Much like Grafana and Fabio, Wryte aims to be completely env-var configurable. On top of having two default `console` and `json` handlers which indicate the formatting and both log to stdout, you can utilize built-in and 3rd party handlers quite easily. +Below are the global env vars used to configure all loggers instantiated by Wryte. +If you want to apply a handler to a specific logger, use the `WRYTE_$LOGGER_NAME_HANDLERS_*` pattern instead (e.g. `WRYTE_WEBLOGGER_HANDLERS_FILE_ENABLED` - all uppercase). + #### File Handler Wryte supports both the rotating and watching file handlers (on Windows, FileHandler replaces WatchingFileHandler if not rotating). diff --git a/wryte.py b/wryte.py index b74a374..4007246 100644 --- a/wryte.py +++ b/wryte.py @@ -138,14 +138,14 @@ def __init__(self, If `hostname` isn't provided, it will be retrieved via socket. """ - logger_name = name or __name__ + self.logger_name = name or __name__ self.pretty = pretty self.color = color self.simple = simple - self._log = self._get_base(logger_name, hostname) - self.logger = self._logger(logger_name) + self._log = self._get_base(self.logger_name, hostname) + self.logger = self._logger(self.logger_name) if not bare: self._configure_handlers(level, jsonify) @@ -250,12 +250,11 @@ def _enrich(self, message, level, objects, kwargs=None): return log - @staticmethod - def _env(variable, logger=None, default=None): - if logger: - return os.getenv('WRYTE_{0}_{1}'.format(logger, variable), default) - else: - return os.getenv('WRYTE_{0}'.format(variable), default) + def _env(self, variable, default=None): + logger_env = os.getenv('WRYTE_{0}_{1}'.format( + self.logger_name.upper(), variable), default) + global_env = os.getenv('WRYTE_{0}'.format(variable), default) + return logger_env or global_env or None def _configure_handlers(self, level, jsonify=False): if not jsonify: