-
Notifications
You must be signed in to change notification settings - Fork 2
refactor: remove github.com/devsy-org/log dependency #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
abce593
878e46d
ba79011
ae0334a
ff2c01d
46bbdec
977696e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,10 +3,9 @@ package log | |
| import ( | ||
| "encoding/json" | ||
| "io" | ||
| "strings" | ||
|
|
||
| "github.com/devsy-org/devsy/pkg/scanner" | ||
| "github.com/devsy-org/log" | ||
| "github.com/sirupsen/logrus" | ||
| ) | ||
|
|
||
| func PipeJSONStream() (io.WriteCloser, chan struct{}) { | ||
|
|
@@ -20,34 +19,49 @@ func PipeJSONStream() (io.WriteCloser, chan struct{}) { | |
| return writer, done | ||
| } | ||
|
|
||
| var levelFuncs = map[logrus.Level]func(...any){ | ||
| logrus.TraceLevel: Debug, | ||
| logrus.DebugLevel: Debug, | ||
| logrus.InfoLevel: Info, | ||
| logrus.WarnLevel: Warn, | ||
| logrus.ErrorLevel: Error, | ||
| logrus.PanicLevel: Error, | ||
| logrus.FatalLevel: Error, | ||
| // jsonLine is a self-contained representation of a JSON log line, | ||
| // replacing the old github.com/devsy-org/log.Line type. | ||
| type jsonLine struct { | ||
| Message string `json:"message,omitempty"` | ||
| Msg string `json:"msg,omitempty"` | ||
| Level string `json:"level,omitempty"` | ||
| } | ||
|
|
||
| func (l *jsonLine) text() string { | ||
| if l.Message != "" { | ||
| return l.Message | ||
| } | ||
| return l.Msg | ||
| } | ||
|
|
||
| var levelFuncs = map[string]func(...any){ | ||
| "trace": Debug, | ||
| "debug": Debug, | ||
| "info": Info, | ||
| "warning": Warn, | ||
| "warn": Warn, | ||
| "error": Error, | ||
| "panic": Error, | ||
| "fatal": Error, | ||
| } | ||
|
|
||
| func ReadJSONStream(reader io.Reader) { | ||
| scan := scanner.NewScanner(reader) | ||
| for scan.Scan() { | ||
| lineObject, err := Unmarshal(scan.Bytes()) | ||
| if err == nil && lineObject.Message != "" { | ||
| if fn, ok := levelFuncs[lineObject.Level]; ok { | ||
| fn(lineObject.Message) | ||
| } | ||
| line := scan.Bytes() | ||
| if len(line) == 0 { | ||
| continue | ||
| } | ||
| obj := &jsonLine{} | ||
| if err := json.Unmarshal(line, obj); err != nil { | ||
| continue | ||
| } | ||
| msg := obj.text() | ||
| if msg == "" { | ||
| continue | ||
| } | ||
| if fn, ok := levelFuncs[strings.ToLower(obj.Level)]; ok { | ||
| fn(msg) | ||
| } | ||
| } | ||
|
Comment on lines
48
to
66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: git ls-files | head -20Repository: devsy-org/devsy Length of output: 585 🏁 Script executed: fd -type f -name "jsonstream.go"Repository: devsy-org/devsy Length of output: 229 🏁 Script executed: find . -name "*.go" -path "*log*" | head -20Repository: devsy-org/devsy Length of output: 542 🏁 Script executed: cat -n pkg/log/jsonstream.goRepository: devsy-org/devsy Length of output: 1766 🏁 Script executed: cat -n pkg/log/levels.goRepository: devsy-org/devsy Length of output: 1644 🏁 Script executed: rg -i "zapcore.Encoder|NewJSONEncoder|EncodeLevel" -A 3Repository: devsy-org/devsy Length of output: 1618 🏁 Script executed: rg -i "zap.Config|zap.NewProduction|zap.NewDevelopment" -A 5Repository: devsy-org/devsy Length of output: 812 🏁 Script executed: rg "ReadJSONStream|PipeJSONStream" -B 3 -A 3Repository: devsy-org/devsy Length of output: 2934 🏁 Script executed: rg "DPanic" -iRepository: devsy-org/devsy Length of output: 41 🏁 Script executed: cat -n pkg/log/logger.go | head -40Repository: devsy-org/devsy Length of output: 1468 🏁 Script executed: rg "func Info|func Warn|func Error|func Debug" -A 1Repository: devsy-org/devsy Length of output: 1394 Lines without a recognized The While the agent is configured to use zap's JSON encoder (which outputs lowercase level strings—
Suggested fix: default to Info when level is missing/unknown- if fn, ok := levelFuncs[strings.ToLower(obj.Level)]; ok {
- fn(msg)
- }
+ fn, ok := levelFuncs[strings.ToLower(obj.Level)]
+ if !ok {
+ fn = Info
+ }
+ fn(msg)🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| func Unmarshal(line []byte) (*log.Line, error) { | ||
| lineObject := &log.Line{} | ||
| err := json.Unmarshal(line, lineObject) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return lineObject, nil | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verbosityflag is not propagated to the agent logger.log.Configsupports aVerbosityfield (0=error, 1=info+warn, 2=debug, 3=trace), butAgentPersistentPreRunEonly forwardsQuietandDebug. If the parent process is invoked with-v/-vv(orDEVSY_VERBOSITY), the agent subprocess will silently ignore it and log at the default level, making it harder to debug agent-side issues.Proposed fix
log.Init(log.Config{ + Verbosity: globalFlags.Verbosity, Quiet: globalFlags.Quiet, Debug: globalFlags.Debug, Format: "json", // Agent must always use JSON: stdout is binary protocol, host reads stderr via ReadJSONStream })📝 Committable suggestion
🤖 Prompt for AI Agents