-
Notifications
You must be signed in to change notification settings - Fork 101
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
Add ZapLogger with option to disable stacktraces #47
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,12 @@ limitations under the License. | |
package logging | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/go-logr/logr" | ||
"github.com/go-logr/zapr" | ||
"go.uber.org/zap" | ||
runtimezap "sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
runtimelog "sigs.k8s.io/controller-runtime/pkg/runtime/log" | ||
) | ||
|
||
|
@@ -34,8 +39,27 @@ var ( | |
// Logger is the base logger used by Crossplane. It delegates to another | ||
// logr.Logger. You *must* call SetLogger to get any actual logging. | ||
Logger = logger.WithName("crossplane") | ||
|
||
// ZapLogger is a Logger implementation. | ||
ZapLogger = zapLogger | ||
) | ||
|
||
// ZapLogger is a Logger implementation from controller runtime. | ||
// If development is true, a Zap development config will be used | ||
// (stacktraces on warnings, no sampling), otherwise a Zap production | ||
// config will be used (stacktraces on errors, sampling). | ||
// If disableStacktrace is true, stacktraces enabled on fatals | ||
// independent of config. | ||
func zapLogger(development bool, disableStacktrace bool) logr.Logger { | ||
zl := runtimezap.RawLoggerTo(os.Stderr, development) | ||
|
||
if disableStacktrace { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you think this should use the new controller-runtime What is your opinion @turkenh? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you noted, updating controller-runtime is not necessary for this specific issue but I agree that it make sense to bump controller-runtime to |
||
zl = zl.WithOptions(zap.AddStacktrace(zap.FatalLevel)) | ||
} | ||
|
||
return zapr.NewLogger(zl) | ||
} | ||
|
||
// SetLogger sets a concrete logging implementation for all deferred Loggers. | ||
func SetLogger(l logr.Logger) { | ||
logger.Fulfill(l) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as discussed in crossplane-contrib/provider-gcp#49, I like the idea of having a common reusable way to get a logger that only does stack traces for fatal level. Can we continue pursuing that on this PR? If we finish and merge this one, then all consumer repos (main crossplane, GCP/AWS/Azure stacks) can just call this one single implementation.