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.
127 lines
3.3 KiB
127 lines
3.3 KiB
// ------------------------------------------------------------------------
|
|
// 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')
|
|
}
|
|
|
|
*/
|
|
|
|
} |