Skip to content

Commit

Permalink
Fixed eclipse-volttron#229 adding logic to detect the output to file.
Browse files Browse the repository at this point in the history
  • Loading branch information
craig8 committed Oct 25, 2024
1 parent 57eddfa commit 4e638b8
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/volttron/server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,31 @@
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
import sys

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.
Expand All @@ -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

Expand Down

0 comments on commit 4e638b8

Please sign in to comment.