-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
76 lines (64 loc) · 2.38 KB
/
logger.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2024 The original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package gslog
import (
"context"
"cloud.google.com/go/logging"
)
// Logger is wraps the set of methods that are used when interacting with a
// logging.Logger. This interface facilitates stubbing out calls to the Logger
// for the purposes of testing and benchmarking.
type Logger interface {
Log
LogSync
// Flush blocks until all currently buffered log entries are sent.
//
// If any errors occurred since the last call to Flush from any Logger, or the
// creation of the client if this is the first call, then Flush returns a non-nil
// error with summary information about the errors. This information is unlikely to
// be actionable. For more accurate error reporting, set Client.OnError.
Flush() error
}
// Log wraps the asynchronous buffered logging of records to
// Google Cloud Logging.
type Log interface {
// Log buffers the Entry for output to the logging service. It never blocks.
Log(e logging.Entry)
}
// LogSync wraps the synchronous logging of records to
// Google Cloud Logging.
type LogSync interface {
// LogSync logs the Entry synchronously without any buffering. Because LogSync is slow
// and will block, it is intended primarily for debugging or critical errors.
// Prefer Log for most uses.
LogSync(ctx context.Context, e logging.Entry) error
}
// The LoggerFunc type is an adapter to allow the use of
// ordinary functions as a Logger. If fn is a function
// with the appropriate signature, LoggerFunc(fn) is a
// Logger that calls fn.
type LoggerFunc func(e logging.Entry)
// Log implements Log.Log.
func (fn LoggerFunc) Log(e logging.Entry) {
fn(e)
}
// LogSync implements LogSync.LogSync.
func (fn LoggerFunc) LogSync(_ context.Context, e logging.Entry) error {
fn(e)
return nil
}
// Flush implements Logger.Flush.
func (fn LoggerFunc) Flush() error {
return nil
}