Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/jaxsim/logging.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,45 @@
import enum
import inspect
import logging
import os
import warnings

import coloredlogs


class JaxSimWarning(UserWarning):
pass


_original_showwarning = warnings.showwarning
_jaxsim_root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))


def pretty_jaxsim_warning(message, category, filename, lineno, file=None, line=None):
try:
caller_frame = inspect.stack()[2]
caller_file = caller_frame.filename
except Exception:
caller_file = filename

if caller_file.startswith(_jaxsim_root_dir):
print(f"\033[93m⚠️ {category.__name__}:\033[0m {message}")
print(f" → {filename}:{lineno}")
else:
_original_showwarning(message, category, filename, lineno, file, line)


# Register filter & formatter only for JaxSimWarning
# and configure it to show each warning only once
warnings.showwarning = pretty_jaxsim_warning
warnings.filterwarnings("once")


# Utility function to issue a JaxSim warning
def jaxsim_warn(msg):
warnings.warn(msg, category=JaxSimWarning, stacklevel=2)


LOGGER_NAME = "jaxsim"


Expand Down
3 changes: 2 additions & 1 deletion src/jaxsim/parsers/descriptions/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from collections.abc import Sequence

from jaxsim import logging
from jaxsim.logging import jaxsim_warn

from ..kinematic_graph import KinematicGraph, KinematicGraphTransforms, RootPose
from .collision import CollidablePoint, CollisionShape
Expand Down Expand Up @@ -164,7 +165,7 @@ def reduce(self, considered_joints: Sequence[str]) -> ModelDescription:
A `ModelDescription` instance that only includes the considered joints.
"""

logging.warning(
jaxsim_warn(
"The joint order in the model description is not preserved when reducing "
"the model. Consider using the `names_to_indices` method to get the correct "
"order of the joints, or use the `joint_names()` method to inspect the internal joint ordering."
Expand Down