Copyright @ 2021 bocloud <fushaosong@beyondcent.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.
Original file: https://gitee.com/bocloud-open-source/carina/blob/v0.9.1/utils/log/logger.go
*/
package log
import (
"fmt"
"os"
"gopkg.openfuyao.cn/common-modules/ologger/log"
)
const (
defaultLogPath = "/var/log/openFuyao/bke.log"
)
var logger *log.Logger
func init() {
logger = log.NewLogger(bkeLoggerConfig()).WithCallerSkip(1)
}
func bkeLoggerConfig() log.Config {
enableFile := true
enableConsole := true
enableSanitize := true
compress := true
watchLevel := false
return log.Config{
Path: defaultLogPath,
Level: log.INFO,
Format: "json",
EnableFile: &enableFile,
EnableConsole: &enableConsole,
EnableSanitize: &enableSanitize,
Compress: &compress,
WatchLevel: &watchLevel,
}
}
func Debug(args ...any) {
logger.Debug(fmt.Sprint(args...))
}
func Debugf(template string, args ...any) {
logger.Debugf(template, args...)
}
func Info(args ...any) {
logger.Info(fmt.Sprint(args...))
}
func Infof(template string, args ...any) {
logger.Infof(template, args...)
}
func Warn(args ...any) {
logger.Warn(fmt.Sprint(args...))
}
func Warnf(template string, args ...any) {
logger.Warnf(template, args...)
}
func Error(args ...any) {
logger.Error(fmt.Sprint(args...))
}
func Errorf(template string, args ...any) {
logger.Errorf(template, args...)
}
func Trace(args ...any) {
logger.Trace(fmt.Sprint(args...))
}
func Tracef(template string, args ...any) {
logger.Tracef(template, args...)
}
func Fatal(args ...any) {
msg := fmt.Sprint(args...)
logger.Critical(msg)
os.Exit(1)
}
func Fatalf(template string, args ...any) {
logger.Criticalf(template, args...)
os.Exit(1)
}
func SteppedInfo(stepName string, args ...any) {
logger.Info(fmt.Sprintf("[%s] %s", stepName, fmt.Sprint(args...)))
}
func SteppedInfof(stepName, template string, args ...any) {
logger.Infof("[%s] "+template, append([]any{stepName}, args...)...)
}