Add stdout logging support to LoggerImpl as an option
This commit is contained in:
@@ -13,10 +13,19 @@ import (
|
||||
)
|
||||
|
||||
type LoggerImpl struct {
|
||||
logger log.Logger
|
||||
logger log.Logger
|
||||
logToStdout bool
|
||||
}
|
||||
|
||||
func NewLoggerImpl(name string, version string) *LoggerImpl {
|
||||
type LoggerImplOption func(*LoggerImpl)
|
||||
|
||||
func PrintToStdout() LoggerImplOption {
|
||||
return func(l *LoggerImpl) {
|
||||
l.logToStdout = true
|
||||
}
|
||||
}
|
||||
|
||||
func NewLoggerImpl(name string, version string, opts ...LoggerImplOption) *LoggerImpl {
|
||||
// Create an OTLP exporter
|
||||
logExporter, err := otlploggrpc.New(context.Background())
|
||||
if err != nil {
|
||||
@@ -51,9 +60,13 @@ func NewLoggerImpl(name string, version string) *LoggerImpl {
|
||||
// Create a logger
|
||||
logger := provider.Logger("salezenify.logger")
|
||||
|
||||
return &LoggerImpl{
|
||||
loggerImpl := &LoggerImpl{
|
||||
logger: logger,
|
||||
}
|
||||
for _, option := range opts {
|
||||
option(loggerImpl)
|
||||
}
|
||||
return loggerImpl
|
||||
}
|
||||
|
||||
func (l *LoggerImpl) Debug(a ...any) {
|
||||
@@ -63,6 +76,9 @@ func (l *LoggerImpl) Debug(a ...any) {
|
||||
println(message)
|
||||
return
|
||||
}
|
||||
if l.logToStdout {
|
||||
PrintDebug(a)
|
||||
}
|
||||
|
||||
// Use OpenTelemetry logger
|
||||
ctx := context.Background()
|
||||
@@ -86,6 +102,10 @@ func (l *LoggerImpl) Error(a ...any) {
|
||||
return
|
||||
}
|
||||
|
||||
if l.logToStdout {
|
||||
PrintError(a)
|
||||
}
|
||||
|
||||
// Use OpenTelemetry logger
|
||||
ctx := context.Background()
|
||||
message := joinStrings(a)
|
||||
|
||||
Reference in New Issue
Block a user