Skip to content

Commit 26ac17d

Browse files
committed
log level info
1 parent 80c7924 commit 26ac17d

4 files changed

Lines changed: 13 additions & 60 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ SERVER_HOST=127.0.0.1
116116
ROOT_EMAIL=your@email.com
117117
ENVIRONMENT=production
118118
API_ENDPOINT=https://your_endpoint.website.com
119+
LOG_LEVEL=info
119120
120121
# Database configuration
121122
DB_HOST=localhost

config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func LoadWithOptions(opts LoadOptions) (*Config, error) {
138138
v.SetDefault("DB_NAME", "${DB_PREFIX}_system")
139139
v.SetDefault("DB_SSLMODE", "require")
140140
v.SetDefault("ENVIRONMENT", "production")
141-
v.SetDefault("LOG_LEVEL", "warn")
141+
v.SetDefault("LOG_LEVEL", "info")
142142
v.SetDefault("VERSION", "3.1")
143143

144144
// SMTP defaults

internal/app/app.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,10 @@ func (a *App) Start() error {
627627
handler = middleware.CORSMiddleware(handler)
628628

629629
addr := fmt.Sprintf("%s:%d", a.config.Server.Host, a.config.Server.Port)
630-
a.logger.WithField("address", addr).Info(fmt.Sprintf("Server starting on %s", addr))
630+
a.logger.WithField("address", addr).
631+
WithField("api_endpoint", a.config.APIEndpoint).
632+
WithField("port", a.config.Server.Port).
633+
Info(fmt.Sprintf("Server starting on %s with API endpoint: %s", addr, a.config.APIEndpoint))
631634

632635
// Create a fresh notification channel and update the server
633636
a.serverMu.Lock()

internal/service/telemetry_service.go

Lines changed: 7 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ func NewTelemetryService(config TelemetryServiceConfig) *TelemetryService {
7171
// SendMetricsForAllWorkspaces collects and sends telemetry metrics for all workspaces
7272
func (t *TelemetryService) SendMetricsForAllWorkspaces(ctx context.Context) error {
7373
if !t.enabled {
74-
t.logger.Debug("Telemetry is disabled, skipping metrics collection")
7574
return nil
7675
}
7776

@@ -81,15 +80,10 @@ func (t *TelemetryService) SendMetricsForAllWorkspaces(ctx context.Context) erro
8180
return fmt.Errorf("failed to list workspaces: %w", err)
8281
}
8382

84-
t.logger.WithField("workspace_count", len(workspaces)).Info("Collecting telemetry metrics for workspaces")
85-
8683
// Collect and send metrics for each workspace
8784
for _, workspace := range workspaces {
8885
if err := t.sendMetricsForWorkspace(ctx, workspace.ID); err != nil {
89-
// Log error but continue with other workspaces
90-
t.logger.WithField("workspace_id", workspace.ID).
91-
WithField("error", err).
92-
Error("Failed to send telemetry metrics for workspace")
86+
// Continue with other workspaces on error
9387
}
9488
}
9589

@@ -112,53 +106,30 @@ func (t *TelemetryService) sendMetricsForWorkspace(ctx context.Context, workspac
112106
// Get workspace database connection
113107
db, err := t.workspaceRepo.GetConnection(ctx, workspaceID)
114108
if err != nil {
115-
t.logger.WithField("workspace_id", workspaceID).
116-
WithField("error", err).
117-
Warn("Failed to get workspace database connection for telemetry")
118109
// Continue without database metrics
119110
} else {
120111
// Count contacts
121-
if contactsCount, err := t.countContacts(ctx, db); err != nil {
122-
t.logger.WithField("workspace_id", workspaceID).
123-
WithField("error", err).
124-
Warn("Failed to count contacts for telemetry")
125-
} else {
112+
if contactsCount, err := t.countContacts(ctx, db); err == nil {
126113
metrics.ContactsCount = contactsCount
127114
}
128115

129116
// Count broadcasts
130-
if broadcastsCount, err := t.countBroadcasts(ctx, db); err != nil {
131-
t.logger.WithField("workspace_id", workspaceID).
132-
WithField("error", err).
133-
Warn("Failed to count broadcasts for telemetry")
134-
} else {
117+
if broadcastsCount, err := t.countBroadcasts(ctx, db); err == nil {
135118
metrics.BroadcastsCount = broadcastsCount
136119
}
137120

138121
// Count transactional notifications
139-
if transactionalCount, err := t.countTransactional(ctx, db); err != nil {
140-
t.logger.WithField("workspace_id", workspaceID).
141-
WithField("error", err).
142-
Warn("Failed to count transactional notifications for telemetry")
143-
} else {
122+
if transactionalCount, err := t.countTransactional(ctx, db); err == nil {
144123
metrics.TransactionalCount = transactionalCount
145124
}
146125

147126
// Count messages
148-
if messagesCount, err := t.countMessages(ctx, db); err != nil {
149-
t.logger.WithField("workspace_id", workspaceID).
150-
WithField("error", err).
151-
Warn("Failed to count messages for telemetry")
152-
} else {
127+
if messagesCount, err := t.countMessages(ctx, db); err == nil {
153128
metrics.MessagesCount = messagesCount
154129
}
155130

156131
// Count lists
157-
if listsCount, err := t.countLists(ctx, db); err != nil {
158-
t.logger.WithField("workspace_id", workspaceID).
159-
WithField("error", err).
160-
Warn("Failed to count lists for telemetry")
161-
} else {
132+
if listsCount, err := t.countLists(ctx, db); err == nil {
162133
metrics.ListsCount = listsCount
163134
}
164135
}
@@ -242,56 +213,34 @@ func (t *TelemetryService) sendMetrics(ctx context.Context, metrics TelemetryMet
242213
// Send request (will fail silently if endpoint is offline due to 5s timeout)
243214
resp, err := t.httpClient.Do(req)
244215
if err != nil {
245-
// Log the error but don't return it to fail silently
246-
t.logger.WithField("workspace_id_sha1", metrics.WorkspaceIDSHA1).
247-
WithField("error", err).
248-
Debug("Failed to send telemetry metrics (endpoint may be offline)")
249216
return nil // Fail silently as requested
250217
}
251218
defer resp.Body.Close()
252219

253220
// Check response status
254221
if resp.StatusCode >= 400 {
255-
t.logger.WithField("workspace_id_sha1", metrics.WorkspaceIDSHA1).
256-
WithField("status_code", resp.StatusCode).
257-
Debug("Telemetry endpoint returned error status")
258222
return nil // Fail silently as requested
259223
}
260224

261-
t.logger.WithField("workspace_id_sha1", metrics.WorkspaceIDSHA1).
262-
WithField("contacts_count", metrics.ContactsCount).
263-
WithField("broadcasts_count", metrics.BroadcastsCount).
264-
WithField("transactional_count", metrics.TransactionalCount).
265-
WithField("messages_count", metrics.MessagesCount).
266-
WithField("lists_count", metrics.ListsCount).
267-
Debug("Successfully sent telemetry metrics")
268-
269225
return nil
270226
}
271227

272228
// StartDailyScheduler starts a goroutine that sends telemetry metrics daily
273229
func (t *TelemetryService) StartDailyScheduler(ctx context.Context) {
274230
if !t.enabled {
275-
t.logger.Debug("Telemetry is disabled, not starting daily scheduler")
276231
return
277232
}
278233

279234
go func() {
280235
ticker := time.NewTicker(24 * time.Hour)
281236
defer ticker.Stop()
282237

283-
t.logger.Info("Started daily telemetry scheduler")
284-
285238
for {
286239
select {
287240
case <-ctx.Done():
288-
t.logger.Info("Stopping daily telemetry scheduler")
289241
return
290242
case <-ticker.C:
291-
t.logger.Debug("Daily telemetry tick - collecting metrics")
292-
if err := t.SendMetricsForAllWorkspaces(ctx); err != nil {
293-
t.logger.WithField("error", err).Error("Failed to send daily telemetry metrics")
294-
}
243+
t.SendMetricsForAllWorkspaces(ctx)
295244
}
296245
}
297246
}()

0 commit comments

Comments
 (0)