github.com/lastbackend/toolkit@v0.0.0-20241020043710-cafa37b95aad/pkg/runtime/logger/logger.go (about)

     1  /*
     2  Copyright [2014] - [2023] The Last.Backend authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package logger
    18  
    19  import (
    20  	"go.uber.org/fx/fxevent"
    21  	"io"
    22  )
    23  
    24  type Fields map[string]interface{}
    25  
    26  type Level int8
    27  
    28  const (
    29  	FatalLevel Level = iota
    30  	PanicLevel
    31  	ErrorLevel
    32  	WarnLevel
    33  	InfoLevel
    34  	DebugLevel
    35  )
    36  
    37  type Options struct {
    38  	Verbose         Level `env:"VERBOSE"`
    39  	JSONFormat      bool  `env:"JSON_FORMAT"`
    40  	CallerSkipCount int
    41  	Fields          Fields
    42  	Out             io.Writer
    43  	Tags            map[string]string
    44  }
    45  
    46  type Logger interface {
    47  	Debug(args ...interface{})
    48  	Debugf(format string, args ...interface{})
    49  	Info(args ...interface{})
    50  	Infof(format string, args ...interface{})
    51  	Warn(args ...interface{})
    52  	Warnf(format string, args ...interface{})
    53  	Error(args ...interface{})
    54  	Errorf(format string, args ...interface{})
    55  	Panic(args ...interface{})
    56  	Panicf(format string, args ...interface{})
    57  	Fatal(args ...interface{})
    58  	Fatalf(format string, args ...interface{})
    59  	V(Level) Logger
    60  	Inject(fn func(level Level))
    61  	Fx() fxevent.Logger
    62  }