mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-06 10:21:05 +02:00
Simplified, and de-duplicated many of the configuration settings. Removed configuration settings that could be deduced from other settings. Added some basic documentation. Removed the (duplicate?) user email domain validation check in proxy. Removed the ClientID middleware check. Added a shared key option to be used as a PSK instead of using the IDPs ClientID and ClientSecret. Removed the CookieSecure setting as we only support secure. Added a letsencrypt script to generate a wildcard certificate. Removed the argument in proxy's constructor that allowed arbitrary fucntions to be passed in as validators. Updated proxy's authenticator client to match the server implementation of just using a PSK. Moved debug-mode logging into the log package. Removed unused approval prompt setting. Fixed a bug where identity provider urls were hardcoded. Removed a bunch of unit tests. There have been so many changes many of these tests don't make sense and will need to be re-thought.
134 lines
3.7 KiB
Go
134 lines
3.7 KiB
Go
// Package log provides a global logger for zerolog.
|
|
package log // import "github.com/pomerium/pomerium/internal/log"
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/rs/zerolog"
|
|
)
|
|
|
|
// Logger is the global logger.
|
|
var Logger = zerolog.New(os.Stderr).With().Timestamp().Logger()
|
|
|
|
// SetDebugMode tells the logger to use standard out and pretty print output.
|
|
func SetDebugMode() {
|
|
Logger = Logger.Output(zerolog.ConsoleWriter{Out: os.Stdout})
|
|
}
|
|
|
|
// Output duplicates the global logger and sets w as its output.
|
|
func Output(w io.Writer) zerolog.Logger {
|
|
return Logger.Output(w)
|
|
}
|
|
|
|
// With creates a child logger with the field added to its context.
|
|
func With() zerolog.Context {
|
|
return Logger.With()
|
|
}
|
|
|
|
// WithRequest creates a child logger with the remote user added to its context.
|
|
func WithRequest(req *http.Request, function string) zerolog.Logger {
|
|
remoteUser := getRemoteAddr(req)
|
|
return Logger.With().
|
|
Str("function", function).
|
|
Str("req-remote-user", remoteUser).
|
|
Str("req-http-method", req.Method).
|
|
Str("req-host", req.Host).
|
|
Str("req-url", req.URL.String()).
|
|
// Str("req-user-agent", req.Header.Get("User-Agent")).
|
|
Logger()
|
|
}
|
|
|
|
// Level creates a child logger with the minimum accepted level set to level.
|
|
func Level(level zerolog.Level) zerolog.Logger {
|
|
return Logger.Level(level)
|
|
}
|
|
|
|
// Sample returns a logger with the s sampler.
|
|
func Sample(s zerolog.Sampler) zerolog.Logger {
|
|
return Logger.Sample(s)
|
|
}
|
|
|
|
// Hook returns a logger with the h Hook.
|
|
func Hook(h zerolog.Hook) zerolog.Logger {
|
|
return Logger.Hook(h)
|
|
}
|
|
|
|
// Debug starts a new message with debug level.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Debug() *zerolog.Event {
|
|
return Logger.Debug()
|
|
}
|
|
|
|
// Info starts a new message with info level.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Info() *zerolog.Event {
|
|
return Logger.Info()
|
|
}
|
|
|
|
// Warn starts a new message with warn level.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Warn() *zerolog.Event {
|
|
return Logger.Warn()
|
|
}
|
|
|
|
// Error starts a new message with error level.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Error() *zerolog.Event {
|
|
return Logger.Error()
|
|
}
|
|
|
|
// Fatal starts a new message with fatal level. The os.Exit(1) function
|
|
// is called by the Msg method.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Fatal() *zerolog.Event {
|
|
return Logger.Fatal()
|
|
}
|
|
|
|
// Panic starts a new message with panic level. The message is also sent
|
|
// to the panic function.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Panic() *zerolog.Event {
|
|
return Logger.Panic()
|
|
}
|
|
|
|
// WithLevel starts a new message with level.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func WithLevel(level zerolog.Level) *zerolog.Event {
|
|
return Logger.WithLevel(level)
|
|
}
|
|
|
|
// Log starts a new message with no level. Setting zerolog.GlobalLevel to
|
|
// zerolog.Disabled will still disable events produced by this method.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Log() *zerolog.Event {
|
|
return Logger.Log()
|
|
}
|
|
|
|
// Print sends a log event using debug level and no extra field.
|
|
// Arguments are handled in the manner of fmt.Print.
|
|
func Print(v ...interface{}) {
|
|
Logger.Print(v...)
|
|
}
|
|
|
|
// Printf sends a log event using debug level and no extra field.
|
|
// Arguments are handled in the manner of fmt.Printf.
|
|
func Printf(format string, v ...interface{}) {
|
|
Logger.Printf(format, v...)
|
|
}
|
|
|
|
// Ctx returns the Logger associated with the ctx. If no logger
|
|
// is associated, a disabled logger is returned.
|
|
func Ctx(ctx context.Context) *zerolog.Logger {
|
|
return zerolog.Ctx(ctx)
|
|
}
|