github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/service/logger/logger.go (about) 1 // Licensed under the Apache License, Version 2.0 (the "License"); 2 // you may not use this file except in compliance with the License. 3 // You may obtain a copy of the License at 4 // 5 // https://www.apache.org/licenses/LICENSE-2.0 6 // 7 // Unless required by applicable law or agreed to in writing, software 8 // distributed under the License is distributed on an "AS IS" BASIS, 9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 // See the License for the specific language governing permissions and 11 // limitations under the License. 12 // 13 // Original source: github.com/micro/go-micro/v3/logger/logger.go 14 15 // Package log provides a log interface 16 package logger 17 18 var ( 19 // Default logger 20 DefaultLogger Logger = NewHelper(NewLogger()) 21 ) 22 23 // Logger is a generic logging interface 24 type Logger interface { 25 // Init initialises options 26 Init(options ...Option) error 27 // The Logger options 28 Options() Options 29 // Fields set fields to always be logged 30 Fields(fields map[string]interface{}) Logger 31 // Log writes a log entry 32 Log(level Level, v ...interface{}) 33 // Logf writes a formatted log entry 34 Logf(level Level, format string, v ...interface{}) 35 // String returns the name of logger 36 String() string 37 } 38 39 func Init(opts ...Option) error { 40 return DefaultLogger.Init(opts...) 41 } 42 43 func Fields(fields map[string]interface{}) Logger { 44 return DefaultLogger.Fields(fields) 45 } 46 47 func Log(level Level, v ...interface{}) { 48 DefaultLogger.Log(level, v...) 49 } 50 51 func Logf(level Level, format string, v ...interface{}) { 52 DefaultLogger.Logf(level, format, v...) 53 } 54 55 func String() string { 56 return DefaultLogger.String() 57 }