Files
zitadel/backend/v3/instrumentation/logformat_enumer.go
T
11dbb1b277 feat(logging): add streams (#11435)
# Which Problems Are Solved

Streams allow differentiating logs produced by different components of
Zitadel.

# How the Problems Are Solved

The `backend/v3/instrumentation/logging` package now exposes convenience
function for setting and getting a logger from the context. As well as
high-level functions to emit log records at various levels. When
constructing a new logger a "stream" needs to be specified:

- **runtime**: General runtime logs, such as startup and shutdown
messages. Default for logs that do not belong to the other categories.
- **request**: Logs for incoming API and HTTP requests.
- **event_handler**: Logs for event handling in projections.
- **queue**: Logs for the job queue processing.
- **event_pusher**: Logs for event pushing to the database. Disabled by
default, contains sensitive information.

Each line from the returned logger contains a `stream` field as well as
a `version` field with the current Zitadel version.

## Runtime config

Streams can be enabled by passing an array of stream names in the
runtime config. Because some log streams may contain sensitive data
(especially events), it is now also possible to mask values by their
key.

# Additional Changes

- Wrap `slogctx` in the `logging` package. (Except API error converter
packages, because of import cycle)
- Add some docs to `logging` package so other devs understand how to add
logging to Zitadel
- Add `logging.OnError` and `logging.WithError` helper functions with
`Panic()` and `Fatal()` methods, to preserve current calls in the `cmd`
packages.
- Add instance context extractor.
- Only output request details in the request info log. Request ID
remains propagated through context.
- Moved middleware functionality into protocol specific packages. 
- Removed setting of URI to context in metric middleware. There were ony
setters and no getters. (Unused value)
- Reuse a single statusWriter in the middleware package for middlewares
that need to know the response status.

# Additional Context

- Closes #11333
- Closes #11331 
- Partly #11330

---------

Co-authored-by: Silvan <[email protected]>
2026-02-04 11:51:43 +01:00

107 lines
3.1 KiB
Go

// Code generated by "enumer -type=LogFormat -trimprefix=LogFormat -text -linecomment -transform=snake"; DO NOT EDIT.
package instrumentation
import (
"fmt"
"strings"
)
const _LogFormatName = "disabledtextjsongcpgcp_error_reporting"
var _LogFormatIndex = [...]uint8{0, 0, 8, 12, 16, 19, 38}
const _LogFormatLowerName = "disabledtextjsongcpgcp_error_reporting"
func (i LogFormat) String() string {
if i < 0 || i >= LogFormat(len(_LogFormatIndex)-1) {
return fmt.Sprintf("LogFormat(%d)", i)
}
return _LogFormatName[_LogFormatIndex[i]:_LogFormatIndex[i+1]]
}
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
func _LogFormatNoOp() {
var x [1]struct{}
_ = x[LogFormatUnspecified-(0)]
_ = x[LogFormatDisabled-(1)]
_ = x[LogFormatText-(2)]
_ = x[LogFormatJSON-(3)]
_ = x[LogFormatGCP-(4)]
_ = x[LogFormatGCPErrorReporting-(5)]
}
var _LogFormatValues = []LogFormat{LogFormatUnspecified, LogFormatDisabled, LogFormatText, LogFormatJSON, LogFormatGCP, LogFormatGCPErrorReporting}
var _LogFormatNameToValueMap = map[string]LogFormat{
_LogFormatName[0:0]: LogFormatUnspecified,
_LogFormatLowerName[0:0]: LogFormatUnspecified,
_LogFormatName[0:8]: LogFormatDisabled,
_LogFormatLowerName[0:8]: LogFormatDisabled,
_LogFormatName[8:12]: LogFormatText,
_LogFormatLowerName[8:12]: LogFormatText,
_LogFormatName[12:16]: LogFormatJSON,
_LogFormatLowerName[12:16]: LogFormatJSON,
_LogFormatName[16:19]: LogFormatGCP,
_LogFormatLowerName[16:19]: LogFormatGCP,
_LogFormatName[19:38]: LogFormatGCPErrorReporting,
_LogFormatLowerName[19:38]: LogFormatGCPErrorReporting,
}
var _LogFormatNames = []string{
_LogFormatName[0:0],
_LogFormatName[0:8],
_LogFormatName[8:12],
_LogFormatName[12:16],
_LogFormatName[16:19],
_LogFormatName[19:38],
}
// LogFormatString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func LogFormatString(s string) (LogFormat, error) {
if val, ok := _LogFormatNameToValueMap[s]; ok {
return val, nil
}
if val, ok := _LogFormatNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to LogFormat values", s)
}
// LogFormatValues returns all values of the enum
func LogFormatValues() []LogFormat {
return _LogFormatValues
}
// LogFormatStrings returns a slice of all String values of the enum
func LogFormatStrings() []string {
strs := make([]string, len(_LogFormatNames))
copy(strs, _LogFormatNames)
return strs
}
// IsALogFormat returns "true" if the value is listed in the enum definition. "false" otherwise
func (i LogFormat) IsALogFormat() bool {
for _, v := range _LogFormatValues {
if i == v {
return true
}
}
return false
}
// MarshalText implements the encoding.TextMarshaler interface for LogFormat
func (i LogFormat) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface for LogFormat
func (i *LogFormat) UnmarshalText(text []byte) error {
var err error
*i, err = LogFormatString(string(text))
return err
}