Skip to content

Commit 9a88d7f

Browse files
committed
Logs: Tweak messages and log levels for improved readability
1 parent 8ebedf2 commit 9a88d7f

32 files changed

Lines changed: 123 additions & 116 deletions

internal/api/album.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,10 +526,10 @@ func DownloadAlbum(router *gin.RouterGroup) {
526526
}
527527
log.Infof("download: added %s as %s", txt.Quote(file.FileName), txt.Quote(alias))
528528
} else {
529-
log.Errorf("download: file %s is missing", txt.Quote(file.FileName))
529+
log.Errorf("download: failed finding %s", txt.Quote(file.FileName))
530530
}
531531
}
532532

533-
log.Infof("download: album zip %s created in %s", txt.Quote(zipFileName), time.Since(start))
533+
log.Infof("download: created %s in %s", txt.Quote(zipFileName), time.Since(start))
534534
})
535535
}

internal/api/api.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ func logError(prefix string, err error) {
4949
}
5050
}
5151

52+
func logWarn(prefix string, err error) {
53+
if err != nil {
54+
log.Warnf("%s: %s", prefix, err.Error())
55+
}
56+
}
57+
5258
func UpdateClientConfig() {
5359
conf := service.Config()
5460

internal/api/batch.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ func BatchPhotosArchive(router *gin.RouterGroup) {
6666
}
6767

6868
// Update precalculated photo and file counts.
69-
logError("photos", entity.UpdatePhotoCounts())
69+
logWarn("index", entity.UpdateCounts())
7070

7171
// Update album, subject, and label cover thumbs.
72-
logError("photos", query.UpdateCovers())
72+
logWarn("index", query.UpdateCovers())
7373

7474
UpdateClientConfig()
7575

@@ -128,10 +128,10 @@ func BatchPhotosRestore(router *gin.RouterGroup) {
128128
}
129129

130130
// Update precalculated photo and file counts.
131-
logError("photos", entity.UpdatePhotoCounts())
131+
logWarn("index", entity.UpdateCounts())
132132

133133
// Update album, subject, and label cover thumbs.
134-
logError("photos", query.UpdateCovers())
134+
logWarn("index", query.UpdateCovers())
135135

136136
UpdateClientConfig()
137137

@@ -264,7 +264,7 @@ func BatchPhotosPrivate(router *gin.RouterGroup) {
264264
}
265265

266266
// Update precalculated photo and file counts.
267-
logError("photos", entity.UpdatePhotoCounts())
267+
logWarn("index", entity.UpdateCounts())
268268

269269
if photos, err := query.PhotoSelection(f); err == nil {
270270
for _, p := range photos {
@@ -382,7 +382,7 @@ func BatchPhotosDelete(router *gin.RouterGroup) {
382382
// Any photos deleted?
383383
if len(deleted) > 0 {
384384
// Update precalculated photo and file counts.
385-
logError("photos", entity.UpdatePhotoCounts())
385+
logWarn("index", entity.UpdateCounts())
386386

387387
UpdateClientConfig()
388388

internal/api/import.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func StartImport(router *gin.RouterGroup) {
113113

114114
// Update album, label, and subject cover thumbs.
115115
if err := query.UpdateCovers(); err != nil {
116-
log.Errorf("import: %s (update covers)", err)
116+
log.Warnf("index: %s (update covers)", err)
117117
}
118118

119119
c.JSON(http.StatusOK, i18n.Response{Code: http.StatusOK, Msg: msg})

internal/api/zip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func CreateZip(router *gin.RouterGroup) {
126126

127127
elapsed := int(time.Since(start).Seconds())
128128

129-
log.Infof("download: zip %s created in %s", txt.Quote(zipBaseName), time.Since(start))
129+
log.Infof("download: created %s in %s", txt.Quote(zipBaseName), time.Since(start))
130130

131131
c.JSON(http.StatusOK, gin.H{"code": http.StatusOK, "message": i18n.Msg(i18n.MsgZipCreatedIn, elapsed), "filename": zipBaseName})
132132
})

internal/commands/cleanup.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"time"
66

7+
"github.com/dustin/go-humanize/english"
8+
79
"github.com/urfave/cli"
810

911
"github.com/photoprism/photoprism/internal/config"
@@ -55,9 +57,7 @@ func cleanUpAction(ctx *cli.Context) error {
5557
if thumbs, orphans, err := w.Start(opt); err != nil {
5658
return err
5759
} else {
58-
elapsed := time.Since(start)
59-
60-
log.Infof("cleanup: removed %d index entries and %d orphan thumbnails in %s", orphans, thumbs, elapsed)
60+
log.Infof("cleanup: removed %s and %s [%s]", english.Plural(orphans, "index entry", "index entries"), english.Plural(thumbs, "thumbnail", "thumbnails"), time.Since(start))
6161
}
6262

6363
conf.Shutdown()

internal/commands/faces.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"strings"
77
"time"
88

9+
"github.com/dustin/go-humanize/english"
10+
911
"github.com/manifoldco/promptui"
1012
"github.com/urfave/cli"
1113

@@ -270,13 +272,13 @@ func facesIndexAction(ctx *cli.Context) error {
270272
if files, photos, err := w.Start(opt); err != nil {
271273
log.Error(err)
272274
} else if len(files) > 0 || len(photos) > 0 {
273-
log.Infof("purge: removed %d files and %d photos", len(files), len(photos))
275+
log.Infof("purge: removed %s and %s", english.Plural(len(files), "file", "files"), english.Plural(len(photos), "photo", "photos"))
274276
}
275277
}
276278

277279
elapsed := time.Since(start)
278280

279-
log.Infof("indexed %d files in %s", len(indexed), elapsed)
281+
log.Infof("indexed %d files [%s]", len(indexed), elapsed)
280282

281283
conf.Shutdown()
282284

@@ -341,7 +343,7 @@ func facesOptimizeAction(ctx *cli.Context) error {
341343
} else {
342344
elapsed := time.Since(start)
343345

344-
log.Infof("%d face clusters merged in %s", res.Merged, elapsed)
346+
log.Infof("%d face clusters merged [%s]", res.Merged, elapsed)
345347
}
346348

347349
conf.Shutdown()

internal/commands/index.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"strings"
77
"time"
88

9+
"github.com/dustin/go-humanize/english"
10+
911
"github.com/urfave/cli"
1012

1113
"github.com/photoprism/photoprism/internal/config"
@@ -78,6 +80,7 @@ func indexAction(ctx *cli.Context) error {
7880
}
7981

8082
if w := service.Purge(); w != nil {
83+
purgeStart := time.Now()
8184
opt := photoprism.PurgeOptions{
8285
Path: subPath,
8386
Ignore: indexed,
@@ -86,11 +89,12 @@ func indexAction(ctx *cli.Context) error {
8689
if files, photos, err := w.Start(opt); err != nil {
8790
log.Error(err)
8891
} else if len(files) > 0 || len(photos) > 0 {
89-
log.Infof("purge: removed %d files and %d photos", len(files), len(photos))
92+
log.Infof("purge: removed %s and %s [%s]", english.Plural(len(files), "file", "files"), english.Plural(len(photos), "photo", "photos"), time.Since(purgeStart))
9093
}
9194
}
9295

9396
if ctx.Bool("cleanup") {
97+
cleanupStart := time.Now()
9498
w := service.CleanUp()
9599

96100
opt := photoprism.CleanUpOptions{
@@ -100,13 +104,13 @@ func indexAction(ctx *cli.Context) error {
100104
if thumbs, orphans, err := w.Start(opt); err != nil {
101105
return err
102106
} else {
103-
log.Infof("cleanup: removed %d index entries and %d orphan thumbnails", orphans, thumbs)
107+
log.Infof("cleanup: removed %s and %s [%s]", english.Plural(orphans, "index entry", "index entries"), english.Plural(thumbs, "thumbnail", "thumbnails"), time.Since(cleanupStart))
104108
}
105109
}
106110

107111
elapsed := time.Since(start)
108112

109-
log.Infof("indexed %d files in %s", len(indexed), elapsed)
113+
log.Infof("indexed %d files [%s]", len(indexed), elapsed)
110114

111115
conf.Shutdown()
112116

internal/commands/index_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ func TestIndexCommand(t *testing.T) {
4949
assert.Contains(t, output, "indexing originals")
5050
assert.Contains(t, output, "classify: loading labels")
5151
assert.Contains(t, output, "index: no .ppignore file found")
52-
assert.Contains(t, output, "searching index for unassigned primary files")
53-
assert.Contains(t, output, "searching index for hidden media files")
54-
assert.Contains(t, output, "updating photo counts")
52+
assert.Contains(t, output, "index: updating primary files")
53+
assert.Contains(t, output, "index: flagging hidden files")
5554
} else {
5655
t.Fatal("log output missing")
5756
}

internal/commands/migrate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func migrateAction(ctx *cli.Context) error {
3535

3636
elapsed := time.Since(start)
3737

38-
log.Infof("database migration completed in %s", elapsed)
38+
log.Infof("database migration completed [%s]", elapsed)
3939

4040
conf.Shutdown()
4141

0 commit comments

Comments
 (0)