From b71bc23bccda312cb33dc3b6b0b31bd551674f6f Mon Sep 17 00:00:00 2001 From: s4s7 Date: Sat, 18 May 2024 01:58:31 +0900 Subject: [PATCH] rename: CloudLoggingHandlerOptions to Options --- README.md | 2 +- soglog.go | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 823c18d..eb73f42 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Special thanks to nownabe. 3. **You can initialize slog with a one-liner at server startup, allowing you to use its default slog methods throughout your application** ```golang -slog.SetDefault(slog.New(soglog.NewCloudLoggingHandler("your-project-id", &CloudLoggingHandlerOptions{IsStackTraced: true, LabelFieldInjector: yourLabelFieldInjector}) +slog.SetDefault(slog.New(soglog.NewCloudLoggingHandler("your-project-id", &soglog.Options{IsStackTraced: true, LabelFieldInjector: yourLabelFieldInjector}) ``` ## Note diff --git a/soglog.go b/soglog.go index 891639f..d35dfc3 100644 --- a/soglog.go +++ b/soglog.go @@ -39,9 +39,8 @@ type CloudLoggingHandler struct { type labelFieldInjector func(ctx context.Context) (key, value string, found bool) -// CloudLoggingHandlerOptions defines the configuration options for creating a CloudLoggingHandler. -// This struct provides options to enable stack tracing and to inject custom label fields. -type CloudLoggingHandlerOptions struct { +// Options struct provides options to enable stack tracing and to inject custom label fields. +type Options struct { // IsStackTraced indicates whether to include a stack trace in error logs. // If set to true, a stack trace will be added to the log entries when the log level is Error. @@ -55,10 +54,10 @@ type CloudLoggingHandlerOptions struct { // NewCloudLoggingHandler creates a new CloudLoggingHandler with optional settings. // If no options are provided, stack traces will not be included in error logs and no additional label fields will be injected. // Example usage: -// slog.SetDefault(slog.New(soglog.NewCloudLoggingHandler("your-project-id", &CloudLoggingHandlerOptions{IsStackTraced: true, LabelFieldInjector: yourLabelFieldInjector}) -func NewCloudLoggingHandler(projectID string, options ...*CloudLoggingHandlerOptions) *CloudLoggingHandler { +// slog.SetDefault(slog.New(soglog.NewCloudLoggingHandler("your-project-id", &soglog.Options{IsStackTraced: true, LabelFieldInjector: yourLabelFieldInjector}) +func NewCloudLoggingHandler(projectID string, options ...*Options) *CloudLoggingHandler { - opts := &CloudLoggingHandlerOptions{} + opts := &Options{} if len(options) > 0 { opts = options[0] }