Skip to content

Commit 3874f0d

Browse files
logging
1 parent 56a2087 commit 3874f0d

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

Taskfile.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ tasks:
7575
dir: apps/semcache-service
7676
cmds:
7777
- |
78-
echo "🔥 Starting semcache-service with Air hot reload + K8s PostgreSQL..."
79-
echo "📝 Edit any .go file and see changes in ~1 second!"
80-
echo ""
78+
echo "Starting semcache-service with Air hot reload + K8s PostgreSQL..."
8179
8280
# Check if port-forward is already running
8381
if lsof -Pi :5432 -sTCP:LISTEN -t >/dev/null 2>&1; then
@@ -116,9 +114,6 @@ tasks:
116114
export OTEL_ENABLED=false
117115
118116
echo "🚀 Starting Air hot reload on port 8090..."
119-
echo " http://localhost:8090/health"
120-
echo " http://localhost:8090/v1/greetings"
121-
echo ""
122117
air -c .air.toml
123118
124119
# dev:stop-port-forwards:

apps/semcache-service/cmd/server/main.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"log"
78
"os"
@@ -15,6 +16,7 @@ import (
1516
"github.com/nextinterfaces/semcache-service/internal/database"
1617
"github.com/nextinterfaces/semcache-service/internal/handlers"
1718
"github.com/nextinterfaces/semcache-service/internal/models"
19+
"github.com/nextinterfaces/semcache-service/internal/util"
1820
"go.opentelemetry.io/otel"
1921
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
2022
"go.opentelemetry.io/otel/sdk/resource"
@@ -29,16 +31,14 @@ func main() {
2931
}
3032

3133
func run() error {
32-
// Load configuration
3334
cfg, err := config.Load()
35+
cfgJSON, _ := json.MarshalIndent(util.RedactedConfig(cfg), "", " ")
36+
log.Println("Loaded configuration:\n" + string(cfgJSON))
3437
if err != nil {
3538
return fmt.Errorf("failed to load config: %w", err)
3639
}
3740

38-
log.Printf("Starting semcache-service on port %d", cfg.Server.Port)
39-
log.Printf("Commit SHA: %s", cfg.Server.CommitSHA)
40-
41-
// Initialize OpenTelemetry if enabled
41+
// Initialize OpenTelemetry
4242
if cfg.OTEL.Enabled {
4343
shutdown, err := initTracer(cfg)
4444
if err != nil {
@@ -79,32 +79,28 @@ func run() error {
7979
e.Use(middleware.Recover())
8080
e.Use(middleware.CORS())
8181

82-
// Routes
8382
e.GET("/v1/health", h.Health)
8483

85-
// API Documentation routes
8684
e.GET("/docs", h.ServeSwaggerUI)
8785
e.GET("/api/openapi.yaml", h.ServeOpenAPISpec)
8886

89-
// API routes
9087
api := e.Group("/v1")
9188
api.POST("/create", h.Create)
9289
api.POST("/search", h.Search)
9390

94-
// Start server in a goroutine
91+
port := cfg.Server.Port
9592
go func() {
96-
addr := fmt.Sprintf(":%d", cfg.Server.Port)
93+
addr := fmt.Sprintf(":%d", port)
9794
if err := e.Start(addr); err != nil {
9895
log.Printf("Server error: %v", err)
9996
}
10097
}()
10198

102-
log.Printf("Server started successfully on port %d", cfg.Server.Port)
103-
log.Printf("Health check: http://localhost:%d/v1/health", cfg.Server.Port)
104-
log.Printf("API Documentation: http://localhost:%d/docs", cfg.Server.Port)
105-
log.Printf("API endpoints:")
106-
log.Printf(" POST http://localhost:%d/v1/create", cfg.Server.Port)
107-
log.Printf(" POST http://localhost:%d/v1/search", cfg.Server.Port)
99+
log.Printf("Server started, endpoints:")
100+
log.Printf(" http://localhost:%d/v1/health", port)
101+
log.Printf(" http://localhost:%d/docs", port)
102+
log.Printf(" POST http://localhost:%d/v1/create", port)
103+
log.Printf(" POST http://localhost:%d/v1/search", port)
108104

109105
// Wait for interrupt signal to gracefully shutdown the server
110106
quit := make(chan os.Signal, 1)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package util
2+
3+
import (
4+
"github.com/nextinterfaces/semcache-service/internal/config"
5+
)
6+
7+
func RedactedConfig(cfg *config.Config) *config.Config {
8+
copy := *cfg // shallow copy
9+
copy.Database.User = mask(copy.Database.User)
10+
copy.Database.Password = mask(copy.Database.Password)
11+
return &copy
12+
}
13+
14+
func mask(s string) string {
15+
if len(s) > 2 {
16+
return s[:2] + "***"
17+
}
18+
return "***"
19+
}

0 commit comments

Comments
 (0)