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.
active/alogs/logger_object.go

151 lines
3.3 KiB

// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name logger_com.go
// Created by DEV
// Modified 29/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 alogs
import (
"errs"
"sync"
"sync/atomic"
)
type (
loggerObject struct {
sync.RWMutex
extenders EntryExtenders
name string
level Level
state State
count int64
logFn loggerLogFnc
errors errs.ErrorList
}
loggerLogFnc func (level Level, msg string, err error, options []EntryFnc)
)
func newLoggerObject(name string, level Level, logFn loggerLogFnc) *loggerObject {
if logFn == nil {
logFn = nopLog
}
l := &loggerObject {
name : name,
level : level,
state : StateCreated,
logFn : logFn,
}
return l
}
func (l *loggerObject) Name () string {
return l.name }
func (l *loggerObject) State() (st State) {
l.RLock()
st = l.state
l.RUnlock()
return
}
func (l *loggerObject) Level() (lv Level) {
l.RLock()
lv = l.level
l.RUnlock()
return
}
func (l *loggerObject) SetLevel (level Level) {
l.Lock()
l.level = level
l.Unlock()
}
func (l *loggerObject) Count () int64 {
return atomic.LoadInt64(&l.count) }
func (l *loggerObject) incCount () {
atomic.AddInt64(&l.count,1) }
func (l *loggerObject) Errors () []error {
l.RLock()
ls := l.errors
l.RUnlock()
return ls
}
func (l *loggerObject) ClearErrors () {
l.Lock()
l.errors = l.errors[:0]
l.Unlock()
}
// Start Debe de implementarse para que cumpla con el interface Logger
func (_ *loggerObject)Start () error { return nil }
// Stop Debe de implementarse para que cumpla con el interface Logger
func (_ *loggerObject)Stop () error { return nil }
// Flush Debe de implementarse para que cumpla con el interface Logger
func (_ *loggerObject)Flush () error { return nil }
func (l *loggerObject) Fatal(msg string, err error, ops ...EntryFnc){
l.logFn(LevelFatal,msg,err,ops) }
func (l *loggerObject) Error(msg string, err error, ops ...EntryFnc){
l.logFn(LevelError,msg,err,ops) }
func (l *loggerObject) Warn (msg string, ops ...EntryFnc){
l.logFn(LevelWarn,msg,nil,ops) }
func (l *loggerObject) Info (msg string, ops ...EntryFnc){
l.logFn(LevelInfo,msg,nil,ops) }
func (l *loggerObject) Debug(msg string, ops ...EntryFnc){
l.logFn(LevelDebug,msg,nil,ops) }
func (l *loggerObject) Data (msg string, data any, ops ...EntryFnc){
l.logFn(LevelData,msg,nil,[]EntryFnc{EntryWithData(data,ops ...)}) }
func nopLog (_ Level, _ string, _ error, _ []EntryFnc) {}
func nopOnEvent(_ *LoggerCore) error { return nil }

Powered by TurnKey Linux.