-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
`FuncDur` must be used in a `defer` statement. This new helper function receives the function name and the time when the function started and logs out the time it took to run. Example: ```go package mypackage func MyFunction() { defer logger.FuncDur(time.Now(), "mypackage.MyFunction") ... } ``` Signed-off-by: Salim Afiune Maya <[email protected]>
- Loading branch information
Showing
8 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package logger | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
// FuncDur must be used in a `defer` statement. It receives the function name and the time | ||
// when the function started and logs out the time it took to execute. | ||
// | ||
// ```go | ||
// | ||
// func MyFunction() { | ||
// defer logger.FuncDur(time.Now(), "mypackage.MyFunction") | ||
// | ||
// ... | ||
// } | ||
// | ||
// ``` | ||
func FuncDur(start time.Time, name string) { | ||
log.Trace().Str("func", name). | ||
TimeDiff("took", time.Now(), start). | ||
Msgf("logger.FuncDur>") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters