logging

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2025 License: MIT Imports: 15 Imported by: 0

README

appsap-logging

Getting Started

Logging lib for appsap-core framework

Installation

Run the following command to install the package:

go get github.com/mortired/appsap-logging

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckElasticsearchHealth

func CheckElasticsearchHealth(config ElasticsearchConfig) error

CheckElasticsearchHealth checks if Elasticsearch is accessible and can write to the specified index This function is now separate and should be called manually when needed

func CheckElasticsearchHealthManually

func CheckElasticsearchHealthManually() error

CheckElasticsearchHealthManually performs a manual health check of Elasticsearch This function can be called manually to verify Elasticsearch connectivity

func ErrorLoggerMiddleware

func ErrorLoggerMiddleware(logger *Logger) echo.MiddlewareFunc

ErrorLoggerMiddleware creates middleware for logging errors

func GetElasticsearchClient

func GetElasticsearchClient() (*elasticsearch.Client, error)

GetElasticsearchClient creates and returns an Elasticsearch client for manual operations

func GetElasticsearchStatus

func GetElasticsearchStatus() (map[string]interface{}, error)

GetElasticsearchStatus returns the current status of Elasticsearch configuration

func LoggerMiddleware

func LoggerMiddleware(logger *Logger) echo.MiddlewareFunc

LoggerMiddleware creates Echo middleware that uses Zap logger

func NewElasticsearchClient

func NewElasticsearchClient(config ElasticsearchConfig) (*elasticsearch.Client, error)

NewElasticsearchClient creates a new Elasticsearch client

func ResetElasticsearchConfig

func ResetElasticsearchConfig()

ResetElasticsearchConfig resets the global configuration (mainly for testing)

func TestElasticsearchConnection

func TestElasticsearchConnection() error

TestElasticsearchConnection tests the connection to Elasticsearch without creating logs

Types

type Config

type Config struct {
	Level       string
	Environment string
	Service     string
	Version     string
}

Config holds logger configuration

func LoadConfigFromEnv

func LoadConfigFromEnv() Config

LoadConfigFromEnv loads logger configuration from environment variables

type ElasticsearchConfig

type ElasticsearchConfig struct {
	URLs     []string
	Username string
	Password string
	Index    string
	Enabled  bool
	// Health check settings
	HealthCheckEnabled bool
	HealthCheckTimeout time.Duration
}

ElasticsearchConfig holds Elasticsearch configuration

func GetElasticsearchConfig

func GetElasticsearchConfig() (*ElasticsearchConfig, error)

GetElasticsearchConfig returns the global Elasticsearch configuration This function loads configuration only once and caches it

func LoadElasticsearchConfigFromEnv

func LoadElasticsearchConfigFromEnv() (ElasticsearchConfig, error)

LoadElasticsearchConfigFromEnv loads Elasticsearch configuration from environment variables

type ElasticsearchCore

type ElasticsearchCore struct {
	// contains filtered or unexported fields
}

ElasticsearchCore implements zapcore.Core for Elasticsearch logging

func NewElasticsearchCore

func NewElasticsearchCore(baseCore zapcore.Core, esClient *elasticsearch.Client, index string) *ElasticsearchCore

NewElasticsearchCore creates a new Elasticsearch core

func (*ElasticsearchCore) Check

Check implements zapcore.Core

func (*ElasticsearchCore) Close

func (ec *ElasticsearchCore) Close() error

Close closes the bulk indexer

func (*ElasticsearchCore) Enabled

func (ec *ElasticsearchCore) Enabled(level zapcore.Level) bool

Enabled implements zapcore.Core

func (*ElasticsearchCore) Sync

func (ec *ElasticsearchCore) Sync() error

Sync implements zapcore.Core

func (*ElasticsearchCore) With

func (ec *ElasticsearchCore) With(fields []zap.Field) zapcore.Core

With implements zapcore.Core

func (*ElasticsearchCore) Write

func (ec *ElasticsearchCore) Write(entry zapcore.Entry, fields []zap.Field) error

Write implements zapcore.Core

type Logger

type Logger struct {
	*zap.Logger
}

Logger wraps zap logger

func New

func New(config Config) (*Logger, error)

New creates a new logger instance

func NewLoggerWithElasticsearch

func NewLoggerWithElasticsearch(config Config, esConfig ElasticsearchConfig) (*Logger, error)

NewLoggerWithElasticsearch creates a new logger with Elasticsearch integration

func NewStandardLogger

func NewStandardLogger(config Config) (*Logger, error)

NewStandardLogger creates a standard logger without Elasticsearch

func (*Logger) WithContext

func (l *Logger) WithContext(ctx context.Context) *Logger

WithContext creates a new logger with context values

func (*Logger) WithFields

func (l *Logger) WithFields(fields map[string]interface{}) *Logger

WithFields creates a new logger with additional fields

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL