From 4e638b8e920e976c731115d6368fa05a9f105a69 Mon Sep 17 00:00:00 2001 From: "C. Allwardt" <3979063+craig8@users.noreply.github.com> Date: Fri, 25 Oct 2024 16:19:36 -0700 Subject: [PATCH 1/2] Fixed #229 adding logic to detect the output to file. --- src/volttron/server/__main__.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/volttron/server/__main__.py b/src/volttron/server/__main__.py index 7d25d3255..e4e67b512 100644 --- a/src/volttron/server/__main__.py +++ b/src/volttron/server/__main__.py @@ -40,6 +40,7 @@ should happen is setting up of logging and verbosity for the server. After that we hand off to the run_server method, which will start the server process. """ +import logging import logging.config import os from pathlib import Path @@ -47,18 +48,23 @@ import yaml -from volttron.server.logs import get_default_logging_config +from volttron.server.logs import get_default_logging_config, log_to_file +file_to_log_to: str | None = None total_count: int = 0 logging_config: Path | str | None = None -for arg in sys.argv: +arg_iter = iter(sys.argv) +for arg in arg_iter: vcount = 0 if arg.startswith("-v"): vcount = arg.count("v") elif arg == "--verbose": vcount = 1 + elif arg == "--log" or arg == "-l": + file_to_log_to = next(arg_iter) + elif arg == "--log-config" or arg == "-L": # Find the index of the log configuration so we can replace the # file with absolute path. @@ -78,20 +84,21 @@ total_count += vcount -logging.config.dictConfig(get_default_logging_config(level=total_count)) - +# If the user has specified a logging configuration then allow them full access to all the +# responsibility of logging. if logging_config: with open(logging_config, 'rt') as f: cfg = yaml.safe_load(f.read()) logging.config.dictConfig(cfg) -# from volttron.utils.logs import enable_trace, setup_logging - -# setup_logging(total_count) +# The user wants to output all to a file so we can do that for them. +if file_to_log_to: + log_to_file(file_to_log_to, total_count, handler_class=logging.handlers.WatchedFileHandler) -# if total_count <= logging.DEBUG: -# enable_trace() +# Normal here just use the default stream handler setup. +else: + logging.config.dictConfig(get_default_logging_config(level=total_count)) from volttron.server.run_server import _main From a026bdf83617deb2bb564b6c0eb69babd92d270e Mon Sep 17 00:00:00 2001 From: "C. Allwardt" <3979063+craig8@users.noreply.github.com> Date: Fri, 25 Oct 2024 16:22:14 -0700 Subject: [PATCH 2/2] Removed file writing as default in logging config. Bump version --- pyproject.toml | 2 +- src/volttron/server/logs.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fde934f64..356c67551 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "volttron-core" -version = "2.0.0rc3" +version = "2.0.0rc4" description = "VOLTTRON™ is an open source platform for distributed sensing and control. The platform provides services for collecting and storing data from buildings and devices and provides an environment for developing applications which interact with that data." authors = ["volttron "] license = "Apache-2.0" diff --git a/src/volttron/server/logs.py b/src/volttron/server/logs.py index 7952b2930..f33bfb405 100644 --- a/src/volttron/server/logs.py +++ b/src/volttron/server/logs.py @@ -132,14 +132,15 @@ def get_default_logging_config(level: int = logging.WARNING) -> dict: "level": level, "formatter": "simple", "stream": "ext://sys.stdout" - }, - "file": { - "class": "logging.FileHandler", - "level": "INFO", - "formatter": "simple", - "filename": "myapp.log", - "mode": "a" } + # , + # "file": { + # "class": "logging.FileHandler", + # "level": "INFO", + # "formatter": "simple", + # "filename": "myapp.log", + # "mode": "a" + # } }, "loggers": get_default_loggers_config(level), "root": {