github.com/greenpau/go-authcrunch@v1.1.4/pkg/util/log/utils.go (about)

     1  // Copyright 2022 Paul Greenberg greenpau@outlook.com
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package log
    16  
    17  import (
    18  	"go.uber.org/zap"
    19  	"go.uber.org/zap/zapcore"
    20  	"os"
    21  )
    22  
    23  // NewLogger returns an instance of logger.
    24  func NewLogger() *zap.Logger {
    25  	logAtom := zap.NewAtomicLevel()
    26  	logAtom.SetLevel(zapcore.DebugLevel)
    27  	logEncoderConfig := zap.NewProductionEncoderConfig()
    28  	logEncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
    29  	logEncoderConfig.TimeKey = "time"
    30  	logger := zap.New(zapcore.NewCore(
    31  		zapcore.NewJSONEncoder(logEncoderConfig),
    32  		zapcore.Lock(os.Stdout),
    33  		logAtom,
    34  	))
    35  	return logger
    36  }
    37  
    38  // NewInfoLogger returns an instance of info-level logger.
    39  func NewInfoLogger() *zap.Logger {
    40  	logAtom := zap.NewAtomicLevel()
    41  	logAtom.SetLevel(zapcore.InfoLevel)
    42  	logEncoderConfig := zap.NewProductionEncoderConfig()
    43  	logEncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
    44  	logEncoderConfig.TimeKey = "time"
    45  	logger := zap.New(zapcore.NewCore(
    46  		zapcore.NewJSONEncoder(logEncoderConfig),
    47  		zapcore.Lock(os.Stdout),
    48  		logAtom,
    49  	))
    50  	return logger
    51  }