Documentation
¶
Index ¶
- Constants
- Variables
- func Debug(msg string, fields ...zap.Field)
- func Error(msg string, err error, fields ...zap.Field)
- func Fatal(msg string, err error, fields ...zap.Field)
- func GetPath(ctx context.Context) (string, bool)
- func GetPort(ctx context.Context) (string, bool)
- func GetSrcIP(ctx context.Context) (string, bool)
- func GetTraceID(ctx context.Context) (string, bool)
- func Info(msg string, fields ...zap.Field)
- func NewArrayStringField(key string, value []string) zap.Field
- func NewBooleanField(key string, value bool) zap.Field
- func NewInt64Field(key string, value int64) zap.Field
- func NewIntField(key string, value int) zap.Field
- func NewObjectField(key string, value interface{}) zap.Field
- func NewStringField(key string, value string) zap.Field
- func Panic(msg string, err error, fields ...zap.Field)
- func Reset()
- func Sync() error
- func TDR(model LogModel)
- func Warn(msg string, fields ...zap.Field)
- func WithPath(ctx context.Context, path string) context.Context
- func WithPort(ctx context.Context, port string) context.Context
- func WithSrcIP(ctx context.Context, srcIP string) context.Context
- func WithTraceID(ctx context.Context, traceID string) context.Context
- type Config
- type Log
- func (l *Log) Debug(msg string, fields ...zap.Field)
- func (l *Log) Error(msg string, err error, fields ...zap.Field)
- func (l *Log) Fatal(msg string, err error, fields ...zap.Field)
- func (l *Log) Info(msg string, fields ...zap.Field)
- func (l *Log) Panic(msg string, err error, fields ...zap.Field)
- func (l *Log) Sync() error
- func (l *Log) TDR(log LogModel)
- func (l *Log) Warn(msg string, fields ...zap.Field)
- func (l *Log) WithContext(ctx context.Context) LoggerInterface
- type LogModel
- type LoggerInterface
Constants ¶
const ( // TraceIDKey is the context key for trace ID TraceIDKey contextKey = "traceId" // SrcIPKey is the context key for source IP SrcIPKey contextKey = "srcIP" // PortKey is the context key for port PortKey contextKey = "port" // PathKey is the context key for path PathKey contextKey = "path" )
Variables ¶
var SENSITIVE_ATTR = map[string]bool{ "password": true, "license": true, "license_code": true, "token": true, "access_token": true, "refresh_token": true, }
var SENSITIVE_HEADER = []string{
"Authorization",
"Signature",
"Apikey",
}
Functions ¶
func Fatal ¶
Fatal logs a message at FatalLevel.
The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.
func GetTraceID ¶
GetTraceID retrieves trace ID from context
func NewObjectField ¶
func Panic ¶
Panic logs a message at PanicLevel.
The logger then panics, even if logging at PanicLevel is disabled.
func Reset ¶
func Reset()
Reset resets the singleton logger. This is primarily useful for testing. It should not be called in production code.
func Sync ¶
func Sync() error
Sync flushes any buffered log entries. Applications should take care to call Sync before exiting to ensure all log entries are written.
func TDR ¶
func TDR(model LogModel)
TDR (Transaction Detail Request) consist of request and response log
Types ¶
type Config ¶
type Config struct {
// App name
App string `json:"app"`
// App Version
AppVer string `json:"appVer"`
// Log environment (development or production)
Env string `json:"env"`
// Location where the system log will be saved
FileLocation string `json:"fileLocation"`
// Location where the tdr log will be saved
// If empty, defaults to FileLocation + "/tdr.log"
FileTDRLocation string `json:"fileTDRLocation"`
// Maximum size of a single log file.
// If the capacity reach, file will be saved but it will be renamed
// with suffix the current date
FileMaxSize int `json:"fileMaxSize"`
// Maximum number of backup file that will not be deleted
FileMaxBackup int `json:"fileMaxBackup"`
// Number of days where the backup log will not be deleted
FileMaxAge int `json:"fileMaxAge"`
// Log will be printed in console if the value is true
Stdout bool `json:"stdout"`
// Log level (debug, info, warn, error). Defaults to info if not set.
LogLevel zapcore.Level `json:"logLevel"`
// Path to version file. If empty, defaults to "version.txt".
// If set and file exists, will override AppVer.
VersionFilePath string `json:"versionFilePath"`
}
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
func (*Log) Sync ¶
Sync flushes any buffered log entries. Applications should take care to call Sync before exiting to ensure all log entries are written.
func (*Log) WithContext ¶ added in v1.1.0
func (l *Log) WithContext(ctx context.Context) LoggerInterface
type LogModel ¶
type LogModel struct {
TraceID string `json:"traceId"`
CorrelationID string `json:"correlationId"`
SrcIP string `json:"srcIp"`
IP string `json:"ip"`
Port string `json:"port"`
Path string `json:"path"`
Method string `json:"method"`
Header interface{} `json:"header"`
Request interface{} `json:"request"`
StatusCode string `json:"statusCode"`
HttpStatus uint64 `json:"httpStatus"`
Response interface{} `json:"response"`
ResponseTime time.Duration `json:"rt"`
Error interface{} `json:"error"`
OtherData interface{} `json:"otherData"`
}
type LoggerInterface ¶
type LoggerInterface interface {
WithContext(ctx context.Context) LoggerInterface
Debug(message string, fields ...zap.Field)
Info(message string, fields ...zap.Field)
Warn(message string, fields ...zap.Field)
Error(message string, err error, fields ...zap.Field)
Fatal(message string, err error, fields ...zap.Field)
Panic(message string, err error, fields ...zap.Field)
TDR(tdr LogModel)
Sync() error
}
func Load ¶
func Load(config Config) LoggerInterface
Load constructs and returns a singleton logger instance. The logger is initialized only once on the first call.
func NewLogger ¶
func NewLogger(conf Config) LoggerInterface
func WithContext ¶ added in v1.1.0
func WithContext(ctx context.Context) LoggerInterface
