Skip to content

Commit

Permalink
DOCS-1827: Update Go module logging examples (viamrobotics#2632)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Rewis <[email protected]>
  • Loading branch information
2 people authored and sguequierre committed Apr 25, 2024
1 parent b12a22a commit de5a9d5
Showing 1 changed file with 9 additions and 7 deletions.
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.CWarnf(ctx, "base %v %s", b.Name(), err.Error())
}
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.CDebugf(ctx, "SetPower Linear: %.2f Angular: %.2f", linear.Y, angular.Z)
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.CDebug(ctx, "Stop")
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.CInfof(ctx, "performing some function with a=%v", a)
// 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", "name", c.Name())
// Log with severity error without a parameter:
c.logger.Errorln("performing some function")
c.logger.CError(ctx, "encountered an error")
}
```

Expand Down

0 comments on commit de5a9d5

Please sign in to comment.