-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: configure logger for module and control from actions files (#63)
* feat: configure logger for module and control from actions files Adds configuration of trestlebot logger along with compliance-trestle logger Allows verbosity to be set from the actions files Signed-off-by: Jennifer Power <[email protected]> * chore: adds formatting fixes Signed-off-by: Jennifer Power <[email protected]> * chore: update logging debug statement bot.py --------- Signed-off-by: Jennifer Power <[email protected]>
- Loading branch information
Showing
9 changed files
with
85 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/python | ||
|
||
# Copyright 2023 Red Hat, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
"""Configure logger for trestlebot and trestle.""" | ||
|
||
import argparse | ||
import logging | ||
import sys | ||
|
||
import trestle.common.log as log | ||
|
||
|
||
_logger = logging.getLogger("trestlebot") | ||
|
||
|
||
def set_log_level_from_args(args: argparse.Namespace) -> None: | ||
"""Set the log level from the args for trestle and trestlebot.""" | ||
|
||
# Setup the trestle logger | ||
log.set_log_level_from_args(args=args) | ||
|
||
if args.verbose == 1: | ||
configure_logger(logging.DEBUG) | ||
else: | ||
configure_logger(logging.INFO) | ||
|
||
|
||
def configure_logger(level: int = logging.INFO) -> None: | ||
"""Configure the logger.""" | ||
_logger.setLevel(level=level) | ||
|
||
# Create a StreamHandler to send non-error logs to stdout | ||
stdout_handler = logging.StreamHandler(sys.stdout) | ||
stdout_handler.setLevel(logging.DEBUG) | ||
|
||
# Create a StreamHandler to send error logs to stderr | ||
stderr_handler = logging.StreamHandler(sys.stderr) | ||
stderr_handler.setLevel(logging.ERROR) | ||
|
||
# Create a formatter and set it on both handlers | ||
log_formatter = logging.Formatter("%(name)s:%(lineno)d %(levelname)s: %(message)s") | ||
stdout_handler.setFormatter(log_formatter) | ||
stderr_handler.setFormatter(log_formatter) | ||
|
||
_logger.addHandler(stdout_handler) | ||
_logger.addHandler(stderr_handler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters