Use logrus for logging

This commit is contained in:
Michael Mayer 2019-05-02 14:10:05 +02:00
parent 7f41d80a1d
commit 3315b87305
26 changed files with 161 additions and 113 deletions

1
go.mod
View File

@ -47,6 +47,7 @@ require (
github.com/stretchr/testify v1.3.0
github.com/tensorflow/tensorflow v1.13.1
github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6 // indirect
github.com/toorop/gin-logrus v0.0.0-20190324082946-8887861896bb
github.com/twinj/uuid v1.0.0 // indirect
github.com/uber-go/atomic v1.3.2 // indirect
github.com/uber/jaeger-client-go v2.15.0+incompatible // indirect

2
go.sum
View File

@ -265,6 +265,8 @@ github.com/tensorflow/tensorflow v1.13.1 h1:ygn0+ztXusm6RGVP4Od5IF+8h5sAgD5qbeTv
github.com/tensorflow/tensorflow v1.13.1/go.mod h1:itOSERT4trABok4UOoG+X4BoKds9F3rIsySdn+Lvu90=
github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6 h1:lYIiVDtZnyTWlNwiAxLj0bbpTcx1BWCFhXjfsvmPdNc=
github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/toorop/gin-logrus v0.0.0-20190324082946-8887861896bb h1:tafzp7Ps8UI91PThlRjtZzQUzPh4ajZg5IyAoYDfbKc=
github.com/toorop/gin-logrus v0.0.0-20190324082946-8887861896bb/go.mod h1:X3Dd1SB8Gt1V968NTzpKFjMM6O8ccta2NPC6MprOxZQ=
github.com/twinj/uuid v0.0.0-20150629100731-70cac2bcd273/go.mod h1:mMgcE1RHFUFqe5AfiwlINXisXfDGro23fWdPUfOMjRY=
github.com/twinj/uuid v1.0.0 h1:fzz7COZnDrXGTAOHGuUGYd6sG+JMq+AoE7+Jlu0przk=
github.com/twinj/uuid v1.0.0/go.mod h1:mMgcE1RHFUFqe5AfiwlINXisXfDGro23fWdPUfOMjRY=

View File

@ -1,10 +1,11 @@
package api
import (
"log"
"net/http"
"strconv"
log "github.com/sirupsen/logrus"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/photoprism/photoprism/internal/forms"

View File

@ -2,9 +2,10 @@ package api
import (
"fmt"
"log"
"strconv"
log "github.com/sirupsen/logrus"
"github.com/gin-gonic/gin"
"github.com/photoprism/photoprism/internal/photoprism"
)

View File

@ -19,6 +19,7 @@ func configAction(ctx *cli.Context) error {
fmt.Printf("NAME VALUE\n")
fmt.Printf("debug %t\n", conf.Debug())
fmt.Printf("log-level %s\n", conf.LogLevel())
fmt.Printf("config-file %s\n", conf.ConfigFile())
fmt.Printf("app-name %s\n", conf.AppName())
fmt.Printf("app-version %s\n", conf.AppVersion())

View File

@ -1,10 +1,9 @@
package commands
import (
"fmt"
"github.com/photoprism/photoprism/internal/context"
"github.com/photoprism/photoprism/internal/photoprism"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
@ -22,13 +21,13 @@ func convertAction(ctx *cli.Context) error {
return err
}
fmt.Printf("Converting RAW images in %s to JPEG...\n", conf.OriginalsPath())
log.Infof("converting RAW images in %s to JPEG", conf.OriginalsPath())
converter := photoprism.NewConverter(conf.DarktableCli())
converter.ConvertAll(conf.OriginalsPath())
fmt.Println("Done.")
log.Infof("image conversion complete")
return nil
}

View File

@ -3,6 +3,8 @@ package commands
import (
"fmt"
log "github.com/sirupsen/logrus"
"github.com/araddon/dateparse"
"github.com/photoprism/photoprism/internal/context"
"github.com/photoprism/photoprism/internal/photoprism"
@ -48,7 +50,7 @@ func exportAction(ctx *cli.Context) error {
after := ctx.String("after")
if before == "" || after == "" {
fmt.Println("You need to provide before and after dates for export, e.g.\n\nphotoprism export --after 2018/04/10 --before '2018/04/15 23:00:00'")
log.Infoln("you need to provide before and after dates for export, e.g.\n\nphotoprism export --after 2018/04/10 --before '2018/04/15 23:00:00'")
return nil
}
@ -72,11 +74,11 @@ func exportAction(ctx *cli.Context) error {
size := ctx.Int("size")
originals := photoprism.FindOriginalsByDate(conf.OriginalsPath(), afterDate, beforeDate)
fmt.Printf("Exporting photos to %s...\n", exportPath)
log.Infof("exporting photos to %s", exportPath)
photoprism.ExportPhotosFromOriginals(originals, conf.ThumbnailsPath(), exportPath, size)
fmt.Println("Done.")
log.Infof("photo export complete")
return nil
}

View File

@ -1,10 +1,9 @@
package commands
import (
"fmt"
"github.com/photoprism/photoprism/internal/context"
"github.com/photoprism/photoprism/internal/photoprism"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
@ -24,7 +23,7 @@ func importAction(ctx *cli.Context) error {
conf.MigrateDb()
fmt.Printf("Importing photos from %s...\n", conf.ImportPath())
log.Infof("importing photos from %s", conf.ImportPath())
tensorFlow := photoprism.NewTensorFlow(conf.TensorFlowModelPath())
@ -36,7 +35,7 @@ func importAction(ctx *cli.Context) error {
importer.ImportPhotosFromDirectory(conf.ImportPath())
fmt.Println("Done.")
log.Info("photo import complete")
return nil
}

View File

@ -1,10 +1,9 @@
package commands
import (
"fmt"
"github.com/photoprism/photoprism/internal/context"
"github.com/photoprism/photoprism/internal/photoprism"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
@ -24,15 +23,15 @@ func indexAction(ctx *cli.Context) error {
conf.MigrateDb()
fmt.Printf("Indexing photos in %s...\n", conf.OriginalsPath())
log.Infof("indexing photos in %s", conf.OriginalsPath())
tensorFlow := photoprism.NewTensorFlow(conf.TensorFlowModelPath())
indexer := photoprism.NewIndexer(conf.OriginalsPath(), tensorFlow, conf.Db())
indexer.IndexAll()
files := indexer.IndexAll()
fmt.Println("Done.")
log.Infof("indexed %d files", len(files))
return nil
}

View File

@ -1,9 +1,8 @@
package commands
import (
"fmt"
"github.com/photoprism/photoprism/internal/context"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
@ -17,11 +16,11 @@ var MigrateCommand = cli.Command{
func migrateAction(ctx *cli.Context) error {
conf := context.NewConfig(ctx)
fmt.Println("Migrating database...")
log.Infoln("migrating database")
conf.MigrateDb()
fmt.Println("Done.")
log.Infoln("database migration complete")
return nil
}

View File

@ -1,8 +1,7 @@
package commands
import (
"fmt"
"log"
log "github.com/sirupsen/logrus"
"github.com/photoprism/photoprism/internal/context"
"github.com/photoprism/photoprism/internal/server"
@ -42,7 +41,7 @@ func startAction(ctx *cli.Context) error {
conf := context.NewConfig(ctx)
if conf.HttpServerPort() < 1 {
log.Fatal("Server port must be a positive integer")
log.Fatal("server port must be a positive integer")
}
if err := conf.CreateDirectories(); err != nil {
@ -51,11 +50,9 @@ func startAction(ctx *cli.Context) error {
conf.MigrateDb()
fmt.Printf("Starting web server at %s:%d...\n", ctx.String("http-host"), ctx.Int("http-port"))
log.Infof("starting web server at %s:%d", conf.HttpServerHost(), conf.HttpServerPort())
server.Start(conf)
fmt.Println("Done.")
return nil
}

View File

@ -1,10 +1,9 @@
package commands
import (
"fmt"
"github.com/photoprism/photoprism/internal/context"
"github.com/photoprism/photoprism/internal/photoprism"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
@ -36,7 +35,7 @@ func thumbnailsAction(ctx *cli.Context) error {
return err
}
fmt.Printf("Creating thumbnails in %s...\n", conf.ThumbnailsPath())
log.Infof("creating thumbnails in %s", conf.ThumbnailsPath())
sizes := ctx.IntSlice("size")
@ -45,7 +44,7 @@ func thumbnailsAction(ctx *cli.Context) error {
}
if len(sizes) == 0 {
fmt.Println("No sizes selected. Nothing to do.")
log.Warn("no thumbnail size selected")
return nil
}
@ -53,7 +52,7 @@ func thumbnailsAction(ctx *cli.Context) error {
photoprism.CreateThumbnailsFromOriginals(conf.OriginalsPath(), conf.ThumbnailsPath(), size, ctx.Bool("square"))
}
fmt.Println("Done.")
log.Info("thumbnails created")
return nil
}

View File

@ -1,7 +1,6 @@
package context
import (
"fmt"
"os"
"time"
@ -35,6 +34,7 @@ type Config struct {
appVersion string
appCopyright string
debug bool
logLevel string
configFile string
assetsPath string
cachePath string
@ -62,26 +62,32 @@ type Config struct {
// 2. SetValuesFromCliContext: Which comes after SetValuesFromFile and overrides
// any previous values giving an option two override file configs through the CLI.
func NewConfig(ctx *cli.Context) *Config {
log.SetLevel(log.InfoLevel)
c := &Config{}
if ctx.GlobalBool("debug") {
c.debug = ctx.GlobalBool("debug")
}
c.appName = ctx.App.Name
c.appCopyright = ctx.App.Copyright
c.appVersion = ctx.App.Version
log.SetLevel(c.LogLevel())
log.SetFormatter(&log.TextFormatter{
DisableColors: false,
FullTimestamp: true,
})
if err := c.SetValuesFromFile(fsutil.ExpandedFilename(ctx.GlobalString("config-file"))); err != nil {
log.Error(err)
log.Info(err)
}
if err := c.SetValuesFromCliContext(ctx); err != nil {
log.Error(err)
}
if c.Debug() {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.ErrorLevel)
}
log.SetLevel(c.LogLevel())
return c
}
@ -99,6 +105,10 @@ func (c *Config) SetValuesFromFile(fileName string) error {
c.debug = debug
}
if logLevel, err := yamlConfig.Get("log-level"); err == nil {
c.logLevel = logLevel
}
if sqlServerHost, err := yamlConfig.Get("sql-host"); err == nil {
c.sqlServerHost = sqlServerHost
}
@ -173,6 +183,10 @@ func (c *Config) SetValuesFromCliContext(ctx *cli.Context) error {
c.debug = ctx.GlobalBool("debug")
}
if ctx.GlobalIsSet("log-level") || c.logLevel == "" {
c.logLevel = ctx.GlobalString("log-level")
}
if ctx.GlobalIsSet("assets-path") || c.assetsPath == "" {
c.assetsPath = fsutil.ExpandedFilename(ctx.GlobalString("assets-path"))
}
@ -288,7 +302,7 @@ func (c *Config) connectToDatabase() error {
if err != nil || db == nil {
if isTiDB {
fmt.Printf("Starting database server at %s:%d...\n", c.SqlServerHost(), c.SqlServerPort())
log.Infof("starting database server at %s:%d\n", c.SqlServerHost(), c.SqlServerPort())
go tidb.Start(c.SqlServerPath(), c.SqlServerPort(), c.SqlServerHost(), c.Debug())
}
@ -306,7 +320,7 @@ func (c *Config) connectToDatabase() error {
err = tidb.InitDatabase(c.SqlServerPort(), c.SqlServerPassword())
if err != nil {
log.Println(err)
log.Debug(err)
} else {
initSuccess = true
}
@ -343,6 +357,19 @@ func (c *Config) Debug() bool {
return c.debug
}
// LogLevel returns the logrus log level.
func (c *Config) LogLevel() log.Level {
if c.Debug() {
c.logLevel = "debug"
}
if logLevel, err := log.ParseLevel(c.logLevel); err == nil {
return logLevel
} else {
return log.ErrorLevel
}
}
// ConfigFile returns the config file name.
func (c *Config) ConfigFile() string {
return c.configFile
@ -374,6 +401,10 @@ func (c *Config) SqlServerPassword() string {
// HttpServerHost returns the built-in HTTP server host name or IP address (empty for all interfaces).
func (c *Config) HttpServerHost() string {
if c.httpServerHost == "" {
return "0.0.0.0"
}
return c.httpServerHost
}

View File

@ -4,9 +4,10 @@ import (
"fmt"
"image"
"image/color"
"log"
"math"
log "github.com/sirupsen/logrus"
"github.com/disintegration/imaging"
"github.com/lucasb-eyer/go-colorful"
)

View File

@ -5,11 +5,13 @@ import (
_ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"github.com/photoprism/photoprism/internal/frontend"
"github.com/sirupsen/logrus"
)
// Config interface implemented in context (cli) and test packages
type Config interface {
Debug() bool
LogLevel() logrus.Level
Db() *gorm.DB
CreateDirectories() error

View File

@ -2,10 +2,11 @@ package photoprism
import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
log "github.com/sirupsen/logrus"
)
// Converter wraps a darktable cli binary.
@ -17,9 +18,9 @@ type Converter struct {
// cli binary location.
func NewConverter(darktableCli string) *Converter {
if stat, err := os.Stat(darktableCli); err != nil {
log.Print("Darktable CLI binary could not be found at " + darktableCli)
log.Errorf("darktable CLI binary could not be found at %s", darktableCli)
} else if stat.IsDir() {
log.Print("Darktable CLI must be a file, not a directory")
log.Error("darktable CLI must be a file, not a directory")
}
return &Converter{darktableCli: darktableCli}
@ -31,7 +32,7 @@ func (c *Converter) ConvertAll(path string) {
err := filepath.Walk(path, func(filename string, fileInfo os.FileInfo, err error) error {
if err != nil {
log.Print(err.Error())
log.Error(err.Error())
return nil
}
@ -46,14 +47,14 @@ func (c *Converter) ConvertAll(path string) {
}
if _, err := c.ConvertToJpeg(mediaFile); err != nil {
log.Print(err.Error())
log.Error(err.Error())
}
return nil
})
if err != nil {
log.Print(err.Error())
log.Error(err.Error())
}
}
@ -77,7 +78,7 @@ func (c *Converter) ConvertToJpeg(image *MediaFile) (*MediaFile, error) {
return mediaFile, nil
}
log.Printf("Converting \"%s\" to \"%s\"\n", image.filename, jpegFilename)
log.Errorf("converting \"%s\" to \"%s\"", image.filename, jpegFilename)
xmpFilename := baseFilename + ".xmp"

View File

@ -2,11 +2,12 @@ package photoprism
import (
"fmt"
"log"
"os"
"path/filepath"
"strings"
"time"
log "github.com/sirupsen/logrus"
)
// FindOriginalsByDate searches the originalsPath given a time frame in the format of
@ -45,19 +46,28 @@ func ExportPhotosFromOriginals(originals []*MediaFile, thumbnailsPath string, ex
return nil
}
log.Printf("Exporting %s as %dpx JPEG", mediaFile.GetFilename(), size)
log.Infof("exporting %s as %dpx JPEG", mediaFile.GetFilename(), size)
thumbnail, err := mediaFile.GetThumbnail(thumbnailsPath, size)
if err != nil {
log.Print(err.Error())
log.Error(err.Error())
}
os.MkdirAll(exportPath, os.ModePerm)
if thumbnail == nil {
log.Error("thumbnail is nil")
return err
}
if err := os.MkdirAll(exportPath, os.ModePerm); err != nil {
log.Error(err.Error())
}
destinationFilename := fmt.Sprintf("%s/%s_%dpx.jpg", exportPath, mediaFile.GetCanonicalName(), size)
thumbnail.Copy(destinationFilename)
if err := thumbnail.Copy(destinationFilename); err != nil {
log.Error(err.Error())
}
}
return nil

View File

@ -3,13 +3,14 @@ package photoprism
import (
"fmt"
"io"
"log"
"os"
"path"
"path/filepath"
"sort"
"strings"
log "github.com/sirupsen/logrus"
"github.com/photoprism/photoprism/internal/fsutil"
)
@ -46,7 +47,6 @@ func (i *Importer) ImportPhotosFromDirectory(importPath string) {
var destinationMainFilename string
if err != nil {
// log.Print(err.Error())
return nil
}
@ -72,7 +72,7 @@ func (i *Importer) ImportPhotosFromDirectory(importPath string) {
relatedFiles, mainFile, err := mediaFile.GetRelatedFiles()
if err != nil {
log.Printf("Could not import \"%s\": %s", mediaFile.GetRelativeFilename(importPath), err.Error())
log.Errorf("could not import \"%s\": %s", mediaFile.GetRelativeFilename(importPath), err.Error())
return nil
}
@ -83,15 +83,15 @@ func (i *Importer) ImportPhotosFromDirectory(importPath string) {
if mainFile.HasSameFilename(relatedMediaFile) {
destinationMainFilename = destinationFilename
log.Printf("Moving main %s file \"%s\" to \"%s\"", relatedMediaFile.GetType(), relatedMediaFile.GetRelativeFilename(importPath), destinationFilename)
log.Infof("moving main %s file \"%s\" to \"%s\"", relatedMediaFile.GetType(), relatedMediaFile.GetRelativeFilename(importPath), destinationFilename)
} else {
log.Printf("Moving related %s file \"%s\" to \"%s\"", relatedMediaFile.GetType(), relatedMediaFile.GetRelativeFilename(importPath), destinationFilename)
log.Infof("moving related %s file \"%s\" to \"%s\"", relatedMediaFile.GetType(), relatedMediaFile.GetRelativeFilename(importPath), destinationFilename)
}
relatedMediaFile.Move(destinationFilename)
} else if i.removeExistingFiles {
relatedMediaFile.Remove()
log.Printf("Deleted \"%s\" (already exists)", relatedMediaFile.GetRelativeFilename(importPath))
log.Infof("deleted \"%s\" (already exists)", relatedMediaFile.GetRelativeFilename(importPath))
}
}
@ -99,7 +99,7 @@ func (i *Importer) ImportPhotosFromDirectory(importPath string) {
importedMainFile, err := NewMediaFile(destinationMainFilename)
if err != nil {
log.Printf("Could not index \"%s\" after import: %s", destinationMainFilename, err.Error())
log.Errorf("could not index \"%s\" after import: %s", destinationMainFilename, err.Error())
return nil
}
@ -122,14 +122,17 @@ func (i *Importer) ImportPhotosFromDirectory(importPath string) {
// Remove empty directories from import path
for _, directory := range directories {
if directoryIsEmpty(directory) {
os.Remove(directory)
log.Printf("Deleted empty directory \"%s\"", directory)
if err := os.Remove(directory); err != nil {
log.Errorf("could not deleted empty directory \"%s\": %s", directory, err)
} else {
log.Infof("deleted empty directory \"%s\"", directory)
}
}
}
}
if err != nil {
log.Print(err.Error())
log.Error(err.Error())
}
}

View File

@ -2,19 +2,20 @@ package photoprism
import (
"fmt"
"log"
"os"
"path/filepath"
"strings"
"time"
log "github.com/sirupsen/logrus"
"github.com/jinzhu/gorm"
"github.com/photoprism/photoprism/internal/models"
)
const (
indexResultUpdated = "Updated"
indexResultAdded = "Added"
indexResultUpdated = "updated"
indexResultAdded = "added"
)
// Indexer defines an indexer with originals path tensorflow and a db.
@ -121,7 +122,7 @@ func (i *Indexer) indexMediaFile(mediaFile *MediaFile) string {
photo.PhotoTitle = fmt.Sprintf("%s / %s / %s", location.LocCounty, location.LocCountry, mediaFile.GetDateCreated().Format("2006"))
}
} else {
log.Printf("No location: %s", err)
log.Infof("no location: %s", err)
var recentPhoto models.Photo
@ -232,7 +233,7 @@ func (i *Indexer) IndexRelated(mediaFile *MediaFile) map[string]bool {
relatedFiles, mainFile, err := mediaFile.GetRelatedFiles()
if err != nil {
log.Printf("Could not index \"%s\": %s", mediaFile.GetRelativeFilename(i.originalsPath), err.Error())
log.Warnf("could not index \"%s\": %s", mediaFile.GetRelativeFilename(i.originalsPath), err.Error())
return indexed
}
@ -240,7 +241,7 @@ func (i *Indexer) IndexRelated(mediaFile *MediaFile) map[string]bool {
mainIndexResult := i.indexMediaFile(mainFile)
indexed[mainFile.GetFilename()] = true
log.Printf("%s main %s file \"%s\"", mainIndexResult, mainFile.GetType(), mainFile.GetRelativeFilename(i.originalsPath))
log.Infof("%s main %s file \"%s\"", mainIndexResult, mainFile.GetType(), mainFile.GetRelativeFilename(i.originalsPath))
for _, relatedMediaFile := range relatedFiles {
if indexed[relatedMediaFile.GetFilename()] {
@ -250,7 +251,7 @@ func (i *Indexer) IndexRelated(mediaFile *MediaFile) map[string]bool {
indexResult := i.indexMediaFile(relatedMediaFile)
indexed[relatedMediaFile.GetFilename()] = true
log.Printf("%s related %s file \"%s\"", indexResult, relatedMediaFile.GetType(), relatedMediaFile.GetRelativeFilename(i.originalsPath))
log.Infof("%s related %s file \"%s\"", indexResult, relatedMediaFile.GetType(), relatedMediaFile.GetRelativeFilename(i.originalsPath))
}
return indexed
@ -283,7 +284,7 @@ func (i *Indexer) IndexAll() map[string]bool {
})
if err != nil {
log.Print(err.Error())
log.Warn(err.Error())
}
return indexed

View File

@ -7,7 +7,6 @@ import (
_ "image/jpeg"
_ "image/png"
"io"
"log"
"math"
"net/http"
"os"
@ -16,6 +15,8 @@ import (
"strings"
"time"
log "github.com/sirupsen/logrus"
"github.com/djherbis/times"
"github.com/photoprism/photoprism/internal/fsutil"
"github.com/photoprism/photoprism/internal/models"
@ -151,7 +152,7 @@ func (m *MediaFile) GetDateCreated() time.Time {
t, err := times.Stat(m.GetFilename())
if err != nil {
log.Println(err.Error())
log.Debug(err.Error())
return m.dateCreated
}
@ -375,7 +376,7 @@ func (m *MediaFile) GetMimeType() string {
handle, err := m.openFile()
if err != nil {
log.Println("Error: Could not open file to determine mime type")
log.Errorf("could not read file to determine mime type: %s", m.GetFilename())
return ""
}
@ -387,7 +388,7 @@ func (m *MediaFile) GetMimeType() string {
_, err = handle.Read(buffer)
if err != nil {
log.Println("Error: Could not read file to determine mime type: " + m.GetFilename())
log.Errorf("could not read file to determine mime type: %s", m.GetFilename())
return ""
}
@ -399,7 +400,7 @@ func (m *MediaFile) GetMimeType() string {
func (m *MediaFile) openFile() (*os.File, error) {
handle, err := os.Open(m.filename)
if err != nil {
log.Println(err.Error())
log.Error(err.Error())
return nil, err
}
return handle, nil
@ -437,7 +438,7 @@ func (m *MediaFile) Copy(destinationFilename string) error {
file, err := m.openFile()
if err != nil {
log.Println(err.Error())
log.Error(err.Error())
return err
}
@ -446,7 +447,7 @@ func (m *MediaFile) Copy(destinationFilename string) error {
destination, err := os.OpenFile(destinationFilename, os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
log.Println(err.Error())
log.Error(err.Error())
return err
}
@ -455,7 +456,7 @@ func (m *MediaFile) Copy(destinationFilename string) error {
_, err = io.Copy(destination, file)
if err != nil {
log.Println(err.Error())
log.Error(err.Error())
return err
}

View File

@ -6,7 +6,6 @@ import (
"errors"
"image"
"io/ioutil"
"log"
"math"
"os"
"sort"
@ -45,12 +44,6 @@ func (a TensorFlowLabels) Len() int { return len(a) }
func (a TensorFlowLabels) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a TensorFlowLabels) Less(i, j int) bool { return a[i].Probability > a[j].Probability }
func (t *TensorFlow) closeSession(s *tf.Session) {
if err := s.Close(); err != nil {
log.Print(err)
}
}
// GetImageTagsFromFile returns tags for a jpeg image file.
func (t *TensorFlow) GetImageTagsFromFile(filename string) (result []TensorFlowLabel, err error) {
imageBuffer, err := ioutil.ReadFile(filename)

View File

@ -2,11 +2,12 @@ package photoprism
import (
"fmt"
"log"
"os"
"path/filepath"
"strings"
log "github.com/sirupsen/logrus"
"github.com/disintegration/imaging"
"github.com/photoprism/photoprism/internal/fsutil"
)
@ -26,15 +27,15 @@ func CreateThumbnailsFromOriginals(originalsPath string, thumbnailsPath string,
if square {
if thumbnail, err := mediaFile.GetSquareThumbnail(thumbnailsPath, size); err != nil {
log.Printf("Could not create thumbnail: %s", err.Error())
log.Errorf("could not create thumbnail: %s", err.Error())
} else {
log.Printf("Created %dx%d px thumbnail for \"%s\"", thumbnail.GetWidth(), thumbnail.GetHeight(), mediaFile.GetRelativeFilename(originalsPath))
log.Infof("created %dx%d px thumbnail for \"%s\"", thumbnail.GetWidth(), thumbnail.GetHeight(), mediaFile.GetRelativeFilename(originalsPath))
}
} else {
if thumbnail, err := mediaFile.GetThumbnail(thumbnailsPath, size); err != nil {
log.Printf("Could not create thumbnail: %s", err.Error())
log.Errorf("could not create thumbnail: %s", err.Error())
} else {
log.Printf("Created %dx%d px thumbnail for \"%s\"", thumbnail.GetWidth(), thumbnail.GetHeight(), mediaFile.GetRelativeFilename(originalsPath))
log.Infof("created %dx%d px thumbnail for \"%s\"", thumbnail.GetWidth(), thumbnail.GetHeight(), mediaFile.GetRelativeFilename(originalsPath))
}
}
@ -42,7 +43,7 @@ func CreateThumbnailsFromOriginals(originalsPath string, thumbnailsPath string,
})
if err != nil {
log.Print(err.Error())
log.Error(err.Error())
}
}
@ -69,7 +70,7 @@ func (m *MediaFile) CreateThumbnail(filename string, size int) (result *MediaFil
img, err := imaging.Open(m.filename, imaging.AutoOrientation(true))
if err != nil {
log.Printf("can't open original: %s", err.Error())
log.Errorf("can't open original: %s", err.Error())
return nil, err
}
@ -108,7 +109,7 @@ func (m *MediaFile) CreateSquareThumbnail(filename string, size int) (result *Me
img, err := imaging.Open(m.filename, imaging.AutoOrientation(true))
if err != nil {
log.Printf("can't open original: %s", err.Error())
log.Errorf("can't open original: %s", err.Error())
return nil, err
}

View File

@ -16,7 +16,8 @@ func Start(conf photoprism.Config) {
gin.SetMode(gin.ReleaseMode)
}
app := gin.Default()
app := gin.New()
app.Use(gin.Logger(), gin.Recovery())
// Set template directory
app.LoadHTMLGlob(conf.HttpTemplatesPath() + "/*")

View File

@ -2,11 +2,12 @@ package test
import (
"fmt"
"log"
"os"
"testing"
"time"
log "github.com/sirupsen/logrus"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/jinzhu/gorm/dialects/sqlite"
@ -173,6 +174,11 @@ func (c *Config) Debug() bool {
return false
}
// LogLevel returns the logrus log level.
func (c *Config) LogLevel() log.Level {
return log.DebugLevel
}
// ConfigFile returns the config file name.
func (c *Config) ConfigFile() string {
return ConfigFile

View File

@ -8,44 +8,41 @@ import (
)
func InitDatabase(port uint, password string) error {
log.Print("init database: trying login without password")
log.Info("init database: trying login without password")
db, err := sql.Open("mysql", fmt.Sprintf("root:@tcp(localhost:%d)/", port))
defer db.Close()
if err != nil {
log.Print(err)
log.Print("init database: login as root with password")
log.Debugf("init database: %s", err)
log.Debug("init database: login as root with password")
db, err = sql.Open("mysql", fmt.Sprintf("root:%s@tcp(localhost:%d)/", password, port))
}
if err != nil {
log.Print(err)
log.Error(err)
return err
}
log.Print("init database: login was successful")
log.Debug("init database: login was successful")
_, err = db.Exec(fmt.Sprintf("SET PASSWORD FOR 'root'@'%%' = '%s'", password))
if err != nil {
log.Print(err)
log.Error(err)
} else {
log.Print("init database: FLUSH PRIVILEGES")
log.Debug("init database: FLUSH PRIVILEGES")
_, err = db.Exec("FLUSH PRIVILEGES")
log.Print(err)
}
log.Printf("init database: CREATE DATABASE IF NOT EXISTS photoprism")
log.Debug("init database: CREATE DATABASE IF NOT EXISTS photoprism")
_, err = db.Exec("CREATE DATABASE IF NOT EXISTS photoprism")
if err != nil {
log.Print(err)
log.Error(err)
}
return nil

View File

@ -106,7 +106,7 @@ func Start(path string, port uint, host string, debug bool) {
}
setupBinlogClient()
setupMetrics()
// setupMetrics()
createStoreAndDomain()
createServer()
signal.SetupSignalHandler(serverShutdown)