File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -113,6 +113,9 @@ func bracketedLevel(l slog.Level) string {
113113// It returns (handled, error). When handled is false, the caller should fall back to formatValue.
114114func writeValueFast (w io.Writer , v interface {}) (bool , error ) {
115115 switch x := v .(type ) {
116+ case string :
117+ _ , err := w .Write ([]byte (quote (x )))
118+ return true , err
116119 case bool :
117120 if x {
118121 _ , err := w .Write ([]byte ("true" ))
Original file line number Diff line number Diff line change @@ -75,6 +75,24 @@ func BenchmarkHumanSinkLogEntry(b *testing.B) {
7575 Fields : nil ,
7676 },
7777 },
78+ {
79+ "StringHeavy" ,
80+ slog.SinkEntry {
81+ Time : time .Unix (0 , 0 ),
82+ Level : slog .LevelInfo ,
83+ Message : "user action" ,
84+ Fields : slog .M (
85+ slog .F ("user_id" , "abc-123-def-456-ghi-789" ),
86+ slog .F ("action" , "login" ),
87+ slog .F ("ip_address" , "192.168.1.100" ),
88+ slog .F ("user_agent" , "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" ),
89+ slog .F ("session_id" , "sess_9d8f7a6b5c4e3d2a1b0c" ),
90+ slog .F ("request_id" , "req_1a2b3c4d5e6f7g8h9i0j" ),
91+ slog .F ("endpoint" , "/api/v1/users/login" ),
92+ slog .F ("method" , "POST" ),
93+ ),
94+ },
95+ },
7896 }
7997 for _ , tc := range testcases {
8098 b .Run (tc .name , func (b * testing.B ) {
You can’t perform that action at this time.
0 commit comments