Add option to log to stderr

This commit is contained in:
hroff-1902 2019-10-28 12:30:09 +03:00
parent 17fce00a5e
commit 255206720f
4 changed files with 13 additions and 3 deletions

View File

@ -9,7 +9,8 @@ from typing import Any, Dict, List, Optional
from freqtrade import constants from freqtrade import constants
from freqtrade.configuration.cli_options import AVAILABLE_CLI_OPTIONS from freqtrade.configuration.cli_options import AVAILABLE_CLI_OPTIONS
ARGS_COMMON = ["verbosity", "logfile", "version", "config", "datadir", "user_data_dir"] ARGS_COMMON = ["verbosity", "log_to_stderr", "logfile", "version", "config", "datadir",
"user_data_dir"]
ARGS_STRATEGY = ["strategy", "strategy_path"] ARGS_STRATEGY = ["strategy", "strategy_path"]

View File

@ -34,6 +34,12 @@ AVAILABLE_CLI_OPTIONS = {
action='count', action='count',
default=0, default=0,
), ),
"log_to_stderr": Arg(
'-E', '--stderr',
help='Force log messages to be printed to stderr instead of stdout.',
action='store_true',
default=False,
),
"logfile": Arg( "logfile": Arg(
'--logfile', '--logfile',
help='Log to the file specified.', help='Log to the file specified.',

View File

@ -125,6 +125,8 @@ class Configuration:
# Log level # Log level
config.update({'verbosity': self.args.get("verbosity", 0)}) config.update({'verbosity': self.args.get("verbosity", 0)})
config.update({'log_to_stderr': self.args.get("log_to_stderr", False)})
if 'logfile' in self.args and self.args["logfile"]: if 'logfile' in self.args and self.args["logfile"]:
config.update({'logfile': self.args["logfile"]}) config.update({'logfile': self.args["logfile"]})

View File

@ -33,8 +33,9 @@ def setup_logging(config: Dict[str, Any]) -> None:
# Log level # Log level
verbosity = config['verbosity'] verbosity = config['verbosity']
# Log to stdout, not stderr # By default, log to stdout, not stderr
log_handlers: List[logging.Handler] = [logging.StreamHandler(sys.stdout)] stream = sys.stderr if config['log_to_stderr'] else sys.stdout
log_handlers: List[logging.Handler] = [logging.StreamHandler(stream)]
if config.get('logfile'): if config.get('logfile'):
log_handlers.append(RotatingFileHandler(config['logfile'], log_handlers.append(RotatingFileHandler(config['logfile'],