Documentation
¶
Overview ¶
Copyright © 2020 Xin Chen <devops.chen@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2020 Xin Chen <devops.chen@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitLogger ¶
InitLogger initialize the zap global logger with log options and return an function undo the changes of the zap global logger, which should be call before the whole program exits. Supported levels include debug, info, warn, error, panic. The return config is in purpose of test, it should be removed until a better way to test is found
func PrintAvailLogLevel ¶
func PrintAvailLogLevel() string
PrintAvailLogLevel returns a string listing all supported log level seperated by comma, e.g. "debug, info, warn, ..."
Types ¶
type LogOption ¶
type LogOption interface {
// Type get the type of this option
OptType() LogOptionType
// ConfigLogger configure the logger according to this option
ConfigLogger(LogOptionType, *zap.Config) error
}
LogOption is used to configure global logger behaviors
func NewEnableLogFileOption ¶
NewEnableLogFileOption returns an enableLogFileOption which enables local log file if file path is specified
func NewLogFilePathOption ¶
NewLogFilePathOption returns an logFilePathOption which enables local log file and configures the file path
func NewLogLevelOption ¶
NewLogLevelOption returns a logLevelOption with specified log level and an error if exists
type LogOptionType ¶
type LogOptionType uint16
LogOptionType indicates configurable log options
const ( // LogLevelOpt is used to configure global log level LogLevelOpt LogOptionType = 1 << iota // EnableLogFileOpt is used to enable local log file. // Local log file is enabled only if // both EnableLogFileOpt and LogFilePathOpt exist. // Value of EnableLogFileOpt is ignored. // Note that currently no internal rotation supported EnableLogFileOpt // LogFilePathOpt is used to configure // the path for local log file LogFilePathOpt )
type StructuredLogger ¶
type StructuredLogger interface {
Sync() error
Info(string, ...map[string]string)
Warn(string, ...map[string]string)
Error(string, ...error)
Debug(string, ...map[string]string)
Panic(string, ...error)
}
StructuredLogger is an interface wraps the zap logger
func GetGlobalStructuredLogger ¶
func GetGlobalStructuredLogger() StructuredLogger
GetGlobalStructuredLogger returns a wrapped global zap logger
type SugaredLogger ¶
type SugaredLogger interface {
Sync() error
Info(...interface{})
Warn(...interface{})
Error(...interface{})
Debug(...interface{})
Panic(...interface{})
Infof(string, ...interface{})
Warnf(string, ...interface{})
Errorf(string, ...interface{})
Debugf(string, ...interface{})
Panicf(string, ...interface{})
UnwrappedStackErrorf(error, string, ...interface{})
}
SugaredLogger is an interface wraps the zap sugared logger
func GetGlobalLogger ¶
func GetGlobalLogger() SugaredLogger
GetGlobalLogger returns a wrapped global zap sugared logger