github.com/anakojm/hugo-katex@v0.0.0-20231023141351-42d6f5de9c0b/common/loggers/loggerglobal.go (about) 1 // Copyright 2023 The Hugo Authors. All rights reserved. 2 // Some functions in this file (see comments) is based on the Go source code, 3 // copyright The Go Authors and governed by a BSD-style license. 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 package loggers 17 18 import ( 19 "sync" 20 21 "github.com/bep/logg" 22 ) 23 24 func InitGlobalLogger(panicOnWarnings bool) { 25 logMu.Lock() 26 defer logMu.Unlock() 27 var logHookLast func(e *logg.Entry) error 28 if panicOnWarnings { 29 logHookLast = PanicOnWarningHook 30 } 31 32 log = New( 33 Options{ 34 Distinct: true, 35 HandlerPost: logHookLast, 36 }, 37 ) 38 } 39 40 var logMu sync.Mutex 41 42 func Log() Logger { 43 logMu.Lock() 44 defer logMu.Unlock() 45 return log 46 } 47 48 // The global logger. 49 var log Logger 50 51 func init() { 52 InitGlobalLogger(false) 53 }