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.
101 lines
2.5 KiB
101 lines
2.5 KiB
// ------------------------------------------------------------------------
|
|
// Project active2
|
|
// Active Thing (activething.com) git.activething.com/go
|
|
//
|
|
// File name active.go
|
|
// Created by DEV
|
|
// Modified 04/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 ftext
|
|
|
|
import (
|
|
"atypes/astrings"
|
|
"errs/fmts"
|
|
"errs/stack"
|
|
"sync"
|
|
)
|
|
|
|
const (
|
|
|
|
DefaultSection int = iota
|
|
ErrorSection
|
|
FieldsSection
|
|
CauseSection
|
|
TraceSection
|
|
|
|
secsSize= 4
|
|
)
|
|
|
|
const (
|
|
|
|
stringsTrans int = iota
|
|
samesTrans
|
|
valuesTrans
|
|
|
|
transSize int = 3
|
|
)
|
|
|
|
|
|
var (
|
|
|
|
G = struct {
|
|
buildDefault sync.Once
|
|
fmtDefault *FmtText
|
|
}{
|
|
}
|
|
|
|
)
|
|
|
|
|
|
func DefaultFormatter () *FmtText {
|
|
G.buildDefault.Do(func() {
|
|
G.fmtDefault = NewFmtText(
|
|
func(f *FmtText) {
|
|
f.FixFieldLen = 13
|
|
},
|
|
WithFieldFormat("*",FieldFormat{
|
|
nameTrans: []astrings.Transform{ astrings.ToKebab },
|
|
}),
|
|
WithFieldFormat("error",FieldFormat{
|
|
nameColor: ColorGreen ,
|
|
}),
|
|
WithErrorSection(
|
|
[]string{ColorRed.StringColor("**********************************************************")},
|
|
[]string{"**********************************************************"}, ColorMagenta),
|
|
WithCauseSection(
|
|
[]string{"- Prev Cause ---------------"},
|
|
[]string(nil), ColorBlue),
|
|
WithTraceSection(
|
|
[]string{"\n* Stack Trace Information **"},
|
|
[]string(nil), ColorMagenta))
|
|
})
|
|
return G.fmtDefault
|
|
}
|
|
|
|
|
|
func defaultFrameBuilder (builder fmts.FormatBuilder, frame stack.Frame, num int) {
|
|
builder.AddString(ColorBlue.SprintfColor("%d %s.%s",num,frame.Package,frame.FuncName))
|
|
builder.AddString(ColorMagenta.SprintfColor(" %.90s:%d",frame.File,frame.LineNumber))
|
|
f,e:= frame.SourceLine()
|
|
if e == nil {
|
|
builder.AddString(ColorYellow.SprintfColor("%s",f))
|
|
|
|
} else {
|
|
builder.AddString(ColorRed.SprintfColor("error %s", e.Error()))
|
|
}
|
|
} |