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/entry_filter.go

105 lines
2.3 KiB

// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name entry_filter.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 alogs
import (
"bins/tokens"
"strings"
)
type (
EntryFilter struct {
name string
active bool
filterFnc EntryFilterFnc
}
EntryFilterFnc func (entry *Entry) bool
)
func NewEntryFilter(name string, fnc EntryFilterFnc) *EntryFilter {
if fnc == nil {
fnc = NopFilterTrue
}
return &EntryFilter{
name : name,
active : true,
filterFnc : fnc,
}
}
func NewFilterLevel (name string, level Level) *EntryFilter {
if len(name) == 0 {
name = filterLevelName
}
l := level
return &EntryFilter{
name : name,
active : true,
filterFnc: func(e *Entry) bool {
return l.Has(e.Level)
},
}
}
func NewFilterScope (name string, topic string) *EntryFilter {
if len(name) == 0 {
name = filterScopeName
}
tp := *g.tokenizer.NewTopic([]byte(strings.ToLower(topic)),tokens.TokenKindAll)
return &EntryFilter{
name : name,
active : true,
filterFnc: func(e *Entry) bool {
return tp.Match(e.Scopes)
},
}
}
func (f *EntryFilter) Name () string {
return f.name }
func (f *EntryFilter) IsActive () bool {
return f.active }
func (f *EntryFilter) SetActive (enable bool) {
f.active = enable }
func (f *EntryFilter) Filter (entry *Entry) bool {
return f.filterFnc(entry) }
func NopFilterTrue (_ *Entry) bool {
return true }
func NopFilterFalse(_ *Entry) bool {
return false }

Powered by TurnKey Linux.