Documentation ¶
Index ¶
- Constants
- func DisableColor(flag bool)
- func EnableColor(flag bool)
- func InitDefaultLogger()
- func InitLogger(loggerName string)
- func InitOtel(serviceName, version, accountId, clusterName string, collectorUrl url.URL) context.Context
- func L() helpers.ILogger
- func ListLoggersNames() []string
- func ShutdownOtel(ctx context.Context)
Constants ¶
const ( // Logger level environment name EnvLoggerLevel = "KS_LOGGER_LEVEL" // Logger name environment name EnvLoggerName = "KS_LOGGER_NAME" )
Variables ¶
This section is empty.
Functions ¶
func DisableColor ¶
func DisableColor(flag bool)
func EnableColor ¶ added in v0.0.6
func EnableColor(flag bool)
func InitDefaultLogger ¶
func InitDefaultLogger()
func InitLogger ¶
func InitLogger(loggerName string)
InitLogger initialize desired logger
Use: InitLogger("<logger name>")
Supported logger names (call ListLoggersNames() for listing supported loggers) - "zap": Logger from package "go.uber.org/zap" - "pretty", "colorful": Human friendly colorful logger - "none", "mock", "empty", "ignore": Logger will not print anything - "icon", "emoji": Human friendly logger with colors and icons/symbols
Default: - "pretty"
If the logger name is empty, will try to get the logger name from the environment variable KS_LOGGER_NAME. If the logger level environment variable is set, will set the logger level to the value of the environment variable.
e.g. InitLogger("none") -> will initialize the mock logger
func InitOtel ¶ added in v0.0.7
func InitOtel(serviceName, version, accountId, clusterName string, collectorUrl url.URL) context.Context
InitOtel configures OpenTelemetry to export data to OTEL_COLLECTOR_SVC using uptrace collector. You have to set the env variable OTEL_COLLECTOR_SVC to enable otel. It is required to call ShutdownOtel on the context at the end of the main.
func main() { // configure otel ctx := logger.InitOtel(logger.L(), "<service>", "<version>") defer logger.ShutdownOtel(ctx) // create a span ctx, span := otel.Tracer("").Start(ctx, "<name of the span>") defer span.End() if err := cmd.Execute(ctx); err != nil { // attach log to the span logger.L().Ctx(ctx).Fatal(err.Error()) } }
func L ¶
Return initialized logger. If logger not initialized, will call InitializeLogger() with the default value
func ListLoggersNames ¶
func ListLoggersNames() []string
func ShutdownOtel ¶ added in v0.0.7
Types ¶
This section is empty.