Skip to content
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

DOCS-1827: Update Go module logging examples #2632

Merged
merged 3 commits into from
Mar 12, 2024
Merged
Changes from 1 commit
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
16 changes: 9 additions & 7 deletions docs/registry/create/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ func (b *myBase) Reconfigure(ctx context.Context, deps resource.Dependencies, co

geometries, err := kinematicbase.CollisionGeometry(conf.Frame)
if err != nil {
b.logger.Warnf("base %v %s", b.Name(), err.Error())
b.logger.CWarnw(ctx, "base %v %s", b.Name(), err.Error())
andf-viam marked this conversation as resolved.
Show resolved Hide resolved
}
b.geometries = geometries

Expand Down Expand Up @@ -497,7 +497,7 @@ func (b *myBase) SetVelocity(ctx context.Context, linear, angular r3.Vector, ext

// SetPower computes relative power between the wheels and sets power for both motors.
func (b *myBase) SetPower(ctx context.Context, linear, angular r3.Vector, extra map[string]interface{}) error {
b.logger.Debugf("SetPower Linear: %.2f Angular: %.2f", linear.Y, angular.Z)
b.logger.CDebugw(ctx, "SetPower Linear: %.2f Angular: %.2f", linear.Y, angular.Z)
andf-viam marked this conversation as resolved.
Show resolved Hide resolved
if math.Abs(linear.Y) < 0.01 && math.Abs(angular.Z) < 0.01 {
return b.Stop(ctx, extra)
}
Expand All @@ -509,7 +509,7 @@ func (b *myBase) SetPower(ctx context.Context, linear, angular r3.Vector, extra

// Stop halts motion.
func (b *myBase) Stop(ctx context.Context, extra map[string]interface{}) error {
b.logger.Debug("Stop")
b.logger.CDebugw(ctx, "Stop")
andf-viam marked this conversation as resolved.
Show resolved Hide resolved
err1 := b.left.Stop(ctx, extra)
err2 := b.right.Stop(ctx, extra)
return multierr.Combine(err1, err2)
Expand Down Expand Up @@ -1060,13 +1060,15 @@ func init() {
resource.RegisterComponent(...)
}
// Finally, when you need to log, use the functions on your component's logger:
fn (c *component) someFunction(a int) {
fn (c *component) someFunction(ctx context.Context, a int) {
// Log with severity info:
c.logger.Infof("performing some function with a=%v",a)
c.logger.CInfow(ctx, "performing some function with a=%v", a)
andf-viam marked this conversation as resolved.
Show resolved Hide resolved
// Log with severity debug (using value wrapping):
c.logger.Debugw("performing some function","a",a)
c.logger.CDebugw(ctx, "performing some function", "a" ,a)
// Log with severity warn:
c.logger.CWarnw(ctx, "encountered warning for component: %v ", c.Name())
andf-viam marked this conversation as resolved.
Show resolved Hide resolved
// Log with severity error without a parameter:
c.logger.Errorln("performing some function")
c.logger.CErrorw(ctx, "encountered an error")
andf-viam marked this conversation as resolved.
Show resolved Hide resolved
}
```

Expand Down
Loading