You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.1 KiB
94 lines
2.1 KiB
// ------------------------------------------------------------------------
|
|
// Project active2
|
|
// Active Thing (activething.com) git.activething.com/go
|
|
//
|
|
// File name logger_level.go
|
|
// Created by DEV
|
|
// Modified 24/04/2024
|
|
//
|
|
// Copyright 2024 activething.com
|
|
// ------------------------------------------------------------------------
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
// ------------------------------------------------------------------------
|
|
|
|
package logs
|
|
|
|
import "sync"
|
|
|
|
type (
|
|
|
|
|
|
loggerLevel struct {
|
|
mux sync.RWMutex
|
|
name string
|
|
level Level
|
|
logFn LogFnc
|
|
}
|
|
|
|
)
|
|
|
|
|
|
func newLoggerLevel (name string, level Level) *loggerLevel {
|
|
return &loggerLevel{
|
|
name : name,
|
|
level: level } }
|
|
|
|
|
|
func (l *loggerLevel) Name () string {
|
|
return l.name }
|
|
|
|
func (l *loggerLevel) Level() (lv Level) {
|
|
l.mux.RLock()
|
|
lv = l.level
|
|
l.mux.RUnlock()
|
|
return
|
|
}
|
|
|
|
func (l *loggerLevel) SetLevel (level Level) {
|
|
l.mux.Lock()
|
|
l.level = level
|
|
l.mux.Unlock()
|
|
}
|
|
|
|
|
|
|
|
func (l *loggerLevel) Fatal (msg string, err error, ops ...EntryFnc){
|
|
l.logFn(LevelFatal,msg,err,ops ...) }
|
|
|
|
|
|
func (l *loggerLevel) Error (msg string, err error, ops ...EntryFnc){
|
|
l.logFn(LevelError,msg,err,ops ...) }
|
|
|
|
|
|
func (l *loggerLevel) Warn (msg string, ops ...EntryFnc){
|
|
l.logFn(LevelWarn,msg,nil,ops ...) }
|
|
|
|
|
|
func (l *loggerLevel) Info (msg string, ops ...EntryFnc){
|
|
l.logFn(LevelInfo,msg,nil,ops...) }
|
|
|
|
|
|
func (l *loggerLevel) Debug (msg string, ops ...EntryFnc){
|
|
l.logFn(LevelDebug,msg,nil,ops...) }
|
|
|
|
|
|
func (l *loggerLevel) Data (msg string, data any, ops ...EntryFnc){
|
|
l.logFn(LevelData,msg,nil,func (e *Entry) {
|
|
e.Data = data
|
|
for _,o := range ops {
|
|
o(e)
|
|
}
|
|
}) }
|
|
|
|
|