Documentation
¶
Index ¶
- Variables
- func DefaultOpenSearchConfig(url string, insecure bool) opensearch.Config
- func FlushLogsWithTimeout(flushFunc CleanUp, timeout time.Duration, logger *zap.Logger) func()
- func IsOpenSearchReady(url string, timeout time.Duration, insecure bool) bool
- func MustLoadLocation(name string) *time.Location
- func MustNewLoggerDebug(opts ...LogOptFunc) *zap.Logger
- func MustNewZapLogger(opts ...LogOptFunc) *zap.Logger
- func MustNewZapLoggerWithFlush(opts ...LogOptFunc) (*zap.Logger, func() error)
- func ReplaceGlobalToShowLogZapL(logger *zap.Logger)
- type CleanUp
- type IndexConfig
- type IndexFormat
- type IndexGenerator
- type LogOptFunc
- func WithConsole(b bool) LogOptFunc
- func WithDevEnv(b bool) LogOptFunc
- func WithInsecure(insecure bool) LogOptFunc
- func WithInternalLogger(logger *zap.Logger) LogOptFunc
- func WithLJ(b bool) LogOptFunc
- func WithLjFilename(s string) LogOptFunc
- func WithLogLevel(lvl zapcore.Level) LogOptFunc
- func WithOpenSearchConfig(config *opensearch.Config) LogOptFunc
- func WithOpenSearchIndex(baseIndex string, dateFormat string) LogOptFunc
- func WithTimeLocation(location *time.Location) LogOptFunc
- type LogOpts
Constants ¶
This section is empty.
Variables ¶
var ( ErrWriterClosed = errors.New("writer already closed") ErrWriterIsStopping = errors.New("writer is stopping") )
var ErrCreateOpensearchCore = errors.New("failed to create OpenSearch core")
Functions ¶
func DefaultOpenSearchConfig ¶ added in v0.1.2
func DefaultOpenSearchConfig(url string, insecure bool) opensearch.Config
func FlushLogsWithTimeout ¶ added in v0.1.2
FlushLogsWithTimeout attempts to flush logs with a timeout. It returns a function suitable for use with defer.
func IsOpenSearchReady ¶ added in v0.1.3
func MustLoadLocation ¶ added in v0.1.4
LoadLocation loads a timezone location or panics on error
func MustNewLoggerDebug ¶ added in v0.1.1
func MustNewLoggerDebug(opts ...LogOptFunc) *zap.Logger
func MustNewZapLogger ¶
func MustNewZapLogger(opts ...LogOptFunc) *zap.Logger
MustNewZapLogger create a simple zap logger
func MustNewZapLoggerWithFlush ¶ added in v0.1.2
func MustNewZapLoggerWithFlush(opts ...LogOptFunc) (*zap.Logger, func() error)
MustNewZapLoggerWithFlush creates a zap logger and returns it along with a flush function. This function wraps MustNewZapLogger to provide a consistent interface with MustNewZapLoggerWithOpenSearch.
Types ¶
type CleanUp ¶ added in v0.1.5
func MustNewZapLoggerWithOpenSearch ¶ added in v0.1.2
func MustNewZapLoggerWithOpenSearch(opts ...LogOptFunc) (*zap.Logger, CleanUp)
MustNewZapLoggerWithOpenSearch creates a zap logger with OpenSearch support. It panics if the required OpenSearch configuration is missing or if initialization fails.
Parameters:
- opts: Variadic LogOptFunc parameters for configuring the logger
Returns:
- *zap.Logger: A configured zap logger instance
- func() error: A flush function that should be called before program termination to ensure all logs are written to OpenSearch
OpenSearch Configuration:
- Bulk Indexing: Uses OpenSearch bulk API for efficient log shipping
- Workers: 2 concurrent workers for processing logs
- Buffer Size: 256KB before forcing flush
- Flush Interval: Every 10 seconds
- Error Handling: Logs bulk indexing errors through internal logger
The function supports both console and OpenSearch output. When OpenSearch is enabled, both openSearchConfig and openSearchIndex must be provided through the options.
type IndexConfig ¶ added in v0.1.4
type IndexConfig struct {
BaseIndexName string
Format string // If empty, defaults to FormatDot
Location *time.Location // If nil, defaults to UTC
}
IndexConfig configures how index names are generated
type IndexFormat ¶ added in v0.1.4
type IndexFormat string
IndexFormat defines standard time formats for index naming
const ( DateFormatDot IndexFormat = "2006.01.02" // example: logs-2024.01.25 DateFormatDash IndexFormat = "2006-01-02" // example: logs-2024-01-25 DateFormatShort IndexFormat = "20060102" // example: logs-20240125 )
Predefined index formats
type IndexGenerator ¶ added in v0.1.4
type IndexGenerator struct {
// contains filtered or unexported fields
}
IndexGenerator generates time-based index names
func NewIndexGenerator ¶ added in v0.1.4
func NewIndexGenerator(config IndexConfig) *IndexGenerator
NewIndexGenerator creates a new index name generator
func (*IndexGenerator) GetIndexName ¶ added in v0.1.4
func (g *IndexGenerator) GetIndexName() string
type LogOptFunc ¶
type LogOptFunc func(o *LogOpts)
func WithConsole ¶
func WithConsole(b bool) LogOptFunc
func WithDevEnv ¶
func WithDevEnv(b bool) LogOptFunc
func WithInsecure ¶ added in v0.1.2
func WithInsecure(insecure bool) LogOptFunc
func WithInternalLogger ¶ added in v0.1.2
func WithInternalLogger(logger *zap.Logger) LogOptFunc
func WithLJ ¶
func WithLJ(b bool) LogOptFunc
func WithLogLevel ¶
func WithLogLevel(lvl zapcore.Level) LogOptFunc
func WithOpenSearchConfig ¶ added in v0.1.2
func WithOpenSearchConfig(config *opensearch.Config) LogOptFunc
func WithOpenSearchIndex ¶ added in v0.1.2
func WithOpenSearchIndex(baseIndex string, dateFormat string) LogOptFunc
WithOpenSearchIndex sets the base index name and optional date format for rotation
func WithTimeLocation ¶ added in v0.1.4
func WithTimeLocation(location *time.Location) LogOptFunc
WithTimeLocation sets the timezone for index rotation