Skip to content

Commit bd6adc4

Browse files
committed
chore(purge): improve logging
1 parent 894193c commit bd6adc4

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

functions/purge/handler.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ var (
6262
)
6363

6464
func init() {
65-
slog.Info("===== Init container =====")
65+
slog.Info("===== Runing 'init' =====")
6666
// Set log level based on environment variable
6767
var logLevel slog.Level
6868
slogLevel, err := strconv.Atoi(os.Getenv("LOG_LEVEL"))
@@ -149,7 +149,7 @@ func init() {
149149
}
150150

151151
func Handle(w http.ResponseWriter, r *http.Request) {
152-
slog.Info("===== Starting purge =====")
152+
slog.Info("===== Runing 'Handle' =====")
153153
// Get Retention date
154154
retentionDate := time.Now().AddDate(0, 0, -config.RetentionDays)
155155
slog.Info(fmt.Sprintf("Purging images older than: %s", retentionDate.Format(time.RFC3339)))
@@ -196,15 +196,15 @@ func Handle(w http.ResponseWriter, r *http.Request) {
196196
for _, tag := range tags {
197197
// Check if tag is older than retention date
198198
if tag.UpdatedAt.Before(retentionDate) {
199-
slog.Info(fmt.Sprintf("Tag %s:%s updated at %s is older than retention date %s",
199+
slog.Debug(fmt.Sprintf("Tag %s:%s updated at %s is older than retention date %s",
200200
image.Name, tag.Name, tag.UpdatedAt.Format(time.RFC3339), retentionDate.Format(time.RFC3339)))
201201

202202
// Check if tag is protected
203203
if config.PreserveTagPatterns.MatchString(tag.Name) {
204-
slog.Info(fmt.Sprintf("Tag %s match protection pattern. Preserving", tag.Name))
204+
slog.Debug(fmt.Sprintf("Tag %s match protection pattern. Preserving", tag.Name))
205205
preservedTags++
206206
} else {
207-
slog.Info(fmt.Sprintf("Tag %s doesn't match protection pattern.", tag.Name))
207+
slog.Debug(fmt.Sprintf("Tag %s doesn't match protection pattern.", tag.Name))
208208
// Delete tag if not dry run
209209
if err := registryClient.DeleteTag(context.Background(), tag); err != nil {
210210
slog.Error(fmt.Sprintf("Failed to delete tag %s (%s): %v", tag.Name, tag.ID, err))
@@ -214,7 +214,7 @@ func Handle(w http.ResponseWriter, r *http.Request) {
214214
deletedTags++
215215
}
216216
} else {
217-
slog.Info(fmt.Sprintf("Tag %s updated at %s is newer than retention date %s. Skipping",
217+
slog.Debug(fmt.Sprintf("Tag %s updated at %s is newer than retention date %s. Skipping",
218218
tag.Name, tag.UpdatedAt.Format(time.RFC3339), retentionDate.Format(time.RFC3339)))
219219
skippedTags++
220220
}
@@ -233,7 +233,7 @@ func Handle(w http.ResponseWriter, r *http.Request) {
233233
// DeleteTag deletes a tag
234234
func (r *RegistryClient) DeleteTag(ctx context.Context, tag *registry.Tag) error {
235235
if r.config.DryRun {
236-
slog.Info(fmt.Sprintf("[DRY RUN] Would delete tag: %s (%s)", tag.Name, tag.ID))
236+
slog.Debug(fmt.Sprintf("[DRY RUN] Would delete tag: %s (%s)", tag.Name, tag.ID))
237237
return nil
238238
}
239239

0 commit comments

Comments
 (0)