Documentation
¶
Overview ¶
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.
Index ¶
- func CleanJSON(jsonStr string) string
- func ClearGlobalVars()
- func Debug(msg string, fields ...zap.Field)
- func Error(msg string, fields ...zap.Field)
- func ExtractField(jsonStr, fieldName string) (string, error)
- func ExtractYaml(message string) string
- func Fatal(msg string, fields ...zap.Field)
- func GetConfig() *viper.Viper
- func GetGlobalVar(key string) (interface{}, bool)
- func GetLogger() *zap.Logger
- func Info(msg string, fields ...zap.Field)
- func InitConfig() error
- func InitLogger(config *LogConfig) (*zap.Logger, error)
- func ParseJSON(jsonStr string) (map[string]interface{}, error)
- func RemoveGlobalVar(key string)
- func RenderMarkdown(md string) error
- func SetGlobalVar(key string, value interface{})
- func Sync() error
- func Warn(msg string, fields ...zap.Field)
- func With(fields ...zap.Field) *zap.Logger
- type LogConfig
- type PerfStats
- func (p *PerfStats) GetMetricStats(operation string) (min, max, avg, p95, p99 time.Duration, count int, total time.Duration)
- func (p *PerfStats) GetMetrics() map[string][]time.Duration
- func (p *PerfStats) GetStats() map[string]interface{}
- func (p *PerfStats) PrintStats() string
- func (p *PerfStats) RecordMetric(operation string, duration time.Duration)
- func (p *PerfStats) Reset()
- func (p *PerfStats) ResetMetrics()
- func (p *PerfStats) SetEnableLogging(enable bool)
- func (p *PerfStats) SetLogger(logger *zap.Logger)
- func (p *PerfStats) StartTimer(operation string)
- func (p *PerfStats) StopTimer(operation string) time.Duration
- func (p *PerfStats) TraceFunc(operation string) func()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanJSON ¶
CleanJSON 清理非标准JSON字符串,使其符合标准格式 参数:
- jsonStr: 可能包含非标准格式的JSON字符串
返回:
- string: 清理后的标准JSON字符串
func ExtractField ¶
ExtractField 从JSON字符串中提取特定字段 参数:
- jsonStr: JSON字符串
- fieldName: 要提取的字段名
返回:
- string: 提取的字段值
- error: 提取错误
func ExtractYaml ¶
ExtractYaml extracts yaml from a markdown message.
func ParseJSON ¶
ParseJSON 解析JSON字符串为map[string]interface{} 参数:
- jsonStr: JSON字符串
返回:
- map[string]interface{}: 解析后的对象
- error: 解析错误
func RenderMarkdown ¶
RenderMarkdown renders markdown to the terminal.
Types ¶
type LogConfig ¶
type LogConfig struct { // 日志级别 Level zapcore.Level // 日志目录 LogDir string // 日志文件名 Filename string // 单个日志文件最大大小,单位MB MaxSize int // 保留的旧日志文件最大数量 MaxBackups int // 保留的日志文件最大天数 MaxAge int // 是否压缩旧日志文件 Compress bool // 是否在控制台输出 ConsoleOutput bool // 是否使用彩色日志 ColoredOutput bool }
LogConfig 日志配置
type PerfStats ¶
type PerfStats struct {
// contains filtered or unexported fields
}
PerfStats 性能统计结构体 用于收集和分析系统各个部分的性能数据
func (*PerfStats) GetMetricStats ¶
func (p *PerfStats) GetMetricStats(operation string) (min, max, avg, p95, p99 time.Duration, count int, total time.Duration)
GetMetricStats 获取特定操作的统计信息 参数:
- operation: 操作名称
返回:
- min: 最小耗时
- max: 最大耗时
- avg: 平均耗时
- p95: 95百分位耗时
- p99: 99百分位耗时
- count: 操作次数
- total: 总耗时