github.com/e154/smart-home@v0.17.2-0.20240311175135-e530a6e5cd45/common/logger/logger.go (about) 1 // This file is part of the Smart Home 2 // Program complex distribution https://github.com/e154/smart-home 3 // Copyright (C) 2016-2023, Filippov Alex 4 // 5 // This library is free software: you can redistribute it and/or 6 // modify it under the terms of the GNU Lesser General Public 7 // License as published by the Free Software Foundation; either 8 // version 3 of the License, or (at your option) any later version. 9 // 10 // This library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 // Library General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public 16 // License along with this library. If not, see 17 // <https://www.gnu.org/licenses/>. 18 19 package logger 20 21 import ( 22 "go.uber.org/zap" 23 ) 24 25 // Logger ... 26 type Logger struct { 27 p string 28 } 29 30 // MustGetLogger ... 31 func MustGetLogger(p string) *Logger { 32 return &Logger{ 33 p: p, 34 } 35 } 36 37 // Error ... 38 func (l *Logger) Error(format string, args ...interface{}) { 39 v := []interface{}{format} 40 v = append(v, args...) 41 zap.L().Named(l.p).Sugar().Error(v...) 42 } 43 44 // Errorf ... 45 func (l *Logger) Errorf(format string, args ...interface{}) { 46 zap.L().Named(l.p).Sugar().Errorf(format, args...) 47 } 48 49 // Warn ... 50 func (l *Logger) Warn(format string, args ...interface{}) { 51 v := []interface{}{format} 52 v = append(v, args...) 53 zap.L().Named(l.p).Sugar().Warn(v...) 54 } 55 56 // Warnf ... 57 func (l *Logger) Warnf(format string, args ...interface{}) { 58 zap.L().Named(l.p).Sugar().Warnf(format, args...) 59 } 60 61 // Info ... 62 func (l *Logger) Info(format string, args ...interface{}) { 63 v := []interface{}{format} 64 v = append(v, args...) 65 zap.L().Named(l.p).Sugar().Info(v...) 66 } 67 68 // Infof ... 69 func (l *Logger) Infof(format string, args ...interface{}) { 70 zap.L().Named(l.p).Sugar().Infof(format, args...) 71 } 72 73 // Debug ... 74 func (l *Logger) Debug(format string, args ...interface{}) { 75 v := []interface{}{format} 76 v = append(v, args...) 77 zap.L().Named(l.p).Sugar().Debug(v...) 78 } 79 80 // Debugf ... 81 func (l *Logger) Debugf(format string, args ...interface{}) { 82 zap.L().Named(l.p).Sugar().Debugf(format, args...) 83 } 84 85 // Fatal ... 86 func (l *Logger) Fatal(format string, args ...interface{}) { 87 v := []interface{}{format} 88 v = append(v, args...) 89 zap.L().Named(l.p).Sugar().Fatal(v...) 90 } 91 92 // Fatalf ... 93 func (l *Logger) Fatalf(format string, args ...interface{}) { 94 zap.L().Named(l.p).Sugar().Fatalf(format, args...) 95 } 96 97 // Fatalf ... 98 func (l *Logger) Loggert() *zap.Logger { 99 return zap.L().Named(l.p) 100 }