github.com/zntrio/harp/v2@v2.0.9/pkg/sdk/log/logger.go (about) 1 // Licensed to Elasticsearch B.V. under one or more contributor 2 // license agreements. See the NOTICE file distributed with 3 // this work for additional information regarding copyright 4 // ownership. Elasticsearch B.V. licenses this file to you under 5 // the Apache License, Version 2.0 (the "License"); you may 6 // not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, 12 // software distributed under the License is distributed on an 13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 // KIND, either express or implied. See the License for the 15 // specific language governing permissions and limitations 16 // under the License. 17 18 package log 19 20 import ( 21 "go.uber.org/zap" 22 "go.uber.org/zap/zapcore" 23 ) 24 25 // logger delegates all calls to the underlying zap.Logger. 26 type logger struct { 27 logger *zap.Logger 28 } 29 30 // Debug logs an debug msg with fields. 31 func (l logger) Debug(msg string, fields ...zapcore.Field) { 32 l.logger.Debug(msg, fields...) 33 } 34 35 // Info logs an info msg with fields. 36 func (l logger) Info(msg string, fields ...zapcore.Field) { 37 l.logger.Info(msg, fields...) 38 } 39 40 // Error logs an error msg with fields. 41 func (l logger) Error(msg string, fields ...zapcore.Field) { 42 l.logger.Error(msg, fields...) 43 } 44 45 // Warn logs a warning with fields. 46 func (l logger) Warn(msg string, fields ...zapcore.Field) { 47 l.logger.Warn(msg, fields...) 48 } 49 50 // Fatal logs a fatal error msg with fields. 51 func (l logger) Fatal(msg string, fields ...zapcore.Field) { 52 l.logger.Fatal(msg, fields...) 53 } 54 55 // With creates a child logger, and optionally adds some context fields to that logger. 56 func (l logger) With(fields ...zapcore.Field) Logger { 57 return &logger{logger: l.logger.With(fields...)} 58 }