Use seelog instead of the default log pkg
This commit is contained in:
parent
725b1d8951
commit
bbbd35e928
6 changed files with 34 additions and 22 deletions
4
README
4
README
|
@ -25,7 +25,9 @@ Under Debian Wheezy you can simply run:
|
|||
|
||||
Yo also need to install go dependences:
|
||||
|
||||
# go get labix.org/v2/mgo/bson labix.org/v2/mgo/ github.com/gorilla/sessions github.com/gorilla/securecookie github.com/gorilla/mux github.com/nfnt/resize
|
||||
# go get labix.org/v2/mgo/bson labix.org/v2/mgo/ github.com/gorilla/sessions \
|
||||
github.com/gorilla/securecookie github.com/gorilla/mux \
|
||||
github.com/nfnt/resize github.com/cihub/seelog
|
||||
|
||||
== Installation ==
|
||||
=== For admins ("for developers" below) ===
|
||||
|
|
5
admin.go
5
admin.go
|
@ -1,9 +1,10 @@
|
|||
package main
|
||||
|
||||
import log "github.com/cihub/seelog"
|
||||
|
||||
import (
|
||||
"github.com/gorilla/mux"
|
||||
"labix.org/v2/mgo/bson"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -224,7 +225,7 @@ func storeHandler(h handler) {
|
|||
book := books[0]
|
||||
if err != nil {
|
||||
h.sess.Notify("An error ocurred!", err.Error(), "error")
|
||||
log.Println("Error storing book '", book.Title, "': ", err.Error())
|
||||
log.Error("Error storing book '", book.Title, "': ", err.Error())
|
||||
continue
|
||||
}
|
||||
h.db.UpdateBook(id, bson.M{"active": true})
|
||||
|
|
16
cover.go
16
cover.go
|
@ -1,5 +1,6 @@
|
|||
package main
|
||||
|
||||
import log "github.com/cihub/seelog"
|
||||
import _ "image/png"
|
||||
import _ "image/jpeg"
|
||||
import _ "image/gif"
|
||||
|
@ -15,7 +16,6 @@ import (
|
|||
"io/ioutil"
|
||||
"labix.org/v2/mgo"
|
||||
"labix.org/v2/mgo/bson"
|
||||
"log"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
@ -49,7 +49,7 @@ func coverHandler(h handler) {
|
|||
f, err = fs.OpenId(book.Cover)
|
||||
}
|
||||
if err != nil {
|
||||
log.Println("Error while opening image:", err)
|
||||
log.Error("Error while opening image:", err)
|
||||
notFound(h)
|
||||
return
|
||||
}
|
||||
|
@ -145,14 +145,14 @@ func storeImg(img io.Reader, title string, db *DB) (bson.ObjectId, bson.ObjectId
|
|||
/* open the files */
|
||||
fBig, err := createCoverFile(title, db)
|
||||
if err != nil {
|
||||
log.Println("Error creating", title, ":", err.Error())
|
||||
log.Error("Error creating", title, ":", err.Error())
|
||||
return "", ""
|
||||
}
|
||||
defer fBig.Close()
|
||||
|
||||
fSmall, err := createCoverFile(title+"_small", db)
|
||||
if err != nil {
|
||||
log.Println("Error creating", title+"_small", ":", err.Error())
|
||||
log.Error("Error creating", title+"_small", ":", err.Error())
|
||||
return "", ""
|
||||
}
|
||||
defer fSmall.Close()
|
||||
|
@ -163,22 +163,22 @@ func storeImg(img io.Reader, title string, db *DB) (bson.ObjectId, bson.ObjectId
|
|||
jpgOptions := jpeg.Options{IMG_QUALITY}
|
||||
imgResized, err := resizeImg(img1, IMG_WIDTH_BIG)
|
||||
if err != nil {
|
||||
log.Println("Error resizing big image:", err.Error())
|
||||
log.Error("Error resizing big image:", err.Error())
|
||||
return "", ""
|
||||
}
|
||||
err = jpeg.Encode(fBig, imgResized, &jpgOptions)
|
||||
if err != nil {
|
||||
log.Println("Error encoding big image:", err.Error())
|
||||
log.Error("Error encoding big image:", err.Error())
|
||||
return "", ""
|
||||
}
|
||||
imgSmallResized, err := resizeImg(&img2, IMG_WIDTH_SMALL)
|
||||
if err != nil {
|
||||
log.Println("Error resizing small image:", err.Error())
|
||||
log.Error("Error resizing small image:", err.Error())
|
||||
return "", ""
|
||||
}
|
||||
err = jpeg.Encode(fSmall, imgSmallResized, &jpgOptions)
|
||||
if err != nil {
|
||||
log.Println("Error encoding small image:", err.Error())
|
||||
log.Error("Error encoding small image:", err.Error())
|
||||
return "", ""
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package main
|
||||
|
||||
import log "github.com/cihub/seelog"
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
@ -23,6 +25,9 @@ func periodicTask(task func() error, periodicity time.Duration) {
|
|||
func tasker(task func() error, periodicity time.Duration) {
|
||||
for true {
|
||||
time.Sleep(periodicity)
|
||||
task()
|
||||
err := task()
|
||||
if err != nil {
|
||||
log.Error("Task error:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
11
trantor.go
11
trantor.go
|
@ -1,10 +1,11 @@
|
|||
package main
|
||||
|
||||
import log "github.com/cihub/seelog"
|
||||
|
||||
import (
|
||||
"github.com/gorilla/mux"
|
||||
"io"
|
||||
"labix.org/v2/mgo/bson"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
@ -31,7 +32,7 @@ func logoutHandler(h handler) {
|
|||
h.sess.LogOut()
|
||||
h.sess.Notify("Log out!", "Bye bye "+h.sess.User, "success")
|
||||
h.sess.Save(h.w, h.r)
|
||||
log.Println("User", h.sess.User, "log out")
|
||||
log.Info("User", h.sess.User, "log out")
|
||||
http.Redirect(h.w, h.r, "/", http.StatusFound)
|
||||
}
|
||||
|
||||
|
@ -39,11 +40,11 @@ func loginHandler(h handler) {
|
|||
user := h.r.FormValue("user")
|
||||
pass := h.r.FormValue("pass")
|
||||
if h.db.UserValid(user, pass) {
|
||||
log.Println("User", user, "log in")
|
||||
log.Info("User", user, "log in")
|
||||
h.sess.LogIn(user)
|
||||
h.sess.Notify("Successful login!", "Welcome "+user, "success")
|
||||
} else {
|
||||
log.Println("User", user, "bad user or password")
|
||||
log.Warn("User", user, "bad user or password")
|
||||
h.sess.Notify("Invalid login!", "user or password invalid", "error")
|
||||
}
|
||||
h.sess.Save(h.w, h.r)
|
||||
|
@ -145,6 +146,8 @@ func notFound(h handler) {
|
|||
}
|
||||
|
||||
func main() {
|
||||
defer log.Flush()
|
||||
|
||||
db := initDB()
|
||||
defer db.Close()
|
||||
|
||||
|
|
13
upload.go
13
upload.go
|
@ -1,10 +1,11 @@
|
|||
package main
|
||||
|
||||
import log "github.com/cihub/seelog"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"git.gitorious.org/go-pkg/epubgo.git"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"mime/multipart"
|
||||
"strings"
|
||||
)
|
||||
|
@ -35,7 +36,7 @@ func processFile(req uploadRequest, db *DB) {
|
|||
|
||||
epub, err := openMultipartEpub(req.file)
|
||||
if err != nil {
|
||||
log.Println("Not valid epub uploaded file", req.filename, ":", err)
|
||||
log.Warn("Not valid epub uploaded file", req.filename, ":", err)
|
||||
return
|
||||
}
|
||||
defer epub.Close()
|
||||
|
@ -45,7 +46,7 @@ func processFile(req uploadRequest, db *DB) {
|
|||
req.file.Seek(0, 0)
|
||||
id, size, err := StoreNewFile(title+".epub", req.file, db)
|
||||
if err != nil {
|
||||
log.Println("Error storing book (", title, "):", err)
|
||||
log.Error("Error storing book (", title, "):", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -53,10 +54,10 @@ func processFile(req uploadRequest, db *DB) {
|
|||
book["filesize"] = size
|
||||
err = db.InsertBook(book)
|
||||
if err != nil {
|
||||
log.Println("Error storing metadata (", title, "):", err)
|
||||
log.Error("Error storing metadata (", title, "):", err)
|
||||
return
|
||||
}
|
||||
log.Println("File uploaded:", req.filename)
|
||||
log.Info("File uploaded:", req.filename)
|
||||
}
|
||||
|
||||
func uploadPostHandler(h handler) {
|
||||
|
@ -67,7 +68,7 @@ func uploadPostHandler(h handler) {
|
|||
for _, f := range filesForm {
|
||||
file, err := f.Open()
|
||||
if err != nil {
|
||||
log.Println("Can not open uploaded file", f.Filename, ":", err)
|
||||
log.Error("Can not open uploaded file", f.Filename, ":", err)
|
||||
h.sess.Notify("Upload problem!", "There was a problem with book "+f.Filename, "error")
|
||||
problem = true
|
||||
continue
|
||||
|
|
Reference in a new issue