Skip to content

Commit a114fa6

Browse files
committed
chore(logger): removes fmt print and uses alchemy logger
Signed-off-by: architm21 <[email protected]>
1 parent 9c91df0 commit a114fa6

File tree

6 files changed

+23
-15
lines changed

6 files changed

+23
-15
lines changed

nets/apiconnect/apiconnect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var log = alog.UseChannel("apic")
3939
func (a *APIConnect) crdStatusMetrics(dynamicClient dynamic.DynamicClient, gvr schema.GroupVersionResource, crdStatus prometheus.GaugeVec) {
4040
subsystems, err := dynamicClient.Resource(gvr).List(context.Background(), v1.ListOptions{})
4141
if err != nil {
42-
fmt.Printf("error getting subsystems: %v\n", err)
42+
log.Log(alog.ERROR, "error getting subsystems %v", err)
4343
return
4444
}
4545

nets/datapower/datapower.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,7 @@ func (d *DataPower) invokeRestMgmt(ip string, path string) (*http.Response, erro
707707
}
708708
if response.StatusCode != 200 {
709709
//return nil, errors.New(fmt.Sprintf("Unexpected status - Got %s, expected 200", response.Status))
710-
fmt.Printf("ERROR %s\n", response.Status)
711-
log.Log(alog.ERROR, response.Status)
710+
log.Log(alog.ERROR, "Error invoking rest management with status %s", response.Status)
712711
return nil, errors.New(response.Status)
713712
}
714713
return response, nil

nets/main.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ type BaseNet struct {
3939
Frequency time.Duration
4040
}
4141

42+
func (b *BaseNet) String() string {
43+
return fmt.Sprintf("Base Net Name: %s || Base Net Disabled: %t || Base net frequency: %d", b.Name, b.Disabled, b.Frequency)
44+
}
45+
4246
type NetInterface interface {
4347
Fish()
4448
}
@@ -52,9 +56,8 @@ var log = alog.UseChannel("nets")
5256
var dynamicClient *dynamic.DynamicClient
5357

5458
func Enable(n BaseNet, frequency int) {
55-
fmt.Println(n)
56-
fmt.Println(frequency)
57-
log.Log(alog.INFO, "enabling %s", n.Name)
59+
log.Log(alog.INFO, "Enabling Base Net", n.String())
60+
5861
net_frequency := time.Duration(5)
5962
if frequency != 0 {
6063
log.Log(alog.INFO, "net is enabled at %ds frequency", frequency)

nets/main_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package nets
22

33
import (
4-
"fmt"
54
"net/http"
65
"net/http/httptest"
76
"testing"
87

8+
"github.com/IBM/alchemy-logging/src/go/alog"
99
"github.com/stretchr/testify/assert"
1010
)
1111

12+
var testLogger = alog.UseChannel("main_tests")
13+
1214
func TestGetToken(t *testing.T) {
1315
assert := assert.New(t)
1416
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -21,8 +23,7 @@ func TestGetToken(t *testing.T) {
2123

2224
token, err := GetToken(server.URL)
2325

24-
fmt.Println(token)
26+
testLogger.Log(alog.DEBUG, "fetched token: %s", token)
2527
assert.Nil(err)
2628
assert.Equal("123445", token)
27-
2829
}

nets/manager/manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ func (m *Manager) getWebhookStats(management_url string, org string, catalog str
160160
defer response.Body.Close()
161161
var cgsResponse ConfiguredGatewayServices
162162
err = json.NewDecoder(response.Body).Decode(&cgsResponse)
163+
log.Log(alog.DEBUG, "Webhook status total results:", cgsResponse.TotalResults)
163164
for _, cgs := range cgsResponse.Results {
164165
m.metrics["outstandingSent"].WithLabelValues(org, catalog, cgs.Name, cgs.ServiceVersion).Set(float64(cgs.GatewayProcessingStatus.OutstandingSentEvents))
165166
m.metrics["outstandingQueued"].WithLabelValues(org, catalog, cgs.Name, cgs.ServiceVersion).Set(float64(cgs.GatewayProcessingStatus.OutstandingQueuedEvents))

nets/manager/manager_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@ package manager
22

33
import (
44
"bytes"
5-
"fmt"
65
"io/ioutil"
76
"net/http"
87
"net/http/httptest"
98
"strings"
109
"testing"
1110

11+
"github.com/IBM/alchemy-logging/src/go/alog"
1212
"github.com/prometheus/client_golang/prometheus"
1313
"github.com/prometheus/client_golang/prometheus/testutil"
1414
"github.com/stretchr/testify/assert"
1515
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1616
)
1717

18+
var testLogger = alog.UseChannel("manager_tests")
19+
1820
var m Manager
1921

2022
// You can use testing.T, if you want to test the code without benchmarking
@@ -58,10 +60,11 @@ func TestTopologyValues(t *testing.T) {
5860
Host: server.URL,
5961
}
6062
m := Manager{Config: config}
61-
fmt.Println(m)
63+
64+
testLogger.Log(alog.DEBUG, "manager: %v", m)
6265
assert.Equal(server.Config.Addr, "")
6366
ti, err := m.getTopologyInfo(server.URL)
64-
fmt.Println(ti)
67+
testLogger.Log(alog.DEBUG, "cloud topology: %v", ti)
6568
assert.Nil(err)
6669
assert.Equal(float64(23), ti.Counts.ProviderOrgs)
6770

@@ -82,12 +85,13 @@ func TestWebhookStats(t *testing.T) {
8285
Host: server.URL,
8386
}
8487
m := Manager{Config: config}
85-
fmt.Println(m)
88+
testLogger.Log(alog.DEBUG, "manager: %v", m)
89+
8690
assert.Equal(server.Config.Addr, "")
8791
m.getWebhookStats(server.URL, "org", "catalog")
8892
assert.Empty("hllo")
8993
//count := testutil.CollectAndCount(m.metrics["outstandingSent"], "manager_gateway_processing_outstanding_sent_events")
90-
//fmt.Println(count)
94+
//testLogger.Log(alog.DEBUG, "collected count: %v", count)
9195
//assert.Equal(0, count)
9296

9397
}
@@ -152,7 +156,7 @@ func TestFindAPIM(t *testing.T) {
152156
getToken = MockGetToken
153157
err := m.findAPIM()
154158
if err != nil {
155-
fmt.Println(err.Error())
159+
t.Error("expected error to be nil but got %v", err)
156160
}
157161
assert.Empty(err)
158162

0 commit comments

Comments
 (0)