mirror of
https://github.com/esphome/esphome.git
synced 2025-01-15 20:21:36 +01:00
Add log level env var (#7604)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
parent
d69926485c
commit
40bee2a854
@ -758,6 +758,14 @@ def parse_args(argv):
|
||||
options_parser.add_argument(
|
||||
"-q", "--quiet", help="Disable all ESPHome logs.", action="store_true"
|
||||
)
|
||||
options_parser.add_argument(
|
||||
"-l",
|
||||
"--log-level",
|
||||
help="Set the log level.",
|
||||
default=os.getenv("ESPHOME_LOG_LEVEL", "INFO"),
|
||||
action="store",
|
||||
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
|
||||
)
|
||||
options_parser.add_argument(
|
||||
"--dashboard", help=argparse.SUPPRESS, action="store_true"
|
||||
)
|
||||
@ -987,11 +995,16 @@ def run_esphome(argv):
|
||||
args = parse_args(argv)
|
||||
CORE.dashboard = args.dashboard
|
||||
|
||||
# Override log level if verbose is set
|
||||
if args.verbose:
|
||||
args.log_level = "DEBUG"
|
||||
elif args.quiet:
|
||||
args.log_level = "CRITICAL"
|
||||
|
||||
setup_log(
|
||||
args.verbose,
|
||||
args.quiet,
|
||||
log_level=args.log_level,
|
||||
# Show timestamp for dashboard access logs
|
||||
args.command == "dashboard",
|
||||
include_timestamp=args.command == "dashboard",
|
||||
)
|
||||
|
||||
if args.command in PRE_CONFIG_ACTIONS:
|
||||
|
@ -67,20 +67,18 @@ class ESPHomeLogFormatter(logging.Formatter):
|
||||
|
||||
|
||||
def setup_log(
|
||||
debug: bool = False, quiet: bool = False, include_timestamp: bool = False
|
||||
log_level=logging.INFO,
|
||||
include_timestamp: bool = False,
|
||||
) -> None:
|
||||
import colorama
|
||||
|
||||
colorama.init()
|
||||
|
||||
if debug:
|
||||
log_level = logging.DEBUG
|
||||
if log_level == logging.DEBUG:
|
||||
CORE.verbose = True
|
||||
elif quiet:
|
||||
log_level = logging.CRITICAL
|
||||
elif log_level == logging.CRITICAL:
|
||||
CORE.quiet = True
|
||||
else:
|
||||
log_level = logging.INFO
|
||||
|
||||
logging.basicConfig(level=log_level)
|
||||
|
||||
logging.getLogger("urllib3").setLevel(logging.WARNING)
|
||||
|
Loading…
Reference in New Issue
Block a user