Skip to content
Merged
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
9 changes: 9 additions & 0 deletions module/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,16 @@ type moduleLogger struct {
// to start modules with a "log-level" commandline argument. The created logger
// will send log events back to the module's parent (the RDK) via gRPC when
// possible and to STDOUT when not possible.
//
// `moduleName` will be the name of the created logger. Pass `""` if you wish to
// use the value specified by the `VIAM_MODULE_NAME` environment variable.
func NewLoggerFromArgs(moduleName string) logging.Logger {
// If no `moduleName` was specified, grab it from the environment (will still be empty
// 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?


modAppender := newModuleAppender()
baseLogger := logging.NewBlankLogger(moduleName)
baseLogger.AddAppender(modAppender)
Expand Down
Loading