Skip to content

Commit

Permalink
Merge pull request #235 from craig8/bug/229-logging-issue
Browse files Browse the repository at this point in the history
Bug/229 logging issue
  • Loading branch information
craig8 authored Oct 29, 2024
2 parents 57eddfa + a026bdf commit fe29716
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "Apache-2.0"
Expand Down
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
15 changes: 8 additions & 7 deletions src/volttron/server/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit fe29716

Please sign in to comment.