package logrus

import (
	
	
	
	
	
	
)

// LogFunction For big messages, it can be more efficient to pass a function
// and only call it if the log level is actually enables rather than
// generating the log message and then checking if the level is enabled
type LogFunction func() []any

type Logger struct {
	// The logs are `io.Copy`'d to this in a mutex. It's common to set this to a
	// file, or leave it default which is `os.Stderr`. You can also set this to
	// something more adventurous, such as logging to Kafka.
	Out io.Writer

	// Hooks for the logger instance. These allow firing events based on logging
	// levels and log entries. For example, to send errors to an error tracking
	// service, log to StatsD or dump the core on fatal errors.
	Hooks LevelHooks

	// All log entries pass through the formatter before logged to Out. The
	// included formatters are `TextFormatter` and `JSONFormatter` for which
	// TextFormatter is the default. In development (when a TTY is attached) it
	// logs with colors, but to a file it wouldn't. You can easily implement your
	// own that implements the `Formatter` interface, see the `README` or included
	// formatters for examples.
	Formatter Formatter

	// Flag for whether to log caller info (off by default)
	ReportCaller bool

	// The logging level the logger should log at. This is typically (and defaults
	// to) `logrus.Info`, which allows Info(), Warn(), Error() and Fatal() to be
	// logged.
	Level Level

	// Used to sync writing to the log. Locking is enabled by Default
	mu mutexWrap

	// Reusable empty entry
	entryPool sync.Pool

	// Function to exit the application, defaults to `os.Exit()`
	ExitFunc func(int)

	// The buffer pool used to format the log. If it is nil, the default global
	// buffer pool will be used.
	BufferPool BufferPool
}

// MutexWrap is the mutex implementation used by [Logger].
//
// Deprecated: MutexWrap is an implementation detail of Logger and should not be used directly.
type MutexWrap = mutexWrap

type mutexWrap struct {
	lock     sync.Mutex
	disabled bool
}

func ( *mutexWrap) () {
	if !.disabled {
		.lock.Lock()
	}
}

func ( *mutexWrap) () {
	if !.disabled {
		.lock.Unlock()
	}
}

func ( *mutexWrap) () {
	.disabled = true
}

// New Creates a new logger. Configuration should be set by changing [Formatter],
// Out and Hooks directly on the default Logger instance. You can also just
// instantiate your own:
//
//	var log = &logrus.Logger{
//	  Out:       os.Stderr,
//	  Formatter: new(logrus.TextFormatter),
//	  Hooks:     make(logrus.LevelHooks),
//	  Level:     logrus.DebugLevel,
//	}
//
// It's recommended to make this a global instance called `log`.
func () *Logger {
	return &Logger{
		Out:          os.Stderr,
		Formatter:    new(TextFormatter),
		Hooks:        make(LevelHooks),
		Level:        InfoLevel,
		ExitFunc:     os.Exit,
		ReportCaller: false,
	}
}

func ( *Logger) () *Entry {
	,  := .entryPool.Get().(*Entry)
	if  {
		return 
	}
	return NewEntry()
}

func ( *Logger) ( *Entry) {
	.Data = map[string]any{}
	.entryPool.Put()
}

// WithField allocates a new entry and adds a field to it.
// Debug, Print, Info, Warn, Error, Fatal or Panic must be then applied to
// this new returned entry.
// If you want multiple fields, use `WithFields`.
func ( *Logger) ( string,  any) *Entry {
	 := .newEntry()
	defer .releaseEntry()
	return .WithField(, )
}

// WithFields adds a struct of fields to the log entry. It calls [Entry.WithField]
// for each Field.
func ( *Logger) ( Fields) *Entry {
	 := .newEntry()
	defer .releaseEntry()
	return .WithFields()
}

// WithError adds an error as single field to the log entry.  It calls
// [Entry.WithError] for the given error.
func ( *Logger) ( error) *Entry {
	 := .newEntry()
	defer .releaseEntry()
	return .WithError()
}

// WithContext add a context to the log entry.
func ( *Logger) ( context.Context) *Entry {
	 := .newEntry()
	defer .releaseEntry()
	return .WithContext()
}

// WithTime overrides the time of the log entry.
func ( *Logger) ( time.Time) *Entry {
	 := .newEntry()
	defer .releaseEntry()
	return .WithTime()
}

// Logf logs a formatted message at the specified level.
//
// Using Logf with [PanicLevel] or [FatalLevel] intentionally does not
// trigger a panic or exit. Logf treats the level as logging severity only;
// use [Logger.Panicf] or [Logger.Fatalf] when those side effects are desired.
func ( *Logger) ( Level,  string,  ...any) {
	if .IsLevelEnabled() {
		 := .newEntry()
		.Logf(, , ...)
		.releaseEntry()
	}
}

func ( *Logger) ( string,  ...any) {
	.Logf(TraceLevel, , ...)
}

func ( *Logger) ( string,  ...any) {
	.Logf(DebugLevel, , ...)
}

func ( *Logger) ( string,  ...any) {
	.Logf(InfoLevel, , ...)
}

func ( *Logger) ( string,  ...any) {
	 := .newEntry()
	.Printf(, ...)
	.releaseEntry()
}

func ( *Logger) ( string,  ...any) {
	.Logf(WarnLevel, , ...)
}

func ( *Logger) ( string,  ...any) {
	.Warnf(, ...)
}

func ( *Logger) ( string,  ...any) {
	.Logf(ErrorLevel, , ...)
}

func ( *Logger) ( string,  ...any) {
	.Logf(FatalLevel, , ...)
	.Exit(1)
}

func ( *Logger) ( string,  ...any) {
	if .IsLevelEnabled(PanicLevel) {
		 := .newEntry()
		defer .releaseEntry()
		.Panicf(, ...)
	}
}

// Log logs a message at the specified level.
//
// Using Log with [PanicLevel] or [FatalLevel] intentionally does not
// trigger a panic or exit. Log treats the level as logging severity only;
// use [Logger.Panic] or [Logger.Fatal] when those side effects are desired.
func ( *Logger) ( Level,  ...any) {
	if .IsLevelEnabled() {
		 := .newEntry()
		.Log(, ...)
		.releaseEntry()
	}
}

// LogFn logs a message returned by fn at the specified level.
//
// Using LogFn with [PanicLevel] or [FatalLevel] intentionally does not
// trigger a panic or exit. LogFn treats the level as logging severity only;
// use [Logger.PanicFn] or [Logger.FatalFn] when those side effects are desired.
func ( *Logger) ( Level,  LogFunction) {
	if .IsLevelEnabled() {
		 := .newEntry()
		.Log(, ()...)
		.releaseEntry()
	}
}

func ( *Logger) ( ...any) {
	.Log(TraceLevel, ...)
}

func ( *Logger) ( ...any) {
	.Log(DebugLevel, ...)
}

func ( *Logger) ( ...any) {
	.Log(InfoLevel, ...)
}

func ( *Logger) ( ...any) {
	 := .newEntry()
	.Print(...)
	.releaseEntry()
}

func ( *Logger) ( ...any) {
	.Log(WarnLevel, ...)
}

func ( *Logger) ( ...any) {
	.Warn(...)
}

func ( *Logger) ( ...any) {
	.Log(ErrorLevel, ...)
}

func ( *Logger) ( ...any) {
	.Log(FatalLevel, ...)
	.Exit(1)
}

func ( *Logger) ( ...any) {
	if .IsLevelEnabled(PanicLevel) {
		 := .newEntry()
		defer .releaseEntry()
		.Panic(...)
	}
}

func ( *Logger) ( LogFunction) {
	.LogFn(TraceLevel, )
}

func ( *Logger) ( LogFunction) {
	.LogFn(DebugLevel, )
}

func ( *Logger) ( LogFunction) {
	.LogFn(InfoLevel, )
}

func ( *Logger) ( LogFunction) {
	 := .newEntry()
	.Print(()...)
	.releaseEntry()
}

func ( *Logger) ( LogFunction) {
	.LogFn(WarnLevel, )
}

func ( *Logger) ( LogFunction) {
	.WarnFn()
}

func ( *Logger) ( LogFunction) {
	.LogFn(ErrorLevel, )
}

func ( *Logger) ( LogFunction) {
	.LogFn(FatalLevel, )
	.Exit(1)
}

func ( *Logger) ( LogFunction) {
	if .IsLevelEnabled(PanicLevel) {
		 := .newEntry()
		defer .releaseEntry()
		.Panic(()...)
	}
}

// Logln logs a message at the specified level with Println-style spacing.
//
// Using Logln with [PanicLevel] or [FatalLevel] intentionally does not
// trigger a panic or exit. Logln treats the level as logging severity only;
// use [Logger.Panicln] or [Logger.Fatalln] when those side effects are desired.
func ( *Logger) ( Level,  ...any) {
	if .IsLevelEnabled() {
		 := .newEntry()
		.Logln(, ...)
		.releaseEntry()
	}
}

func ( *Logger) ( ...any) {
	.Logln(TraceLevel, ...)
}

func ( *Logger) ( ...any) {
	.Logln(DebugLevel, ...)
}

func ( *Logger) ( ...any) {
	.Logln(InfoLevel, ...)
}

func ( *Logger) ( ...any) {
	 := .newEntry()
	.Println(...)
	.releaseEntry()
}

func ( *Logger) ( ...any) {
	.Logln(WarnLevel, ...)
}

func ( *Logger) ( ...any) {
	.Warnln(...)
}

func ( *Logger) ( ...any) {
	.Logln(ErrorLevel, ...)
}

func ( *Logger) ( ...any) {
	.Logln(FatalLevel, ...)
	.Exit(1)
}

func ( *Logger) ( ...any) {
	if .IsLevelEnabled(PanicLevel) {
		 := .newEntry()
		defer .releaseEntry()
		.Panicln(...)
	}
}

func ( *Logger) ( int) {
	runHandlers()
	if .ExitFunc == nil {
		.ExitFunc = os.Exit
	}
	.ExitFunc()
}

// SetNoLock disables the lock for situations where a file is opened with
// appending mode, and safe for concurrent writes to the file (within 4k
// message on Linux). In these cases user can choose to disable the lock.
func ( *Logger) () {
	.mu.Disable()
}

func ( *Logger) () Level {
	return Level(atomic.LoadUint32((*uint32)(&.Level)))
}

// SetLevel sets the logger level.
func ( *Logger) ( Level) {
	atomic.StoreUint32((*uint32)(&.Level), uint32())
}

// GetLevel returns the logger level.
func ( *Logger) () Level {
	return .level()
}

// AddHook adds a hook to the logger hooks.
func ( *Logger) ( Hook) {
	.mu.Lock()
	defer .mu.Unlock()
	.Hooks.Add()
}

// hooksForLevel returns a snapshot of the hooks registered for the given level.
// The returned slice is a shallow copy and may be used without holding logger.mu.
func ( *Logger) ( Level) []Hook {
	.mu.Lock()
	 := .Hooks[]
	if len() == 0 {
		.mu.Unlock()
		return nil
	}
	 := make([]Hook, len())
	copy(, )
	.mu.Unlock()
	return 
}

// IsLevelEnabled checks if logging for the given level is enabled.
func ( *Logger) ( Level) bool {
	return .level() >= 
}

// SetFormatter sets the logger formatter.
func ( *Logger) ( Formatter) {
	.mu.Lock()
	defer .mu.Unlock()
	.Formatter = 
}

// SetOutput sets the logger output.
func ( *Logger) ( io.Writer) {
	.mu.Lock()
	defer .mu.Unlock()
	.Out = 
}

// SetReportCaller sets whether the caller stack frame must be logged.
func ( *Logger) ( bool) {
	.mu.Lock()
	defer .mu.Unlock()
	.ReportCaller = 
}

// ReplaceHooks replaces the logger hooks and returns the old ones
func ( *Logger) ( LevelHooks) LevelHooks {
	.mu.Lock()
	defer .mu.Unlock()
	 := .Hooks
	.Hooks = 
	return 
}

// SetBufferPool sets the logger buffer pool.
func ( *Logger) ( BufferPool) {
	.mu.Lock()
	defer .mu.Unlock()
	.BufferPool = 
}