Skip to content

RSDK-9438: Update example usage to show resource-level logging #797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 10, 2024
Merged
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
5 changes: 1 addition & 4 deletions docs/examples/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,8 @@
"from typing import Any, Dict, Mapping, Optional\n",
"\n",
"from viam.components.sensor import Sensor\n",
"from viam.logging import getLogger\n",
"from viam.utils import SensorReading\n",
"\n",
"LOGGER = getLogger(__name__)\n",
"\n",
"\n",
"class MySensor(Sensor):\n",
" # Subclass the Viam Sensor component and implement the required functions\n",
Expand All @@ -293,7 +290,7 @@
" async def close(self):\n",
" # This is a completely optional function to include. This will be called when the resource is removed from the config or the module\n",
" # is shutting down.\n",
" LOGGER.info(f\"{self.name} is closed.\")\n",
" self.logger.info(f\"{self.name} is closed.\")\n",
"\n",
"# Anything below this line is optional and will be replaced later, but may come in handy for debugging and testing.\n",
"# To use, call `python wifi_sensor_module.py` in the command line while in the `src` directory.\n",
Expand Down
5 changes: 1 addition & 4 deletions docs/examples/module_step2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
from typing_extensions import Self

from viam.components.sensor import Sensor
from viam.logging import getLogger
from viam.proto.app.robot import ComponentConfig
from viam.proto.common import ResourceName
from viam.resource.base import ResourceBase
from viam.resource.registry import Registry, ResourceCreatorRegistration
from viam.resource.types import Model, ModelFamily
from viam.utils import SensorReading

LOGGER = getLogger(__name__)


class MySensor(Sensor):
# Subclass the Viam Sensor component and implement the required functions
Expand All @@ -34,7 +31,7 @@ async def get_readings(self, extra: Optional[Dict[str, Any]] = None, **kwargs) -
async def close(self):
# This is a completely optional function to include. This will be called when the resource is removed from the config or the module
# is shutting down.
LOGGER.info(f"{self.name} is closed.")
self.logger.info(f"{self.name} is closed.")


async def main():
Expand Down
5 changes: 1 addition & 4 deletions docs/examples/module_step2_optional.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
from typing_extensions import Self

from viam.components.sensor import Sensor
from viam.logging import getLogger
from viam.proto.app.robot import ComponentConfig
from viam.proto.common import ResourceName
from viam.resource.base import ResourceBase
from viam.resource.registry import Registry, ResourceCreatorRegistration
from viam.resource.types import Model, ModelFamily
from viam.utils import SensorReading

LOGGER = getLogger(__name__)


class MySensor(Sensor):
# Subclass the Viam Sensor component and implement the required functions
Expand Down Expand Up @@ -56,7 +53,7 @@ def reconfigure(self, config: ComponentConfig, dependencies: Mapping[ResourceNam
async def close(self):
# This is a completely optional function to include. This will be called when the resource is removed from the config or the module
# is shutting down.
LOGGER.info(f"{self.name} is closed.")
self.logger.info(f"{self.name} is closed.")


async def main():
Expand Down
5 changes: 1 addition & 4 deletions docs/examples/module_step3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing_extensions import Self

from viam.components.sensor import Sensor
from viam.logging import getLogger
from viam.module.module import Module
from viam.proto.app.robot import ComponentConfig
from viam.proto.common import ResourceName
Expand All @@ -14,8 +13,6 @@
from viam.resource.types import Model, ModelFamily
from viam.utils import SensorReading

LOGGER = getLogger(__name__)


class MySensor(Sensor):
# Subclass the Viam Sensor component and implement the required functions
Expand All @@ -35,7 +32,7 @@ async def get_readings(self, extra: Optional[Dict[str, Any]] = None, **kwargs) -
async def close(self):
# This is a completely optional function to include. This will be called when the resource is removed from the config or the module
# is shutting down.
LOGGER.info(f"{self.name} is closed.")
self.logger.info(f"{self.name} is closed.")


async def main():
Expand Down
5 changes: 1 addition & 4 deletions docs/examples/my_cool_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
from typing import Any, Dict, List, Optional, Tuple

from viam.components.arm import Arm, JointPositions, KinematicsFileFormat, Pose
from viam.logging import getLogger
from viam.operations import run_with_operation
from viam.proto.common import Capsule, Geometry, Sphere

LOGGER = getLogger(__name__)


class MyCoolArm(Arm):
# Subclass the Viam Arm component and implement the required functions
Expand Down Expand Up @@ -109,4 +106,4 @@ async def get_kinematics(self, extra: Optional[Dict[str, Any]] = None, **kwargs)
async def close(self):
# This is a completely optional function to include. This will be called when the resource is removed from the config or the module
# is shutting down.
LOGGER.info(f"{self.name} is closed.")
self.logger.info(f"{self.name} is closed.")
Loading