fix: rebuild MES as compilable go-zero+ent backend (renamed bj_power_mes), restore 3 workstation projects from pristine original, align naming; all Go projects go build clean

This commit is contained in:
SunYF
2026-08-27 10:56:41 +08:00
parent 380715f8a9
commit 371b494c54
523 changed files with 67923 additions and 24758 deletions
+10 -85
View File
@@ -10,7 +10,6 @@ import (
"path/filepath"
"runtime"
"strings"
"sync"
"time"
"github.com/zeromicro/go-zero/core/logx"
@@ -47,11 +46,16 @@ func NewLogger(conf LogConf) *Logger {
conf.Filename = filepath.Join(workdir, conf.Filename)
}
// 匧予𠧧嚗𡁏憭拐銝芣隞塚 bj_power_mes-YYYY-MM-DD.log
// 瘥誩予?lumberjack 匧之撠𧶏MaxSize嚗㗇靽萘 MaxBackups 銝芸隞?
dw := newDailyWriter(conf)
// 创建lumberjack日志滚动器
lumberjackLogger := &lumberjack.Logger{
Filename: conf.Filename,
MaxSize: conf.MaxSize,
MaxBackups: conf.MaxBackups,
MaxAge: conf.MaxAge,
Compress: conf.Compress,
} // 创建写入器
var writer io.Writer = dw
var writer io.Writer = lumberjackLogger
if conf.Console {
writer = io.MultiWriter(writer, os.Stdout)
}
@@ -67,7 +71,7 @@ func NewLogger(conf LogConf) *Logger {
if source.File == "" {
return slog.Attr{}
}
return slog.String(slog.SourceKey, " "+filepath.Base(source.File)+fmt.Sprintf(":%d", source.Line))
return slog.String(slog.SourceKey, filepath.Base(source.File)+fmt.Sprintf(":%d", source.Line))
}
case slog.TimeKey:
return slog.String(slog.TimeKey, attr.Value.Time().Format(conf.TimeFormat))
@@ -168,29 +172,7 @@ func (l *Logger) Error(v any, fields ...logx.LogField) {
l.logAttrs(context.Background(), slog.LevelError, fmt.Sprintf("%v", v), attrs...)
}
// skipHttpPollLog 餈誘擃㗛頧株砭嚗𡁜蝡航蔭霂X𦻖𣂼 GET嚗㗇蝘埝㺭甈∪撅𧶏
// 靝遠潛凒乩腺撘雿頣POST/PUT/DELETE嚗劐?2xx 躰秤靽萘?
func skipHttpPollLog(v any) bool {
msg, ok := v.(string)
if !ok || !strings.HasPrefix(msg, "[HTTP]") {
return false
}
// : [HTTP] 200 - GET /api/v1/jobs - 127.0.0.1:49864 - UA
parts := strings.SplitN(msg, " - ", 3)
if len(parts) < 3 {
return false
}
code := strings.TrimSpace(strings.TrimPrefix(parts[0], "[HTTP]"))
if len(code) < 1 || code[0] != '2' {
return false
}
return strings.HasPrefix(parts[1], "GET ")
}
func (l *Logger) Info(v any, fields ...logx.LogField) {
if skipHttpPollLog(v) {
return
}
attrs := l.buildAttrs(fields)
l.logAttrs(context.Background(), slog.LevelInfo, fmt.Sprintf("%v", v), attrs...)
}
@@ -200,9 +182,6 @@ func (l *Logger) Severe(v any) {
}
func (l *Logger) Slow(v any, fields ...logx.LogField) {
if skipHttpPollLog(v) {
return
}
attrs := l.buildAttrs(fields)
l.logAttrs(context.Background(), slog.LevelWarn, fmt.Sprintf("%v", v), attrs...)
}
@@ -215,57 +194,3 @@ func (l *Logger) Stat(v any, fields ...logx.LogField) {
attrs := l.buildAttrs(fields)
l.logAttrs(context.Background(), slog.LevelInfo, fmt.Sprintf("%v", v), attrs...)
}
// dailyWriter 匧予𠧧?
// 瘥𤩺活 Write 齿𠯫頝典予嗉䌊隞嗚?
// 瘥誩予眏 lumberjack 匧之撠𤩺靽萘 MaxBackups 銝芸隞賬?
type dailyWriter struct {
mu sync.Mutex
conf LogConf
baseDir string
baseName string // 銝滚鉄憒?"bj_power_mes"
ext string // 憒?".log"
currentDay string
lj *lumberjack.Logger
}
func newDailyWriter(conf LogConf) *dailyWriter {
dir := filepath.Dir(conf.Filename)
ext := filepath.Ext(conf.Filename)
base := strings.TrimSuffix(filepath.Base(conf.Filename), ext)
// 蝖桐摮睃銁
if err := os.MkdirAll(dir, 0755); err != nil {
// 𥕦遣憭梯揖啣虾嚗屸摨誩鍳典仃韐?
slog.Error("log: 𥕦遣憭梯揖嚗啣極雿𦦵𤌍敶?, "dir", dir, "error", err)
dir = workdir
}
return &dailyWriter{
conf: conf,
baseDir: dir,
baseName: base,
ext: ext,
}
}
func (w *dailyWriter) Write(p []byte) (n int, err error) {
w.mu.Lock()
defer w.mu.Unlock()
day := time.Now().Format("2006-01-02")
if day != w.currentDay {
// 頝典予嚗𡁜剜唂 writer嚗撱箸鰵
if w.lj != nil {
w.lj.Close()
}
filename := filepath.Join(w.baseDir, w.baseName+"-"+day+w.ext)
w.lj = &lumberjack.Logger{
Filename: filename,
MaxSize: w.conf.MaxSize,
MaxBackups: w.conf.MaxBackups,
MaxAge: w.conf.MaxAge,
Compress: w.conf.Compress,
}
w.currentDay = day
}
return w.lj.Write(p)
}