Skip to content

Commit

Permalink
set_loggers to change yasmin logs
Browse files Browse the repository at this point in the history
  • Loading branch information
mgonzs13 committed Oct 28, 2024
1 parent 196d006 commit 206e69e
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 24 deletions.
16 changes: 12 additions & 4 deletions yasmin/yasmin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
from .state import State
from .cb_state import CbState
from .blackboard import Blackboard
from .state_machine import StateMachine
from yasmin.state import State
from yasmin.cb_state import CbState
from yasmin.blackboard import Blackboard
from yasmin.state_machine import StateMachine

from yasmin.yasmin_logs import (
set_loggers,
YASMIN_LOG_ERROR,
YASMIN_LOG_WARN,
YASMIN_LOG_INFO,
YASMIN_LOG_DEBUG,
)
12 changes: 5 additions & 7 deletions yasmin/yasmin/state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

from typing import Dict, List, Union
from threading import Lock
from yasmin.state import State
from yasmin.yasmin_logs import YASMIN_LOG_INFO

import yasmin
from yasmin import State
from yasmin.blackboard import Blackboard


Expand Down Expand Up @@ -153,11 +154,8 @@ def execute(self, blackboard: Blackboard) -> str:

# translate outcome using transitions
if outcome in state["transitions"]:
YASMIN_LOG_INFO(
"%s: %s --> %s",
self.__current_state,
outcome,
state["transitions"][outcome],
yasmin.YASMIN_LOG_INFO(
f"{self.__current_state}: {outcome} --> {state['transitions'][outcome]}"
)
outcome = state["transitions"][outcome]

Expand Down
36 changes: 27 additions & 9 deletions yasmin/yasmin/yasmin_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,42 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.


import yasmin
import logging

import yasmin.yasmin_logs

__all__ = [
"set_loggers",
"YASMIN_LOG_ERROR",
"YASMIN_LOG_WARN",
"YASMIN_LOG_INFO",
"YASMIN_LOG_DEBUG",
]


# Define the logging configuration
logging.basicConfig(level=logging.NOTSET, format="%(message)s")


def YASMIN_LOG_ERROR(text: str, *args) -> None:
logging.error("[ERROR] " + text, *args)
def YASMIN_LOG_ERROR(text: str) -> None:
logging.error("[ERROR] " + text)


def YASMIN_LOG_WARN(text: str) -> None:
logging.warning("[WARN] " + text)


def YASMIN_LOG_WARN(text: str, *args) -> None:
logging.warning("[WARN] " + text, *args)
def YASMIN_LOG_INFO(text: str) -> None:
logging.info("[INFO] " + text)


def YASMIN_LOG_INFO(text: str, *args) -> None:
logging.info("[INFO] " + text, *args)
def YASMIN_LOG_DEBUG(text: str) -> None:
logging.debug("[DEBUG] " + text)


def YASMIN_LOG_DEBUG(text: str, *args) -> None:
logging.info("[DEBUG] " + text, *args)
def set_loggers(info, warn, debug, error):
yasmin.YASMIN_LOG_ERROR = error
yasmin.YASMIN_LOG_WARN = warn
yasmin.YASMIN_LOG_INFO = info
yasmin.YASMIN_LOG_DEBUG = debug
6 changes: 3 additions & 3 deletions yasmin_ros/yasmin_ros/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .action_state import ActionState
from .service_state import ServiceState
from .monitor_state import MonitorState
from yasmin_ros.action_state import ActionState
from yasmin_ros.service_state import ServiceState
from yasmin_ros.monitor_state import MonitorState
9 changes: 9 additions & 0 deletions yasmin_ros/yasmin_ros/yasmin_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from rclpy.node import Node
from rclpy.executors import MultiThreadedExecutor

import yasmin


class YasminNode(Node):

Expand All @@ -44,6 +46,13 @@ def __init__(self) -> None:

super().__init__(f"yasmin_{str(uuid.uuid4()).replace('-', '_')}_node")

yasmin.set_loggers(
self.get_logger().info,
self.get_logger().warn,
self.get_logger().debug,
self.get_logger().error,
)

# executor
self._executor = MultiThreadedExecutor()
self._executor.add_node(self)
Expand Down
2 changes: 1 addition & 1 deletion yasmin_viewer/yasmin_viewer/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .yasmin_viewer_pub import YasminViewerPub
from yasmin_viewer.yasmin_viewer_pub import YasminViewerPub

0 comments on commit 206e69e

Please sign in to comment.