-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
51 lines (44 loc) · 1.28 KB
/
options.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
// Copyright 2024 HUMAN Security.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package envite
// Option is a function type for configuring the Environment during initialization.
type Option func(*Environment)
// Logger is a function type for logging messages with different log levels.
type Logger func(level LogLevel, message string)
// LogLevel represents the severity level of a log message.
type LogLevel uint8
const (
// LogLevelTrace represents the trace log level.
LogLevelTrace LogLevel = iota
// LogLevelDebug represents the debug log level.
LogLevelDebug
// LogLevelInfo represents the info log level.
LogLevelInfo
// LogLevelError represents the error log level.
LogLevelError
// LogLevelFatal represents the fatal log level.
LogLevelFatal
)
// String converts a LogLevel value to a string.
func (l LogLevel) String() string {
switch l {
case LogLevelTrace:
return "TRACE"
case LogLevelDebug:
return "DEBUG"
case LogLevelInfo:
return "INFO"
case LogLevelError:
return "ERROR"
case LogLevelFatal:
return "FATAL"
}
return "INFO"
}
// WithLogger is an Option function that sets the logger for the Environment.
func WithLogger(logger Logger) Option {
return func(b *Environment) {
b.Logger = logger
}
}