You've already forked agentic-coding-workflow
fix(logger): expose AddSource option; FromEnv enables caller in non-dev (spec §8.2)
This commit is contained in:
@@ -57,3 +57,33 @@ func TestFromEnv_NonDevelopmentUsesJSON(t *testing.T) {
|
||||
require.NoError(t, json.Unmarshal(buf.Bytes(), &got))
|
||||
require.Equal(t, "prod", got["msg"])
|
||||
}
|
||||
|
||||
func TestNew_AddSourceTrue_IncludesSourceField(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
log := New(Options{Format: FormatJSON, Level: LevelInfo, Writer: &buf, AddSource: true})
|
||||
log.Info("with source")
|
||||
|
||||
var got map[string]any
|
||||
require.NoError(t, json.Unmarshal(buf.Bytes(), &got))
|
||||
require.Contains(t, got, "source", "AddSource:true 时应有 source 字段")
|
||||
}
|
||||
|
||||
func TestNew_AddSourceFalse_OmitsSourceField(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
log := New(Options{Format: FormatJSON, Level: LevelInfo, Writer: &buf, AddSource: false})
|
||||
log.Info("without source")
|
||||
|
||||
var got map[string]any
|
||||
require.NoError(t, json.Unmarshal(buf.Bytes(), &got))
|
||||
require.NotContains(t, got, "source")
|
||||
}
|
||||
|
||||
func TestFromEnv_NonDevelopmentEnablesSource(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
log := FromEnv("production", &buf)
|
||||
log.Info("prod log")
|
||||
|
||||
var got map[string]any
|
||||
require.NoError(t, json.Unmarshal(buf.Bytes(), &got))
|
||||
require.Contains(t, got, "source", "production 应自动开 AddSource (spec §8.2)")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user