-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
193 additions
and
119 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
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,43 @@ | ||
// Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
// Licensed under the GNU Affero General Public License (AGPL). | ||
// See License.AGPL.txt in the project root for license information. | ||
|
||
package prettyprint | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log/slog" | ||
) | ||
|
||
var _ slog.Handler = &Handler{} | ||
|
||
type Handler struct { | ||
Attrs []slog.Attr | ||
LogLevel slog.Level | ||
} | ||
|
||
// Enabled implements slog.Handler. | ||
func (h *Handler) Enabled(ctx context.Context, lvl slog.Level) bool { | ||
return lvl >= h.LogLevel | ||
} | ||
|
||
// Handle implements slog.Handler. | ||
func (h *Handler) Handle(ctx context.Context, req slog.Record) error { | ||
fmt.Printf("[%s] %s\n", req.Level, req.Message) | ||
return nil | ||
} | ||
|
||
// WithAttrs implements slog.Handler. | ||
func (h *Handler) WithAttrs(attrs []slog.Attr) slog.Handler { | ||
h.Attrs = append(h.Attrs, attrs...) | ||
return &Handler{ | ||
Attrs: attrs, | ||
LogLevel: h.LogLevel, | ||
} | ||
} | ||
|
||
// WithGroup implements slog.Handler. | ||
func (h *Handler) WithGroup(name string) slog.Handler { | ||
return h | ||
} |
Oops, something went wrong.