diff --git a/README.md b/README.md index fe3507e..7f273b7 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ +[![Release](https://img.shields.io/github/release/trustbloc/logutil-go.svg?style=flat-square)](https://github.com/trustbloc/logutil-go/releases/latest) +[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://raw.githubusercontent.com/trustbloc/logutil-go/main/LICENSE) +[![Godocs](https://img.shields.io/badge/godoc-reference-blue.svg)](https://godoc.org/github.com/trustbloc/logutil-go) + +[![Build Status](https://github.com/trustbloc/logutil-go/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/trustbloc/logutil-go/actions/workflows/build.yml) +[![codecov](https://codecov.io/gh/trustbloc/logutil-go/branch/main/graph/badge.svg)](https://codecov.io/gh/trustbloc/logutil-go) +[![Go Report Card](https://goreportcard.com/badge/github.com/trustbloc/logutil-go)](https://goreportcard.com/report/github.com/trustbloc/logutil-go) + # logutil-go General purpose field enabled logging module. This allows logs to be attribute labelled instead of having long string logs. diff --git a/pkg/log/fields.go b/pkg/log/fields.go index 1802bbd..67e7130 100644 --- a/pkg/log/fields.go +++ b/pkg/log/fields.go @@ -16,6 +16,7 @@ import ( // Log Fields. const ( FieldAdditionalMessage = "additionalMessage" + FieldAddress = "address" FieldCertPoolSize = "certPoolSize" FieldCommand = "command" FieldConcurrencyRequests = "concurrencyRequests" @@ -28,20 +29,22 @@ const ( FieldIDToken = "idToken" FieldJSON = "json" FieldJSONResolution = "jsonResolution" + FieldMessageBrokers = "message-brokers" FieldName = "name" FieldParameter = "parameter" FieldParameters = "parameters" FieldPath = "path" FieldPresDefID = "presDefinitionID" FieldProfileID = "profileID" - FieldResponseBody = "responseBody" FieldResponse = "response" + FieldResponseBody = "responseBody" FieldResponses = "responses" + FieldService = "service" FieldSleep = "sleep" FieldState = "state" - FieldService = "service" FieldToken = "token" FieldTopic = "topic" + FieldTotalMessages = "total-messages" FieldTotalRequests = "totalRequests" FieldTxID = "transactionID" FieldURL = "url" @@ -235,3 +238,18 @@ func WithState(state string) zap.Field { func WithProfileID(id string) zap.Field { return zap.String(FieldProfileID, id) } + +// WithAddress sets the address field. +func WithAddress(address string) zap.Field { + return zap.String(FieldAddress, address) +} + +// WithMessageBrokers sets the topic field. +func WithMessageBrokers(value []string) zap.Field { + return zap.Any(FieldMessageBrokers, value) +} + +// WithTotalMessages sets the total messages field. +func WithTotalMessages(totalMessages int) zap.Field { + return zap.Int(FieldTotalMessages, totalMessages) +} diff --git a/pkg/log/fields_test.go b/pkg/log/fields_test.go index 4d3c105..b786890 100644 --- a/pkg/log/fields_test.go +++ b/pkg/log/fields_test.go @@ -60,6 +60,7 @@ func TestStandardFields(t *testing.T) { topic := "some topic" msg := "Some message" hostURL := "https://localhost:8080" + address := "https://localhost:8080" responseBody := []byte("response body") token := "someToken" totalRequests := 10 @@ -84,6 +85,8 @@ func TestStandardFields(t *testing.T) { profileID := "some profile id" parameter := "param1" parameters := &mockObject{Field1: "param1", Field2: 4612} + brokers := []string{"broker"} + totalMessages := 3 dockerComposeCmd := strings.Join([]string{ "docker-compose", @@ -127,6 +130,9 @@ func TestStandardFields(t *testing.T) { WithUserLogLevel(DEBUG.String()), WithVPToken(vpToken), WithWorkers(workers), + WithAddress(address), + WithMessageBrokers(brokers), + WithTotalMessages(totalMessages), ) t.Logf(stdOut.String()) @@ -160,6 +166,9 @@ func TestStandardFields(t *testing.T) { require.Equal(t, presDefID, l.PresDefID) require.Equal(t, state, l.State) require.Equal(t, profileID, l.ProfileID) + require.Equal(t, address, l.Address) + require.Equal(t, brokers, l.MessageBrokers) + require.Equal(t, totalMessages, l.TotalMessages) }) t.Run("json fields 2", func(t *testing.T) { @@ -219,6 +228,9 @@ type logData struct { UserLogLevel string `json:"userLogLevel"` VPToken string `json:"vpToken"` Workers int `json:"workers"` + Address string `json:"address"` + MessageBrokers []string `json:"message-brokers"` + TotalMessages int `json:"total-messages"` } func unmarshalLogData(t *testing.T, b []byte) *logData { diff --git a/scripts/check_unit.sh b/scripts/check_unit.sh index a30eefa..0dd715d 100755 --- a/scripts/check_unit.sh +++ b/scripts/check_unit.sh @@ -18,7 +18,7 @@ if [ -f profile.out ]; then fi } -# Running vcs unit tests +# Running logutil-go unit tests echo "logutil-go unit tests..." PKGS=`go list github.com/trustbloc/logutil-go/... 2> /dev/null | \ grep -v /mocks`