Documentation ¶
Index ¶
- Variables
- func StreamServerLogging(logger log.Logger, withTimer bool) grpc.StreamServerInterceptor
- func StreamServerTiming(logger log.Logger) grpc.StreamServerInterceptor
- func UnaryServerLogging(logger log.Logger, withTimer bool) grpc.UnaryServerInterceptor
- func UnaryServerTiming(logger log.Logger) grpc.UnaryServerInterceptor
- type GRPCLogServer
- type LSAddr
- type LSLogger
- type LSOpts
- type LSServiceLogger
- type LSStreamInterceptor
- type LSTiming
- type LSUnaryInterceptor
- type LogServer
- type LogServerConfig
- func MultiConf(conf ...LogServerConfig) LogServerConfig
- func WithAddr(addr string) LogServerConfig
- func WithGRPCOpts(opts ...grpc.ServerOption) LogServerConfig
- func WithLogger(loggers ...log.Logger) LogServerConfig
- func WithServiceLogger(loggers ...log.Logger) LogServerConfig
- func WithServiceLoggerV(loggers ...log.Logger) LogServerConfig
- func WithStreamInterceptor(name string, itcp grpc.StreamServerInterceptor) LogServerConfig
- func WithTLS(certPath, keyPath string, caPath ...string) LogServerConfig
- func WithTiming() LogServerConfig
- func WithUnaryInterceptor(name string, itcp grpc.UnaryServerInterceptor) LogServerConfig
Constants ¶
This section is empty.
Variables ¶
var ( ErrCACertAddFailed error = errors.New("failed to add server CA's certificate") LogServerConfigs = map[int]LogServerConfig{ 0: defaultConfig, 1: WithServiceLogger(log.New()), 2: WithServiceLogger(log.New(log.NilConfig)), 3: WithServiceLogger(log.New(log.WithFormat(log.TextColorLevelFirst))), 4: WithServiceLogger(log.New(log.WithFormat(log.FormatJSON))), 5: WithLogger(), 6: WithLogger(log.New(log.WithFormat(log.TextColorLevelFirst))), 7: WithLogger(log.New(log.WithFormat(log.FormatJSON))), } DefaultCfg LogServerConfig = LogServerConfigs[0] // placeholder for an initialized default LogServerConfig ServiceLogDefault LogServerConfig = LogServerConfigs[1] // placeholder for an initialized default logger as service logger ServiceLogNil LogServerConfig = LogServerConfigs[2] // placeholder for an initialized nil-service-logger LogServerConfig ServiceLogColor LogServerConfig = LogServerConfigs[3] // placeholder for an initialized colored, level-first, service logger ServiceLogJSON LogServerConfig = LogServerConfigs[4] // placeholder for an initialized JSON service logger LoggerDefault LogServerConfig = LogServerConfigs[5] // placeholder for an initialized default logger LoggerColor LogServerConfig = LogServerConfigs[6] // placeholder for an initialized colored, level-first logger LoggerJSON LogServerConfig = LogServerConfigs[7] // placeholder for an initialized JSON logger )
Functions ¶
func StreamServerLogging ¶
func StreamServerLogging(logger log.Logger, withTimer bool) grpc.StreamServerInterceptor
StreamServerLogging returns a new stream server interceptor that adds a gRPC Server Logger which captures inbound / outbound interactions with the service
To be able to safely capture the message exchange within the stream, a wrapper is created containing the logger, the stream and the method name. This wrapper will implement the grpc.ServerStream interface, to add new actions when sending and receiving a message.
This assures that the stream is untouched while still adding a new feature to each exchange.
func StreamServerTiming ¶
func StreamServerTiming(logger log.Logger) grpc.StreamServerInterceptor
StreamServerTiming returns a new stream server interceptor that adds a gRPC Server Logger which times inbound / outbound interactions with the service
To be able to safely capture the message exchange within the stream, a wrapper is created containing the logger, the stream and the method name. This wrapper will implement the grpc.ServerStream interface, to add new actions when sending and receiving a message.
This assures that the stream is untouched while still adding a new feature to each exchange.
func UnaryServerLogging ¶
func UnaryServerLogging(logger log.Logger, withTimer bool) grpc.UnaryServerInterceptor
UnaryServerLogging returns a new unary server interceptor that adds a gRPC Server Logger which captures inbound / outbound interactions with the service
func UnaryServerTiming ¶
func UnaryServerTiming(logger log.Logger) grpc.UnaryServerInterceptor
UnaryServerTiming returns a new unary server interceptor that adds a gRPC Server Logger which times inbound / outbound interactions with the service
Types ¶
type GRPCLogServer ¶
type GRPCLogServer struct {
// contains filtered or unexported fields
}
GRPCLogServer struct will define the elements required to build and work with a gRPC Log Server.
Besides the gRPC-related elements, this struct will contain two Loggers (Logger and SvcLogger). This allows the gRPC Server to both do its job -- and register any (important) log events to a different output, with its own configuration and requirements.
func New ¶
func New(confs ...LogServerConfig) *GRPCLogServer
New function will create a new gRPC Log Server, ensuring that at least the default settings are applied.
Once the Log Server is configured, a goroutine is kicked off to listen to internal comms (the registerComms() method), which will route runtime-related log messages to its SvcLogger
func (GRPCLogServer) Channels ¶
func (s GRPCLogServer) Channels() (logCh, logSvCh chan *event.Event, errCh chan error)
Channels method returns channels for a Log Server's I/O. It returns a channel for log messages (for actual log event writes), a channel for the service logger (the server's own logger), and an error channel to collect Log Server errors from.
func (GRPCLogServer) Serve ¶
func (s GRPCLogServer) Serve()
Serve method will be a long-running, blocking function which will launch the gRPC server
It will start listening to the resgistered address and launch its internal message handler routine. Then, the gRPC Server is created (as a package-level instance), registered for reflection. Finally, the grpc.Server's own Serve() method is executed and persisted unless an error occurs.
func (GRPCLogServer) Stop ¶
func (s GRPCLogServer) Stop()
Stop method will be a wrapper for the routine involved to (gracefully) stop this gRPC Log Server.
type LSAddr ¶
type LSAddr struct {
// contains filtered or unexported fields
}
LSAddr struct is a custom LogServerConfig to define addresses to new gRPC Log Server
type LSLogger ¶
type LSLogger struct {
// contains filtered or unexported fields
}
LSLogger struct is a custom LogServerConfig to define the (served) logger for the new gRPC Log Server
type LSOpts ¶
type LSOpts struct {
// contains filtered or unexported fields
}
LSOpts struct is a custom LogServerConfig to define gRPC Dial Options to new gRPC Log Server
type LSServiceLogger ¶
type LSServiceLogger struct {
// contains filtered or unexported fields
}
LSServiceLogger struct is a custom LogServerConfig to define the service logger for the new gRPC Log Server
func (LSServiceLogger) Apply ¶
func (l LSServiceLogger) Apply(ls *gRPCLogServerBuilder)
Apply method will set this option's logger as the input GRPCLogServer's service logger, and its logger interceptors
type LSStreamInterceptor ¶
type LSStreamInterceptor struct {
// contains filtered or unexported fields
}
LSStreamInterceptor struct is a custom LogServerConfig to define a custom interceptor
func (LSStreamInterceptor) Apply ¶
func (l LSStreamInterceptor) Apply(ls *gRPCLogServerBuilder)
Apply method will set this option's Stream interceptor on the gRPCLogServerBuilder
type LSTiming ¶
type LSTiming struct{}
LSTiming struct is a custom LogServerConfig to add a timing module to exchanged RPCs
type LSUnaryInterceptor ¶
type LSUnaryInterceptor struct {
// contains filtered or unexported fields
}
LSUnaryInterceptor struct is a custom LogServerConfig to define a custom interceptor
func (LSUnaryInterceptor) Apply ¶
func (l LSUnaryInterceptor) Apply(ls *gRPCLogServerBuilder)
Apply method will set this option's Unary interceptor on the gRPCLogClientBuilder
type LogServer ¶
type LogServer interface { Serve() Stop() Channels() (logCh, logSvCh chan *event.Event, errCh chan error) }
LogServer interface defines the behavior of a gRPC Log Server, which focuses mostly on its (background) runtime operations.
The interface exposes a `Channels()` method nevertheless, which allows for local control of log messages (and error handling) without having to send a message over-the-wire
func MultiLogger ¶
Multilogger function takes in any number of LogServer interfaces, merging them together and returning a single LogServer.
This is a LogServer multiplexer.
type LogServerConfig ¶
type LogServerConfig interface {
Apply(ls *gRPCLogServerBuilder)
}
LogServerConfig interface describes the behavior that a LogServerConfig object should have
The single Apply(lb *GRPCLogServer) method allows for different modules to apply changes to a GRPCLogServer, in a non-blocking way for other features.
Each feature should implement its own structs with their own methods; where they can implement Apply(lb *GRPCLogServer) to set their own configurations to the input GRPCLogServer
func MultiConf ¶
func MultiConf(conf ...LogServerConfig) LogServerConfig
MultiConf function is a wrapper for multiple configs to be bundled (and executed) in one shot.
Similar to io.MultiWriter, it will iterate through all set LogServerConfig and run the same method on each of them.
func WithAddr ¶
func WithAddr(addr string) LogServerConfig
WithAddr function will take one address for the gRPC Log Server to listen to.
If this address is empty, defaults are applied (localhost:9099)
func WithGRPCOpts ¶
func WithGRPCOpts(opts ...grpc.ServerOption) LogServerConfig
WithGRPCOpts will allow passing in any number of gRPC Server Options, which are added to the gRPC Log Server.
Running this function with zero parameters will generate a LogServerConfig with the default gRPC Server Options.
func WithLogger ¶
func WithLogger(loggers ...log.Logger) LogServerConfig
WithLogger function will define this gRPC Log Server's logger.
This logger will register the gRPC Client incoming log messages, from either Unary or Stream RPCs.
This function's loggers input parameter is variadic -- it supports setting any number of loggers. If no input is provided, then it will default to setting this logger as a default logger (with its output set to os.Stderr)
func WithServiceLogger ¶
func WithServiceLogger(loggers ...log.Logger) LogServerConfig
WithServiceLogger function will define this gRPC Log Server's service logger.
This logger will register the gRPC Server's transactions, and not the client's incoming log messages.
This function's loggers input parameter is variadic -- it supports setting any number of loggers. If no input is provided, then it will default to setting this service logger as a nil logger (one which doesn't do anything)
func WithServiceLoggerV ¶
func WithServiceLoggerV(loggers ...log.Logger) LogServerConfig
WithServiceLoggerV function will define this gRPC Log Server's service logger, in verbose mode -- capturing interactions for each RPC. This differs from a log level filter as it will add a logging interceptor as a module.
This logger will register the gRPC Server's transactions, and not the client's incoming log messages.
This function's loggers input parameter is variadic -- it supports setting any number of loggers. If no input is provided, then it will default to setting this service logger as a nil logger (one which doesn't do anything)
func WithStreamInterceptor ¶
func WithStreamInterceptor(name string, itcp grpc.StreamServerInterceptor) LogServerConfig
WithStreamInterceptor function creates a new Stream interceptor config, based on the input interceptor, mapped to the input name. Note that depending of the order of the chanining and naming, this may overwrite other existing interceptors.
func WithTLS ¶
func WithTLS(certPath, keyPath string, caPath ...string) LogServerConfig
WithTLS function allows configuring TLS / mTLS for a gRPC Log Server.
If only two parameters are passed (certPath, keyPath), it will run its TLS flow. If three parameters are set (certPath, keyPath, caPath), it will run its mTLS flow.
The function will try to open the certificates that the user points to in these paths, so it is required that they are accessible in terms of permissions. These configurations will panic if they fail to execute. This is OK since it should happen as soon as the server is executed.
func WithTiming ¶
func WithTiming() LogServerConfig
WithTiming function will set a gRPC Log Server's service logger to measure the time taken when executing RPCs. It is only an option, and is directly tied to the configured service logger.
Since defaults are enforced, the service logger value is never nil.
This function configures the gRPC server's timer interceptors
func WithUnaryInterceptor ¶
func WithUnaryInterceptor(name string, itcp grpc.UnaryServerInterceptor) LogServerConfig
WithUnaryInterceptor function creates a new Unary interceptor config, based on the input interceptor, mapped to the input name. Note that depending of the order of the chanining and naming, this may overwrite other existing interceptors.