packs2
DEV 3 years ago
parent 88226e0679
commit 5701f591c4

@ -0,0 +1,41 @@
// ------------------------------------------------------------------------
// Project atila
// Active Thing (activething.com) git.activething.com/go
//
// File name field.go
// Created by DEV
// Modified 03/03/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 values
type (
Field interface {
Namer
Valuer
}
)
func NewField (name string, value any) (Field,error) {
switch value.(type) {
}
}

@ -0,0 +1,56 @@
// ------------------------------------------------------------------------
// Project atila
// Active Thing (activething.com) git.activething.com/go
//
// File name field_string.go
// Created by DEV
// Modified 03/03/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 values
type (
FieldString struct {
n string
v string
}
)
func NewFieldString (name string, value string) *FieldString {
return &FieldString {
n : name,
v: value,
}
}
func (f FieldString) Name () string {
return f.n }
func (f FieldString) Value() string {
return f.v }
func (_ FieldString) FieldType () FieldType {
}

@ -0,0 +1,45 @@
// ------------------------------------------------------------------------
// Project atila
// Active Thing (activething.com) git.activething.com/go
//
// File name field_type.go
// Created by DEV
// Modified 03/03/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 values
const (
FieldTypeUnknown FieldType = iota
FieldTypeString
FieldTypeInt8
FieldTypeInt16
FieldTypeInt32
FieldTypeInt64
FieldTypeUInt8
FieldTypeUInt16
FieldTypeUInt32
FieldTypeUInt64
FieldTypeFloat32
FieldTypeFloat64
)
type FieldType uint8

@ -0,0 +1,43 @@
// ------------------------------------------------------------------------
// Project atila
// Active Thing (activething.com) git.activething.com/go
//
// File name namer.go
// Created by DEV
// Modified 03/03/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 values
type (
Namer interface {
Name () string
}
NameFnc func () string
)
func (f NameFnc) Name () string {
return f() }

@ -0,0 +1,43 @@
// ------------------------------------------------------------------------
// Project atila
// Active Thing (activething.com) git.activething.com/go
//
// File name valueSetter.go
// Created by DEV
// Modified 03/03/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 values
type (
ValueSetter interface {
SetValue (value any) error
}
SetValueFnc func (value any) error
)
func (f SetValueFnc) SetValue (value any) error {
return f(value) }

@ -34,7 +34,7 @@ type (
Entry struct {
logger Logger
Logger Logger
Id uint64
Scope string
@ -68,7 +68,7 @@ func NewEntry (logger Logger, level Level, message string, err error, options ..
func (e *Entry) init (logger Logger, level Level, message string, err error) *Entry {
e.logger = logger
e.Logger = logger
e.Level = level
e.Message = message
e.Err = err
@ -77,7 +77,7 @@ func (e *Entry) init (logger Logger, level Level, message string, err error) *En
func (e *Entry) reset ()*Entry {
e.logger = nil
e.Logger = nil
e.Stack = nil
e.Data = nil
e.Message = ""
@ -96,7 +96,7 @@ func (e *Entry) Clone () *Entry {
c.Message = e.Message
c.Level = e.Level
c.Err = e.Err
c.logger = e.logger
c.Logger = e.Logger
c.Scope = e.Scope
c.Scopes = append(c.Scopes[:0],e.Scopes...)
c.excludes = append(c.excludes[:0],e.excludes ...)

@ -0,0 +1,127 @@
// ------------------------------------------------------------------------
// Project atila
// Active Thing (activething.com) git.activething.com/go
//
// File name entry_fortmats.go
// Created by DEV
// Modified 23/02/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 (
"activething.com/go/gogo/core/bins"
"activething.com/go/gogo/core/times"
)
type (
EntryFormatter interface {
FormatEntry (buffer *bins.Buffer, entry *Entry)
}
FormatEntryFnc func(buffer *bins.Buffer, entry *Entry)
)
func (f FormatEntryFnc) FormatEntry (buffer *bins.Buffer, entry *Entry) {
f(buffer,entry) }
func EntryFormatTextShort(buffer *bins.Buffer, entry *Entry){
buffer.WriteString(entry.Level.String())
buffer.WriteByte(' ')
buffer.WriteString(entry.Logger.Name())
buffer.WriteByte(' ')
buffer.AppendWith(bins.AppendFnc(func (d []byte) []byte { return times.TimeANSIC(entry.Date,d) }))
buffer.WriteByte(' ')
buffer.WriteString(entry.Message)
if entry.Err != nil {
buffer.WriteString(" Error: ")
buffer.WriteString(entry.Err.Error())
}
buffer.WriteByte('\n')
}
func EntryFormatTextLong(buffer *bins.Buffer, entry *Entry) {
buffer.WriteString(entry.Level.String())
buffer.Write2Byte(' ','(')
buffer.WriteUint64(entry.Id,nil)
buffer.Write2Byte(')',' ')
buffer.Write2Byte('>',' ')
buffer.WriteString(entry.Logger.Name())
buffer.Write2Byte(':',' ')
buffer.WriteString(entry.Message)
buffer.WriteByte('\n')
buffer.WriteString("\tDate: ")
buffer.AppendWith(bins.AppendFnc(func (d []byte) []byte { return times.TimeANSIC(entry.Date,d) }))
buffer.WriteByte('\n')
if entry.Err != nil {
buffer.WriteString("\tError: ")
buffer.WriteString(entry.Err.Error())
buffer.WriteByte('\n')
}
if entry.Scope != "" {
buffer.WriteString("\tScope: ")
buffer.WriteString(entry.Scope)
buffer.WriteByte('\n')
}
/*
if len(entry.Fields) > 0 {
buffer.WriteString("\tFields\n")
for _, f := range entry.Fields {
buffer.Write2Byte('\t','\t')
buffer.WriteString(f.Name())
buffer.Write2Byte(':', ' ')
buffer.WriteString(fmt.Sprintf("%v", f.Value()))
buffer.WriteByte('\n')
}
}
if len(entry.Stack) > 0 {
buffer.WriteString("\tCaller\n")
buffer.WriteString("\t\tName: ")
buffer.WriteString(entry.Stack[0].Name())
buffer.WriteString("\n\t\tLine: ")
buffer.WriteInt(entry.Frame.Line())
buffer.WriteString("\n\t\tFile: ")
buffer.WriteString(entry.Frame.File())
buffer.WriteString("\n\t\tPackage: ")
buffer.WriteString(entry.Frame.Package())
if sc,er := entry.Frame.SourceLine(); er == nil {
buffer.WriteString("\n\t\tSource : ")
buffer.WriteString(sc)
}
buffer.WriteByte('\n')
}
*/
}

@ -0,0 +1,39 @@
// ------------------------------------------------------------------------
// Project atila
// Active Thing (activething.com) git.activething.com/go
//
// File name entry_logger.go
// Created by DEV
// Modified 03/03/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
type (
EntryLogger interface {
Log (entry *Entry) error
}
LogEntry func (entry *Entry) error
)

@ -27,58 +27,78 @@ import "activething.com/go/gogo/sapis/tokens"
type (
Filter struct {
Filter interface {
Name () string
Active() bool
Denied() bool
Apply (e *Entry) bool
}
filter struct {
name string
active bool
applyFn FilterFnc
denied bool
applyFn FilterApplyFnc
}
FilterFnc func (*Entry) bool
FilterApplyFnc func (*Entry) bool
)
func NewFilter (name string, filterFn FilterFnc) *Filter {
func NewFilter (name string, denied bool, filterFn FilterApplyFnc) *filter {
if filterFn == nil {
filterFn = filterAlwaysTrue
}
return &Filter{
return &filter{
name : name,
active : true,
denied : denied,
applyFn : filterFn,
}
}
func NewFilterLevel (level Level) *Filter {
func NewFilterLevel (level Level, deny bool) *filter {
l := level
return NewFilter(level.String(),func(e *Entry) bool {
return e.Level.Has(l) })
return NewFilter(level.String(),deny,func(e *Entry) bool {
return e.Level.Has(l) })
}
func NewFilterScope (scope string) *Filter {
func NewFilterScope (scope string, deny bool) *filter {
tk := tokens.NewTopic(G.tokenizer,[]byte(scope),tokens.TokenKindAll)
if tk.Kind().HasInvalid() {
return nil
}
return NewFilter(scope,func(e *Entry) bool {
return NewFilter(scope,deny,func(e *Entry) bool {
return tk.Match(e.Scopes) })
}
func (f Filter) Name () string {
func (f filter) Name () string {
return f.name }
func (f Filter) Active () bool {
func (f filter) Active () bool {
return f.active }
func (f Filter) SetActive (active bool) {
func (f filter) SetActive (active bool) {
f.active = active }
func (f Filter) Apply (e *Entry) bool {
return f.applyFn(e) }
func (f filter) Denied () bool {
return f.denied }
func (f filter) Apply (e *Entry) bool {
if !f.denied {
return f.applyFn(e)
}
return !f.applyFn(e)
}

@ -32,8 +32,7 @@ type (
Filters struct {
mux sync.RWMutex
allows []Filter
denies []Filter
filters []Filter
}
)
@ -43,20 +42,50 @@ func NewFilters (options ...opts.OptionFnc[Filters]) *Filters {
return opts.Apply[Filters](&Filters{}, options ...) }
func (f *Filters) RegAllowed (filter Filter) {
f.allows = append(f.allows,filter) }
func (f *Filters) RegDenied (filter Filter) {
f.denies = append(f.denies,filter) }
func (f *Filters) RegNewAllowed (name string, applyFn FilterFnc) {
f.allows = append(f.allows,*NewFilter(name, applyFn)) }
func (f *Filters) Apply (entry *Entry) bool {
f.mux.RLock()
for _,a := range f.filters {
if a.Active() {
if a.Apply(entry) {
f.mux.RUnlock()
return false
}
}
}
f.mux.RUnlock()
return true
}
func (f *Filters) RegNewDenied (name string, applyFn FilterFnc) {
f.denies = append(f.denies,*NewFilter(name, applyFn)) }
func (f *Filters) Reg (filter Filter) {
f.mux.Lock()
if x := findFilter(f.filters,filter.Name()); x != -1 {
f.filters[x]=filter
} else {
f.filters = append(f.filters,filter)
}
f.mux.Unlock()
return
}
func (f *Filters) RegNew (name string, denied bool, filterFn FilterApplyFnc) {
f.Reg(NewFilter(name,denied,filterFn)) }
func (f *Filters) Del (name string) {
f.mux.Lock()
if x := findFilter(f.filters, name); x != -1 {
f.filters = append(f.filters[:x], f.filters[x+1:]...)
}
f.mux.Unlock()
}
func findFilter (filters []Filter, name string) int {
for i,f := range filters {
if f.Name() == name {
return i
}
}
return -1
}

@ -53,9 +53,9 @@ var (
}{
ErrDuplicatedScope : errs.ErrCode ("logs:duplicated-scope"),
ErrDuplicatedLogger: errs.ErrCode ("logs:duplicated-logger"),
ErrDuplicatedLogger: errs.ErrCode ("logs:duplicated-Logger"),
ErrInvalidScope : errs.ErrCode ("logs:invalid-scope"),
ErrNotExistsLogger : errs.ErrCode ("logs:not-exists-logger"),
ErrNotExistsLogger : errs.ErrCode ("logs:not-exists-Logger"),
entryPool: syncs.NewPool[Entry](

@ -2,7 +2,7 @@
// Project atila
// Active Thing (activething.com) git.activething.com/go
//
// File name logger.go
// File name Logger.go
// Created by DEV
// Modified 22/02/2024
//

@ -0,0 +1,33 @@
// ------------------------------------------------------------------------
// Project atila
// Active Thing (activething.com) git.activething.com/go
//
// File name logger_core.go
// Created by DEV
// Modified 03/03/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
type (
LoggerCore struct {
}
)

@ -31,7 +31,6 @@ type (
mux sync.RWMutex
name string
level Level
logFnc func (level Level, message string, err error, options ...*EntryFnc)
}
)

@ -0,0 +1,64 @@
// ------------------------------------------------------------------------
// Project atila
// Active Thing (activething.com) git.activething.com/go
//
// File name queue.go
// Created by DEV
// Modified 23/02/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
type (
entryQueue []*Entry
)
func (q entryQueue) Len() int {
return len(q) }
func (q *entryQueue) PushNew (logger Logger, level Level, message string, err error, options ...EntryFnc){
*q = append(*q,NewEntry(logger, level, message,err,options ...)) }
func (q *entryQueue) Push(ent *Entry){
*q = append(*q,ent) }
func (q *entryQueue) Pop () *Entry {
if len(*q) == 0 {
return nil
}
en := (*q)[0]
*q = (*q)[1:]
return en
}
func (q *entryQueue) Clear(){
for en := q.Pop(); en != nil; {
G.entryPool.Put(en)
}
}
Loading…
Cancel
Save

Powered by TurnKey Linux.