logs

package
v0.0.117 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2023 License: MIT Imports: 21 Imported by: 3

Documentation

Overview

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

Index

Constants

View Source
const (
	DefaultMaxAge         = 72 * time.Hour
	DefaultMaxCount       = 72
	DefaultRotateInterval = time.Hour
	//100MB
	DefaultRotateSize = 104857600
)

Variables

View Source
var (
	Log_Level_name = map[int32]string{
		0: "panic",
		1: "fatal",
		2: "error",
		3: "warn",
		4: "info",
		5: "debug",
		6: "trace",
	}
	Log_Level_value = map[string]int32{
		"panic": 0,
		"fatal": 1,
		"error": 2,
		"warn":  3,
		"info":  4,
		"debug": 5,
		"trace": 6,
	}
)

Enum value maps for Log_Level.

View Source
var (
	Log_Formatter_name = map[int32]string{
		0: "text",
		1: "json",
		2: "glog",
	}
	Log_Formatter_value = map[string]int32{
		"text": 0,
		"json": 1,
		"glog": 2,
	}
)

Enum value maps for Log_Formatter.

View Source
var (
	Log_Redirct_name = map[int32]string{
		0: "stdout",
		1: "file",
	}
	Log_Redirct_value = map[string]int32{
		"stdout": 0,
		"file":   1,
	}
)

Enum value maps for Log_Redirct.

View Source
var File_pkg_logs_log_proto protoreflect.FileDescriptor

Functions

func GetLogger added in v0.0.71

func GetLogger(ctx context.Context) *logrus.Entry

func GetLoggerOrFallback added in v0.0.81

func GetLoggerOrFallback(ctx context.Context, defaultValue string) *logrus.Entry

func WithRotate

func WithRotate(log *logrus.Logger, filedir string, redirect Log_Redirct, options ...RotateOption) error

Types

type CallerPrettyfierFunc

type CallerPrettyfierFunc func(f *runtime.Frame) (function string, file string)

func GenShortCallPrettyfier

func GenShortCallPrettyfier() CallerPrettyfierFunc

type CompletedConfig

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

func (CompletedConfig) Apply

func (c CompletedConfig) Apply() error

func (CompletedConfig) Validate

func (c CompletedConfig) Validate() error

Validate checks Config.

type Config

type Config struct {
	Proto     Log
	Validator *validator.Validate
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(options ...ConfigOption) *Config

func (*Config) ApplyOptions

func (o *Config) ApplyOptions(options ...ConfigOption) *Config

func (*Config) Complete

func (c *Config) Complete() CompletedConfig

Complete set default ServerRunOptions.

type ConfigOption

type ConfigOption interface {
	// contains filtered or unexported methods
}

A ConfigOption sets options.

func WithViper

func WithViper(v *viper.Viper) ConfigOption

type ConfigOptionFunc

type ConfigOptionFunc func(*Config)

ConfigOptionFunc wraps a function that modifies Client into an implementation of the ConfigOption interface.

type EmptyConfigOption

type EmptyConfigOption struct{}

EmptyConfigOption does not alter the configuration. It can be embedded in another structure to build custom options.

This API is EXPERIMENTAL.

type EmptyRotateOption

type EmptyRotateOption struct{}

EmptyRotateOption does not alter the configuration. It can be embedded in another structure to build custom options.

This API is EXPERIMENTAL.

type HookHandler

type HookHandler func(entry *logrus.Entry) error

func (HookHandler) Fire

func (h HookHandler) Fire(entry *logrus.Entry) error

func (HookHandler) Levels

func (h HookHandler) Levels() []logrus.Level

type Log

type Log struct {
	Level             Log_Level          `protobuf:"varint,1,opt,name=level,proto3,enum=api.v1.viper.logs.Log_Level" json:"level,omitempty"`
	Formatter         Log_Formatter      `protobuf:"varint,2,opt,name=formatter,proto3,enum=api.v1.viper.logs.Log_Formatter" json:"formatter,omitempty"`
	Filepath          string             `protobuf:"bytes,3,opt,name=filepath,proto3" json:"filepath,omitempty"`
	MaxAge            *duration.Duration `protobuf:"bytes,4,opt,name=max_age,json=maxAge,proto3" json:"max_age,omitempty"`
	MaxCount          int64              `protobuf:"varint,5,opt,name=max_count,json=maxCount,proto3" json:"max_count,omitempty"`
	RotateInterval    *duration.Duration `protobuf:"bytes,6,opt,name=rotate_interval,json=rotateInterval,proto3" json:"rotate_interval,omitempty"`
	RotateSize        int64              `protobuf:"varint,7,opt,name=rotate_size,json=rotateSize,proto3" json:"rotate_size,omitempty"`
	ReportCaller      bool               `protobuf:"varint,8,opt,name=report_caller,json=reportCaller,proto3" json:"report_caller,omitempty"`
	EnableGoroutineId bool               `protobuf:"varint,9,opt,name=enable_goroutine_id,json=enableGoroutineId,proto3" json:"enable_goroutine_id,omitempty"`
	Redirct           Log_Redirct        `protobuf:"varint,10,opt,name=redirct,proto3,enum=api.v1.viper.logs.Log_Redirct" json:"redirct,omitempty"`
	// contains filtered or unexported fields
}

func (*Log) Descriptor deprecated

func (*Log) Descriptor() ([]byte, []int)

Deprecated: Use Log.ProtoReflect.Descriptor instead.

func (*Log) GetEnableGoroutineId added in v0.0.73

func (x *Log) GetEnableGoroutineId() bool

func (*Log) GetFilepath

func (x *Log) GetFilepath() string

func (*Log) GetFormatter

func (x *Log) GetFormatter() Log_Formatter

func (*Log) GetLevel

func (x *Log) GetLevel() Log_Level

func (*Log) GetMaxAge

func (x *Log) GetMaxAge() *duration.Duration

func (*Log) GetMaxCount

func (x *Log) GetMaxCount() int64

func (*Log) GetRedirct added in v0.0.86

func (x *Log) GetRedirct() Log_Redirct

func (*Log) GetReportCaller

func (x *Log) GetReportCaller() bool

func (*Log) GetRotateInterval

func (x *Log) GetRotateInterval() *duration.Duration

func (*Log) GetRotateSize

func (x *Log) GetRotateSize() int64

func (*Log) ProtoMessage

func (*Log) ProtoMessage()

func (*Log) ProtoReflect

func (x *Log) ProtoReflect() protoreflect.Message

func (*Log) Reset

func (x *Log) Reset()

func (*Log) String

func (x *Log) String() string

type Log_Formatter

type Log_Formatter int32
const (
	Log_text Log_Formatter = 0
	Log_json Log_Formatter = 1
	Log_glog Log_Formatter = 2
)

func (Log_Formatter) Descriptor

func (Log_Formatter) Enum

func (x Log_Formatter) Enum() *Log_Formatter

func (Log_Formatter) EnumDescriptor deprecated

func (Log_Formatter) EnumDescriptor() ([]byte, []int)

Deprecated: Use Log_Formatter.Descriptor instead.

func (Log_Formatter) Number

func (Log_Formatter) String

func (x Log_Formatter) String() string

func (Log_Formatter) Type

type Log_Level

type Log_Level int32
const (
	Log_panic Log_Level = 0
	Log_fatal Log_Level = 1
	Log_error Log_Level = 2
	Log_warn  Log_Level = 3
	Log_info  Log_Level = 4
	Log_debug Log_Level = 5
	Log_trace Log_Level = 6
)

func (Log_Level) Descriptor

func (Log_Level) Descriptor() protoreflect.EnumDescriptor

func (Log_Level) Enum

func (x Log_Level) Enum() *Log_Level

func (Log_Level) EnumDescriptor deprecated

func (Log_Level) EnumDescriptor() ([]byte, []int)

Deprecated: Use Log_Level.Descriptor instead.

func (Log_Level) Number

func (x Log_Level) Number() protoreflect.EnumNumber

func (Log_Level) String

func (x Log_Level) String() string

func (Log_Level) Type

type Log_Redirct added in v0.0.86

type Log_Redirct int32
const (
	Log_stdout Log_Redirct = 0
	Log_file   Log_Redirct = 1
)

func (Log_Redirct) Descriptor added in v0.0.86

func (Log_Redirct) Enum added in v0.0.86

func (x Log_Redirct) Enum() *Log_Redirct

func (Log_Redirct) EnumDescriptor deprecated added in v0.0.86

func (Log_Redirct) EnumDescriptor() ([]byte, []int)

Deprecated: Use Log_Redirct.Descriptor instead.

func (Log_Redirct) Number added in v0.0.86

func (x Log_Redirct) Number() protoreflect.EnumNumber

func (Log_Redirct) String added in v0.0.86

func (x Log_Redirct) String() string

func (Log_Redirct) Type added in v0.0.86

type Rotate

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

func (*Rotate) ApplyOptions

func (o *Rotate) ApplyOptions(options ...RotateOption) *Rotate

type RotateOption

type RotateOption interface {
	// contains filtered or unexported methods
}

A RotateOption sets options.

func WithMaxAge

func WithMaxAge(maxAge time.Duration) RotateOption

func WithMaxCount

func WithMaxCount(maxCount int64) RotateOption

func WithPrefixName

func WithPrefixName(prefixName string) RotateOption

func WithRotateInterval

func WithRotateInterval(rotateInterval time.Duration) RotateOption

func WithRotateSize

func WithRotateSize(rotateSize int64) RotateOption

func WithSuffixName

func WithSuffixName(suffixName string) RotateOption

type RotateOptionFunc

type RotateOptionFunc func(*Rotate)

RotateOptionFunc wraps a function that modifies Client into an implementation of the RotateOption interface.

Directories

Path Synopsis
*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software.
*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software.

Jump to

Keyboard shortcuts

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