Skip to content

RSDK-10245 Use VIAM_MODULE_NAME as logger name for golang module loggers #4850

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
Mar 12, 2025

Conversation

benjirewis
Copy link
Member

@benjirewis benjirewis commented Mar 12, 2025

RSDK-10245

Uses VIAM_MODULE_NAME as the logger name for loggers created through NewLoggerFromArgs if passed in moduleName is "".

Golang modular resource logs that used to look like:

2025-03-12T19:20:59.145Z	INFO	rdk:component:generic/counter1	simplemodule/module.go:37	Creating a new counter component!	{"log_ts":"2025-03-12T19:20:59.144Z"}

now look like:

2025-03-12T19:21:52.640Z	INFO	SimpleModule.rdk:component:generic/counter1	simplemodule/module.go:37	Creating a new counter component!	{"log_ts":"2025-03-12T19:21:52.640Z"}

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Mar 12, 2025
// string if not specified in environment.)
if moduleName == "" {
moduleName, _ = os.LookupEnv("VIAM_MODULE_NAME")
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were a couple different ways to do this. Both ModularMain and NewModuleFromArgs call NewLoggerFromArgs(""), so this is what I chose to do. Could also pass in VIAM_MODULE_NAME to NewLoggerFromArgs from both those call sites. Don't want to break any of this module API though for existing modules (e.g. not take in a moduleName parameter to this function.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm, maybe add something to the comment saying this will happen?

@benjirewis benjirewis requested a review from cheukt March 12, 2025 19:37
@benjirewis benjirewis marked this pull request as ready for review March 12, 2025 19:37
Copy link
Member

@cheukt cheukt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

// string if not specified in environment.)
if moduleName == "" {
moduleName, _ = os.LookupEnv("VIAM_MODULE_NAME")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm, maybe add something to the comment saying this will happen?

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Mar 12, 2025
@benjirewis benjirewis merged commit 16a11da into viamrobotics:main Mar 12, 2025
16 checks passed
@benjirewis benjirewis deleted the module-logger-uses-name branch March 12, 2025 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants