Skip to content

Commit 16a11da

Browse files
authored
RSDK-10245 Use VIAM_MODULE_NAME as logger name for golang module loggers (viamrobotics#4850)
1 parent dc787f3 commit 16a11da

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

module/log.go

+9
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,16 @@ type moduleLogger struct {
5959
// to start modules with a "log-level" commandline argument. The created logger
6060
// will send log events back to the module's parent (the RDK) via gRPC when
6161
// possible and to STDOUT when not possible.
62+
//
63+
// `moduleName` will be the name of the created logger. Pass `""` if you wish to
64+
// use the value specified by the `VIAM_MODULE_NAME` environment variable.
6265
func NewLoggerFromArgs(moduleName string) logging.Logger {
66+
// If no `moduleName` was specified, grab it from the environment (will still be empty
67+
// string if not specified in environment.)
68+
if moduleName == "" {
69+
moduleName, _ = os.LookupEnv("VIAM_MODULE_NAME")
70+
}
71+
6372
modAppender := newModuleAppender()
6473
baseLogger := logging.NewBlankLogger(moduleName)
6574
baseLogger.AddAppender(modAppender)

0 commit comments

Comments
 (0)