Skip to content

Commit

Permalink
✨ Rewrite logging
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Nov 9, 2017
1 parent c327b56 commit e439ab9
Show file tree
Hide file tree
Showing 36 changed files with 129 additions and 160 deletions.
3 changes: 1 addition & 2 deletions controller/archivectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/b3log/pipe/service"
"github.com/b3log/pipe/util"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)

func showArchivesAction(c *gin.Context) {
Expand Down Expand Up @@ -67,7 +66,7 @@ func showArchiveArticlesAction(c *gin.Context) {

authorModel := service.User.GetUser(articleModel.AuthorID)
if nil == authorModel {
log.Errorf("not found author of article [id=%d, authorID=%d]", articleModel.ID, articleModel.AuthorID)
logger.Errorf("not found author of article [id=%d, authorID=%d]", articleModel.ID, articleModel.AuthorID)

continue
}
Expand Down
7 changes: 3 additions & 4 deletions controller/articlectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/b3log/pipe/service"
"github.com/b3log/pipe/util"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"github.com/vinta/pangu"
)

Expand All @@ -51,7 +50,7 @@ func showArticlesAction(c *gin.Context) {

authorModel := service.User.GetUser(articleModel.AuthorID)
if nil == authorModel {
log.Errorf("not found author of article [id=%d, authorID=%d]", articleModel.ID, articleModel.AuthorID)
logger.Errorf("not found author of article [id=%d, authorID=%d]", articleModel.ID, articleModel.AuthorID)

continue
}
Expand Down Expand Up @@ -129,7 +128,7 @@ func showArticleAction(c *gin.Context) {
for _, commentModel := range commentModels {
commentAuthor := service.User.GetUser(commentModel.AuthorID)
if nil == commentAuthor {
log.Errorf("not found comment author [userID=%d]", commentModel.AuthorID)
logger.Errorf("not found comment author [userID=%d]", commentModel.AuthorID)

continue
}
Expand Down Expand Up @@ -188,7 +187,7 @@ func showArticleAction(c *gin.Context) {

authorModel := service.User.GetUser(articleModel.AuthorID)
if nil == authorModel {
log.Errorf("not found author of article [id=%d, authorID=%d]", articleModel.ID, articleModel.AuthorID)
logger.Errorf("not found author of article [id=%d, authorID=%d]", articleModel.ID, articleModel.AuthorID)

continue
}
Expand Down
5 changes: 2 additions & 3 deletions controller/b3midware.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/b3log/pipe/util"
"github.com/gin-gonic/gin"
"github.com/parnurzeal/gorequest"
log "github.com/sirupsen/logrus"
)

type DataModel map[string]interface{}
Expand Down Expand Up @@ -71,7 +70,7 @@ func fillUser(c *gin.Context) {
_, _, errs := request.Get(util.HacPaiURL+"/apis/check-b3-identity?b3id="+b3id).
Set("user-agent", util.UserAgent).Timeout(30 * time.Second).EndStruct(result)
if nil != errs {
log.Errorf("check b3 identity failed: %s", errs)
logger.Errorf("check b3 identity failed: %s", errs)
c.Next()

return
Expand Down Expand Up @@ -114,7 +113,7 @@ func fillUser(c *gin.Context) {
Role: session.URole,
}
if err := service.User.AddUser(user); nil != err {
log.Errorf("add user [name=%s] failed: %s", username, err.Error())
logger.Errorf("add user [name=%s] failed: %s", username, err.Error())
}
session.UID = user.ID
}
Expand Down
11 changes: 5 additions & 6 deletions controller/blogmidware.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/b3log/pipe/util"
"github.com/dustin/go-humanize"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)

func resolveBlog(c *gin.Context) {
Expand Down Expand Up @@ -105,7 +104,7 @@ func fillCommon(c *gin.Context) {
for _, statistic := range statistics {
count, err := strconv.Atoi(statistic.Value)
if nil != err {
log.Errorf("statistic [%s] should be an integer, actual is [%v]", statistic.Name, statistic.Value)
logger.Errorf("statistic [%s] should be an integer, actual is [%v]", statistic.Name, statistic.Value)
}
statisticMap[strings.Title(statistic.Name)] = count
statisticMap[statistic.Name] = count
Expand Down Expand Up @@ -149,7 +148,7 @@ func fillMostUseCategories(settingMap *map[string]interface{}, dataModel *DataMo
func fillMostUseTags(settingMap *map[string]interface{}, dataModel *DataModel, blogID uint) {
tagSize, err := strconv.Atoi((*settingMap)[model.SettingNamePreferenceMostUseTagListSize].(string))
if nil != err {
log.Errorf("setting [%s] should be an integer, actual is [%v]", model.SettingNamePreferenceMostUseTagListSize,
logger.Errorf("setting [%s] should be an integer, actual is [%v]", model.SettingNamePreferenceMostUseTagListSize,
(*settingMap)[model.SettingNamePreferenceMostUseTagListSize])
tagSize = model.SettingPreferenceMostUseTagListSizeDefault
}
Expand All @@ -168,7 +167,7 @@ func fillMostUseTags(settingMap *map[string]interface{}, dataModel *DataModel, b
func fillMostViewArticles(settingMap *map[string]interface{}, dataModel *DataModel, blogID uint) {
mostViewArticleSize, err := strconv.Atoi((*settingMap)[model.SettingNamePreferenceMostViewArticleListSize].(string))
if nil != err {
log.Errorf("setting [%s] should be an integer, actual is [%v]", model.SettingNamePreferenceMostViewArticleListSize,
logger.Errorf("setting [%s] should be an integer, actual is [%v]", model.SettingNamePreferenceMostViewArticleListSize,
(*settingMap)[model.SettingNamePreferenceMostViewArticleListSize])
mostViewArticleSize = model.SettingPreferenceMostViewArticleListSizeDefault
}
Expand All @@ -195,7 +194,7 @@ func fillMostViewArticles(settingMap *map[string]interface{}, dataModel *DataMod
func fillRecentComments(settingMap *map[string]interface{}, dataModel *DataModel, blogID uint) {
recentCommentSize, err := strconv.Atoi((*settingMap)[model.SettingNamePreferenceRecentCommentListSize].(string))
if nil != err {
log.Errorf("setting [%s] should be an integer, actual is [%v]", model.SettingNamePreferenceRecentCommentListSize,
logger.Errorf("setting [%s] should be an integer, actual is [%v]", model.SettingNamePreferenceRecentCommentListSize,
(*settingMap)[model.SettingNamePreferenceRecentCommentListSize])
recentCommentSize = model.SettingPreferenceRecentCommentListSizeDefault
}
Expand All @@ -222,7 +221,7 @@ func fillRecentComments(settingMap *map[string]interface{}, dataModel *DataModel
func fillMostCommentArticles(settingMap *map[string]interface{}, dataModel *DataModel, blogID uint) {
mostCommentArticleSize, err := strconv.Atoi((*settingMap)[model.SettingNamePreferenceMostCommentArticleListSize].(string))
if nil != err {
log.Errorf("setting [%s] should be an integer, actual is [%v]", model.SettingNamePreferenceMostCommentArticleListSize,
logger.Errorf("setting [%s] should be an integer, actual is [%v]", model.SettingNamePreferenceMostCommentArticleListSize,
(*settingMap)[model.SettingNamePreferenceMostCommentArticleListSize])
mostCommentArticleSize = model.SettingPreferenceMostCommentArticleListSizeDefault
}
Expand Down
3 changes: 1 addition & 2 deletions controller/categoryctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/b3log/pipe/service"
"github.com/b3log/pipe/util"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)

func showCategoriesAction(c *gin.Context) {
Expand Down Expand Up @@ -79,7 +78,7 @@ func showCategoryArticlesArticlesAction(c *gin.Context) {

authorModel := service.User.GetUser(articleModel.AuthorID)
if nil == authorModel {
log.Errorf("not found author of article [id=%d, authorID=%d]", articleModel.ID, articleModel.AuthorID)
logger.Errorf("not found author of article [id=%d, authorID=%d]", articleModel.ID, articleModel.AuthorID)

continue
}
Expand Down
5 changes: 2 additions & 3 deletions controller/commentctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/b3log/pipe/service"
"github.com/b3log/pipe/util"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)

func getRepliesAction(c *gin.Context) {
Expand All @@ -44,7 +43,7 @@ func getRepliesAction(c *gin.Context) {
for _, replyComment := range replyComments {
commentAuthor := service.User.GetUser(replyComment.AuthorID)
if nil == commentAuthor {
log.Errorf("not found comment author [userID=%d]", replyComment.AuthorID)
logger.Errorf("not found comment author [userID=%d]", replyComment.AuthorID)

continue
}
Expand Down Expand Up @@ -127,7 +126,7 @@ func addCommentAction(c *gin.Context) {

htmlBuilder := bytes.Buffer{}
if err := t.ExecuteTemplate(&htmlBuilder, "comment/comment", dataModel); nil != err {
log.Errorf("execute comment template failed: " + err.Error())
logger.Errorf("execute comment template failed: " + err.Error())

return
}
Expand Down
12 changes: 8 additions & 4 deletions controller/console/articlectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ package console

import (
"net/http"
"os"
"strconv"
"strings"

"github.com/b3log/pipe/log"
"github.com/b3log/pipe/model"
"github.com/b3log/pipe/service"
"github.com/b3log/pipe/util"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)

// Logger
var logger = log.NewLogger(os.Stdout)

func AddArticleAction(c *gin.Context) {
result := util.NewResult()
defer c.JSON(http.StatusOK, result)
Expand Down Expand Up @@ -94,14 +98,14 @@ func GetArticlesAction(c *gin.Context) {

authorModel := service.User.GetUser(articleModel.AuthorID)
if nil == authorModel {
log.Errorf("not found author of article [id=%d, authorID=%d]", articleModel.ID, articleModel.AuthorID)
logger.Errorf("not found author of article [id=%d, authorID=%d]", articleModel.ID, articleModel.AuthorID)

continue
}

blogURLSetting := service.Setting.GetSetting(model.SettingCategoryBasic, model.SettingNameBasicBlogURL, authorModel.BlogID)
if nil == blogURLSetting {
log.Errorf("not found blog URL setting [blogID=%d]", authorModel.BlogID)
logger.Errorf("not found blog URL setting [blogID=%d]", authorModel.BlogID)

continue
}
Expand Down Expand Up @@ -167,7 +171,7 @@ func RemoveArticlesAction(c *gin.Context) {
ids := arg["ids"].([]interface{})
for _, id := range ids {
if err := service.Article.RemoveArticle(uint(id.(float64))); nil != err {
log.Errorf("remove article failed: " + err.Error())
logger.Errorf("remove article failed: " + err.Error())
}
}
}
Expand Down
14 changes: 6 additions & 8 deletions controller/console/commentctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (
"github.com/b3log/pipe/service"
"github.com/b3log/pipe/util"
"github.com/gin-gonic/gin"

log "github.com/sirupsen/logrus"
)

func GetCommentsAction(c *gin.Context) {
Expand All @@ -40,19 +38,19 @@ func GetCommentsAction(c *gin.Context) {
for _, commentModel := range commentModels {
article := service.Article.ConsoleGetArticle(commentModel.ArticleID)
if nil == article {
log.Errorf("not found comment [id=%d]'s article", commentModel.ID)
logger.Errorf("not found comment [id=%d]'s article", commentModel.ID)

continue
}
articleAuthor := service.User.GetUser(article.AuthorID)
if nil == articleAuthor {
log.Errorf("not found article [id=%d]'s author", article.ID)
logger.Errorf("not found article [id=%d]'s author", article.ID)

continue
}
blogURLSetting := service.Setting.GetSetting(model.SettingCategoryBasic, model.SettingNameBasicBlogURL, articleAuthor.BlogID)
if nil == blogURLSetting {
log.Errorf("not found blog URL setting [blogID=%d]", articleAuthor.BlogID)
logger.Errorf("not found blog URL setting [blogID=%d]", articleAuthor.BlogID)

continue
}
Expand All @@ -64,13 +62,13 @@ func GetCommentsAction(c *gin.Context) {

commentAuthor := service.User.GetUser(commentModel.AuthorID)
if nil == commentAuthor {
log.Errorf("not found comment author [userID=%d]", commentModel.AuthorID)
logger.Errorf("not found comment author [userID=%d]", commentModel.AuthorID)

continue
}
blogURLSetting = service.Setting.GetSetting(model.SettingCategoryBasic, model.SettingNameBasicBlogURL, commentAuthor.BlogID)
if nil == blogURLSetting {
log.Errorf("not found blog URL setting [blogID=%d]", commentAuthor.BlogID)
logger.Errorf("not found blog URL setting [blogID=%d]", commentAuthor.BlogID)

continue
}
Expand Down Expand Up @@ -133,7 +131,7 @@ func RemoveCommentsAction(c *gin.Context) {
ids := arg["ids"].([]interface{})
for _, id := range ids {
if err := service.Comment.RemoveComment(uint(id.(float64))); nil != err {
log.Errorf("remove comment failed: " + err.Error())
logger.Errorf("remove comment failed: " + err.Error())
}
}
}
5 changes: 2 additions & 3 deletions controller/console/consolectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ import (
"text/template"

"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)

func ShowAdminPagesAction(c *gin.Context) {
t, err := template.ParseFiles("console/dist/admin" + c.Param("path") + "/index.html")
if nil != err {
log.Error("load console page [" + c.Param("path") + "] failed: " + err.Error())
logger.Errorf("load console page [" + c.Param("path") + "] failed: " + err.Error())
c.String(http.StatusNotFound, "load console page failed")

return
Expand All @@ -39,7 +38,7 @@ func ShowAdminPagesAction(c *gin.Context) {
func ShowLoginAction(c *gin.Context) {
t, err := template.ParseFiles("console/dist/login/index.html")
if nil != err {
log.Error("loads login page failed: " + err.Error())
logger.Errorf("loads login page failed: " + err.Error())
c.String(http.StatusNotFound, "loads login page failed")

return
Expand Down
3 changes: 1 addition & 2 deletions controller/console/devctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/b3log/pipe/service"
"github.com/b3log/pipe/util"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)

func GenArticlesAction(c *gin.Context) {
Expand All @@ -39,7 +38,7 @@ func GenArticlesAction(c *gin.Context) {
BlogID: session.BID,
}
if err := service.Article.AddArticle(article); nil != err {
log.Errorf("generate article failed: " + err.Error())
logger.Errorf("generate article failed: " + err.Error())
}
}

Expand Down
7 changes: 3 additions & 4 deletions controller/console/settingctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/b3log/pipe/service"
"github.com/b3log/pipe/util"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)

func GetBasicSettingsAction(c *gin.Context) {
Expand All @@ -39,7 +38,7 @@ func GetBasicSettingsAction(c *gin.Context) {
if model.SettingNameBasicCommentable == setting.Name {
v, err := strconv.ParseBool(setting.Value)
if nil != err {
log.Errorf("value of basic setting [name=%s] must be \"true\" or \"false\"", setting.Name)
logger.Errorf("value of basic setting [name=%s] must be \"true\" or \"false\"", setting.Name)
data[setting.Name] = true
} else {
data[setting.Name] = v
Expand Down Expand Up @@ -101,7 +100,7 @@ func GetPreferenceSettingsAction(c *gin.Context) {
if model.SettingNamePreferenceArticleListStyle != setting.Name {
v, err := strconv.ParseInt(setting.Value, 10, 64)
if nil != err {
log.Errorf("value of preference setting [name=%s] must be an integer", setting.Name)
logger.Errorf("value of preference setting [name=%s] must be an integer", setting.Name)
data[setting.Name] = 10
} else {
data[setting.Name] = v
Expand Down Expand Up @@ -243,7 +242,7 @@ func GetFeedSettingsAction(c *gin.Context) {
if model.SettingNameFeedOutputSize == setting.Name {
v, err := strconv.ParseInt(setting.Value, 10, 64)
if nil != err {
log.Errorf("value of feed setting [name=%s] must be an integer", setting.Name)
logger.Errorf("value of feed setting [name=%s] must be an integer", setting.Name)
data[setting.Name] = 20
} else {
data[setting.Name] = v
Expand Down
3 changes: 1 addition & 2 deletions controller/console/themectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/b3log/pipe/theme"
"github.com/b3log/pipe/util"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)

func UpdateThemeAction(c *gin.Context) {
Expand Down Expand Up @@ -58,7 +57,7 @@ func GetThemesAction(c *gin.Context) {
currentID := theme.Themes[0]
themeNameSetting := service.Setting.GetSetting(model.SettingCategoryTheme, model.SettingNameThemeName, session.BID)
if nil == themeNameSetting {
log.Error("not found theme name setting")
logger.Errorf("not found theme name setting")
} else {
currentID = themeNameSetting.Value
}
Expand Down
3 changes: 1 addition & 2 deletions controller/console/userctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/b3log/pipe/service"
"github.com/b3log/pipe/util"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)

func GetUsersAction(c *gin.Context) {
Expand All @@ -34,7 +33,7 @@ func GetUsersAction(c *gin.Context) {

blogURLSetting := service.Setting.GetSetting(model.SettingCategoryBasic, model.SettingNameBasicBlogURL, session.BID)
if nil == blogURLSetting {
log.Errorf("not found blog URL setting [blogID=%d]", session.BID)
logger.Errorf("not found blog URL setting [blogID=%d]", session.BID)

return
}
Expand Down
Loading

0 comments on commit e439ab9

Please sign in to comment.