Logging
  • 1 Minute to read

Logging


Article summary

RayaApplicationBase includes an embedded logger that ensures all the entries will be tracked and stored by the Ra-Ya SDK and App Manager.

Embedded logger

The log() method adds a record to the logger, for example:

from raya.application_base import RayaApplicationBase

class RayaApplication(RayaApplicationBase):
    async def setup(self):
        self.log(f'Hello from setup()')

    async def loop(self):
        self.log(f'Hello from loop()')
        await self.finish_app()

    async def finish(self):
        self.log(f'Hello from finish()')

Output:

Hello from setup()
Hello from loop()
Hello from finish()

Loggin Level

You can also specify the loggin level by importing the LogLevel enum:

...
from raya.logger import LogLevel
...
self.log(LogLevel.TRACE, 'Trace message')
self.log(LogLevel.DEBUG, 'Debug message')
self.log(LogLevel.INFO, 'Info message (default)')
self.log(LogLevel.WARNING, 'Warning message')
self.log(LogLevel.ERROR, 'Error message')
self.log(LogLevel.FATAL, 'Fatal message')

Output:

(trace) Trace message
(debug) Debug message
Info message
(warning) Warning message
(error) Error message
(fatal) Fatal message

By default, the INFO level doesn't show the level in the stdout record.

Custom Loggers

You can logger objects with custom names:

...
self.log_nav = self.create_logger('navigation')
self.log_arms = self.create_logger('arms')
...        
self.log_nav(LogLevel.ERROR, 'Couldn't get the selected target')
....
self.log_arms('Arms ready to move')
...

Output:

(error) <RayaApp.app_name.navigation>: Couldn't get the selected target
(info) <RayaApp.app_name.arms>: Arms ready to move

Records

Application stores and manages the loggers' records in the log folder.


Was this article helpful?