Skip to content

Commit 404283e

Browse files
authored
refactor(log): rework logger initialization #27
- Remove verbose flag and terminal logging - Logger is now file-based only - Use env vars for debug level - Remove config for air Fixes #25
2 parents 3e98779 + 3909e1c commit 404283e

File tree

10 files changed

+108
-375
lines changed

10 files changed

+108
-375
lines changed

.air.toml

Lines changed: 0 additions & 22 deletions
This file was deleted.

internal/collections/manager.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (c *CollectionsManager) Create(ctx context.Context, name string) (Collectio
1919
return CollectionEntity{}, crud.ErrInvalidInput
2020
}
2121

22-
log.DebugIf("creating collection", "name", name)
22+
log.Debug("creating collection", "name", name)
2323
collection, err := c.DB.CreateCollection(ctx, name)
2424
if err != nil {
2525
log.Error("failed to create collection", "name", name, "error", err)
@@ -36,7 +36,7 @@ func (c *CollectionsManager) Read(ctx context.Context, id int64) (CollectionEnti
3636
return CollectionEntity{}, crud.ErrInvalidInput
3737
}
3838

39-
log.DebugIf("reading collection", "id", id)
39+
log.Debug("reading collection", "id", id)
4040
collection, err := c.DB.GetCollection(ctx, id)
4141
if err != nil {
4242
if err == sql.ErrNoRows {
@@ -60,7 +60,7 @@ func (c *CollectionsManager) Update(ctx context.Context, id int64, name string)
6060
return CollectionEntity{}, crud.ErrInvalidInput
6161
}
6262

63-
log.DebugIf("updating collection", "id", id, "name", name)
63+
log.Debug("updating collection", "id", id, "name", name)
6464
collection, err := c.DB.UpdateCollectionName(ctx, database.UpdateCollectionNameParams{
6565
Name: name,
6666
ID: id,
@@ -84,7 +84,7 @@ func (c *CollectionsManager) Delete(ctx context.Context, id int64) error {
8484
return crud.ErrInvalidInput
8585
}
8686

87-
log.DebugIf("deleting collection", "id", id)
87+
log.Debug("deleting collection", "id", id)
8888
err := c.DB.DeleteCollection(ctx, id)
8989
if err != nil {
9090
log.Error("failed to delete collection", "id", id, "error", err)
@@ -96,7 +96,7 @@ func (c *CollectionsManager) Delete(ctx context.Context, id int64) error {
9696
}
9797

9898
func (c *CollectionsManager) List(ctx context.Context) ([]CollectionEntity, error) {
99-
log.DebugIf("listing all collections with default pagination")
99+
log.Debug("listing all collections with default pagination")
100100
paginated, err := c.ListPaginated(ctx, 50, 0)
101101
if err != nil {
102102
return nil, err
@@ -113,7 +113,7 @@ func (c *CollectionsManager) ListPaginated(ctx context.Context, limit, offset in
113113
log.Warn("negative pagination offset", "offset", offset)
114114
}
115115

116-
log.DebugIf("listing paginated collections", "limit", limit, "offset", offset)
116+
log.Debug("listing paginated collections", "limit", limit, "offset", offset)
117117

118118
total, err := c.DB.CountCollections(ctx)
119119
if err != nil {

internal/endpoints/manager.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (e *EndpointsManager) Read(ctx context.Context, id int64) (EndpointEntity,
2525
return EndpointEntity{}, crud.ErrInvalidInput
2626
}
2727

28-
log.DebugIf("reading endpoint", "id", id)
28+
log.Debug("reading endpoint", "id", id)
2929
endpoint, err := e.DB.GetEndpoint(ctx, id)
3030
if err != nil {
3131
if err == sql.ErrNoRows {
@@ -49,7 +49,7 @@ func (e *EndpointsManager) Delete(ctx context.Context, id int64) error {
4949
return crud.ErrInvalidInput
5050
}
5151

52-
log.DebugIf("deleting endpoint", "id", id)
52+
log.Debug("deleting endpoint", "id", id)
5353
err := e.DB.DeleteEndpoint(ctx, id)
5454
if err != nil {
5555
log.Error("failed to delete endpoint", "id", id, "error", err)
@@ -70,7 +70,7 @@ func (e *EndpointsManager) ListByCollection(ctx context.Context, collectionID in
7070
return nil, crud.ErrInvalidInput
7171
}
7272

73-
log.DebugIf("listing paginated endpoints", "collection_id", collectionID, "limit", limit, "offset", offset)
73+
log.Debug("listing paginated endpoints", "collection_id", collectionID, "limit", limit, "offset", offset)
7474

7575
total, err := e.DB.CountEndpointsByCollection(ctx, collectionID)
7676
if err != nil {
@@ -132,7 +132,7 @@ func (e *EndpointsManager) CreateEndpoint(ctx context.Context, data EndpointData
132132
queryParamsJSON = string(qpBytes)
133133
}
134134

135-
log.DebugIf("creating endpoint", "collection_id", data.CollectionID, "name", data.Name, "method", data.Method, "url", data.URL)
135+
log.Debug("creating endpoint", "collection_id", data.CollectionID, "name", data.Name, "method", data.Method, "url", data.URL)
136136
endpoint, err := e.DB.CreateEndpoint(ctx, database.CreateEndpointParams{
137137
CollectionID: data.CollectionID,
138138
Name: data.Name,
@@ -180,7 +180,7 @@ func (e *EndpointsManager) UpdateEndpoint(ctx context.Context, id int64, data En
180180
queryParamsJSON = string(qpBytes)
181181
}
182182

183-
log.DebugIf("updating endpoint", "id", id, "name", data.Name, "method", data.Method, "url", data.URL)
183+
log.Debug("updating endpoint", "id", id, "name", data.Name, "method", data.Method, "url", data.URL)
184184
endpoint, err := e.DB.UpdateEndpoint(ctx, database.UpdateEndpointParams{
185185
Name: data.Name,
186186
Method: data.Method,

internal/history/manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (h *HistoryManager) Read(ctx context.Context, id int64) (HistoryEntity, err
3131
return HistoryEntity{}, err
3232
}
3333

34-
log.DebugIf("read history entry", "id", id)
34+
log.Debug("read history entry", "id", id)
3535
return HistoryEntity{History: history}, nil
3636
}
3737

@@ -111,7 +111,7 @@ func (h *HistoryManager) RecordExecution(ctx context.Context, data ExecutionData
111111
return HistoryEntity{}, err
112112
}
113113

114-
log.DebugIf("recording execution", "method", data.Method, "url", data.URL, "status", data.StatusCode)
114+
log.Debug("recording execution", "method", data.Method, "url", data.URL, "status", data.StatusCode)
115115

116116
// Marshal to JSON for database storage
117117
requestHeaders, err := json.Marshal(data.Headers)

internal/http/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (h *HTTPManager) ExecuteRequest(req *Request) (*Response, error) {
5959
return nil, err
6060
}
6161

62-
log.DebugIf("executing HTTP request", "method", req.Method, "url", req.URL)
62+
log.Debug("executing HTTP request", "method", req.Method, "url", req.URL)
6363

6464
requestURL, err := h.buildURL(req.URL, req.QueryParams)
6565
if err != nil {

internal/log/handler.go

Lines changed: 0 additions & 145 deletions
This file was deleted.

internal/log/handler_test.go

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)