Skip to content

Commit

Permalink
Fix error not show
Browse files Browse the repository at this point in the history
  • Loading branch information
NV4RE committed Nov 23, 2023
1 parent 53a3c0e commit 0711b2b
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 14 deletions.
3 changes: 1 addition & 2 deletions examples/application_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,5 @@ func Example_application_with_data() {
Write()

// Output:
// {"level":"info","timestamp":"2023-11-09T14:48:14.803+0700","caller":"examples/application_log_test.go:44","message":"Info message","app_name":"sampleApp","version":"v1.0.0","alert":0,"log_type":"application","data":{"error":{},"sampleApp":{"field2":"value2"}}}

//{"level":"info","timestamp":"2023-11-09T14:48:14.803+0700","caller":"examples/application_log_test.go:44","message":"Info message","app_name":"sampleApp","version":"v1.0.0","alert":0,"log_type":"application","data":{"error":"error message here","sampleApp":{"field2":"value2"}}}
}
3 changes: 1 addition & 2 deletions examples/audit_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ func Example_audit_log() {
Write()

// Output:
// {"level":"info","timestamp":"2023-11-09T14:48:14.803+0700","caller":"examples/audit_log_test.go:35","message":"Audit message","app_name":"harry_squatter","version":"the_boy_who_lifted","alert":0,"log_type":"audit","data":{"audit":{"actor_type":"hawkward.wizard","actor_id":"magic_user_42","action":"create","entity":"hawkward.spell.banned","entity_refs":["dead_rift","bicep_curse"],"entity_owner_type":"fantasy_realm.system","entity_owner_id":"realm_keeper_5678"},"error":{},"harry_squatter":{"app_data":"app_data_value"}}}

// {"level":"info","timestamp":"2023-11-09T14:48:14.803+0700","caller":"examples/audit_log_test.go:35","message":"Audit message","app_name":"harry_squatter","version":"the_boy_who_lifted","alert":0,"log_type":"audit","data":{"audit":{"actor_type":"hawkward.wizard","actor_id":"magic_user_42","action":"create","entity":"hawkward.spell.banned","entity_refs":["dead_rift","bicep_curse"],"entity_owner_type":"fantasy_realm.system","entity_owner_id":"realm_keeper_5678"},"error":"you got mail","harry_squatter":{"app_data":"app_data_value"}}}
}
3 changes: 1 addition & 2 deletions examples/event_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,5 @@ func Example_event_log() {
Write()

// Output:
// {"level":"info","timestamp":"2023-11-09T14:48:14.803+0700","caller":"examples/event_log_test.go:34","message":"Event message","app_name":"lord_of_the_rim","version":"the_rim_of_lovers","alert":0,"log_type":"event","data":{"event":{"entity":"rim","reference_id":"#1","action":"create","result":"success","data":null},"lord_of_the_rim":{"app_data":"app_data_value"}}}

// {"level":"info","timestamp":"2023-11-09T14:48:14.803+0700","caller":"examples/event_log_test.go:34","message":"Event message","app_name":"lord_of_the_rim","version":"the_rim_of_lovers","alert":0,"log_type":"event","data":{"event":{"entity":"rim","reference_id":"#1","action":"create","result":"success","data":""},"lord_of_the_rim":{"app_data":"app_data_value"}}}
}
6 changes: 3 additions & 3 deletions examples/handler_http_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func Example_handler_http_log() {
Write()

// Output:
// {"level":"info","timestamp":"2023-11-09T14:48:14.803+0700","caller":"examples/handler_http_log_test.go:36","message":"HandlerHTTP request received","app_name":"sampleApp","version":"v1.0.0","alert":0,"log_type":"handler.http","data":{"http_request":{"method":"POST","handler":"GetResourceById","path":"/api/{{resource}}","remote_ip":"192.168.1.1","headers":{"Content-Type":"application/json"},"params":{"resource":"123"},"query":{"param1":"value1"},"body":"eyJrZXkiOiAidmFsdWUifQ==","request_id":"unique-request-id"}}}
// {"level":"info","timestamp":"2023-11-09T14:48:14.803+0700","caller":"examples/handler_http_log_test.go:48","message":"HandlerHTTP request processed successfully","app_name":"sampleApp","version":"v1.0.0","alert":0,"log_type":"handler.http","data":{"http_response":{"status":200,"duration":2,"body":"eyJyZXN1bHQiOiAic3VjY2VzcyJ9","request_id":"unique-request-id"}}}
// {"level":"info","timestamp":"2023-11-09T14:48:14.803+0700","caller":"examples/handler_http_log_test.go:54","message":"HandlerHTTP request processing failed","app_name":"sampleApp","version":"v1.0.0","alert":0,"log_type":"handler.http","data":{"error":{},"sampleApp":{"field2":"value2"}}}
//{"level":"info","timestamp":"2023-11-09T14:48:14.803+0700","caller":"examples/handler_http_log_test.go:35","message":"HandlerHTTP request received","app_name":"sampleApp","version":"v1.0.0","alert":0,"log_type":"handler.http","data":{"http_request":{"method":"POST","handler":"GetResourceById","path":"/api/{{resource}}","remote_ip":"192.168.1.1","headers":{"Content-Type":"application/json"},"params":{"resource":"123"},"query":{"param1":"value1"},"body":"{\"key\": \"value\"}","request_id":"unique-request-id"}}}
//{"level":"info","timestamp":"2023-11-09T14:48:14.803+0700","caller":"examples/handler_http_log_test.go:47","message":"HandlerHTTP request processed successfully","app_name":"sampleApp","version":"v1.0.0","alert":0,"log_type":"handler.http","data":{"http_response":{"status":200,"duration":2,"body":"{\"result\": \"success\"}","request_id":"unique-request-id","headers":null}}}
//{"level":"info","timestamp":"2023-11-09T14:48:14.803+0700","caller":"examples/handler_http_log_test.go:53","message":"HandlerHTTP request processing failed","app_name":"sampleApp","version":"v1.0.0","alert":0,"log_type":"handler.http","data":{"error":"error message here","sampleApp":{"field2":"value2"}}}
}
7 changes: 3 additions & 4 deletions examples/handler_kafka_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ func Example_handler_kafka_log() {
Write()

// Output:
// {"level":"info","timestamp":"2023-11-09T14:48:14.803+0700","caller":"examples/handler_kafka_log_test.go:34","message":"HandlerKafka message received","app_name":"sampleApp","version":"v1.0.0","alert":0,"log_type":"handler.kafka","data":{"kafka_message":{"topic":"topic","partition":0,"offset":0,"headers":{"header1":"value1","header2":"value2"},"key":"key","payload":"cGF5bG9hZA==","timestamp":"0001-01-01T00:00:00Z"}}}
// {"level":"info","timestamp":"2023-11-09T14:48:14.803+0700","caller":"examples/handler_kafka_log_test.go:41","message":"HandlerKafka message processed successfully","app_name":"sampleApp","version":"v1.0.0","alert":0,"log_type":"handler.kafka","data":{"kafka_result":{"duration":3,"committed":true}}}
// {"level":"info","timestamp":"2023-11-09T14:48:14.803+0700","caller":"examples/handler_kafka_log_test.go:49","message":"HandlerKafka message processed Failed","app_name":"sampleApp","version":"v1.0.0","alert":0,"log_type":"handler.kafka","data":{"error":{},"kafka_result":{"duration":3},"sampleApp":{"field2":"value2"}}}

// {"level":"info","timestamp":"2023-11-09T14:48:14.803+0700","caller":"examples/handler_kafka_log_test.go:34","message":"HandlerKafka message received","app_name":"sampleApp","version":"v1.0.0","alert":0,"log_type":"handler.kafka","data":{"kafka_message":{"topic":"topic","partition":0,"offset":0,"headers":{"header1":"value1","header2":"value2"},"key":"key","payload":"payload","timestamp":"0001-01-01T00:00:00Z"}}}
//{"level":"info","timestamp":"2023-11-09T14:48:14.803+0700","caller":"examples/handler_kafka_log_test.go:41","message":"HandlerKafka message processed successfully","app_name":"sampleApp","version":"v1.0.0","alert":0,"log_type":"handler.kafka","data":{"kafka_result":{"duration":3,"committed":true}}}
//{"level":"info","timestamp":"2023-11-09T14:48:14.803+0700","caller":"examples/handler_kafka_log_test.go:49","message":"HandlerKafka message processed Failed","app_name":"sampleApp","version":"v1.0.0","alert":0,"log_type":"handler.kafka","data":{"error":"error message here","kafka_result":{"duration":3},"sampleApp":{"field2":"value2"}}}
}
2 changes: 1 addition & 1 deletion zap_logger/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func TestBase_WithError(t *testing.T) {
},
want: &Logger{
logger: logger,
Data: map[string]any{"error": fmt.Errorf("Sample error message")},
Data: map[string]any{"error": "Sample error message"},
},
},
{
Expand Down

0 comments on commit 0711b2b

Please sign in to comment.