bloat/service/logging.go

342 lines
10 KiB
Go
Raw Normal View History

2019-12-13 20:08:26 +02:00
package service
import (
"log"
2019-12-14 22:19:02 +02:00
"mime/multipart"
2019-12-13 20:08:26 +02:00
"time"
2020-01-01 17:58:27 +02:00
"bloat/model"
2019-12-13 20:08:26 +02:00
)
2020-01-28 19:51:00 +02:00
type ls struct {
2019-12-13 20:08:26 +02:00
logger *log.Logger
Service
}
func NewLoggingService(logger *log.Logger, s Service) Service {
2020-01-28 19:51:00 +02:00
return &ls{logger, s}
2019-12-13 20:08:26 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) ServeErrorPage(c *model.Client, err error) {
2019-12-13 20:08:26 +02:00
defer func(begin time.Time) {
2020-01-28 19:51:00 +02:00
s.logger.Printf("method=%v, err=%v, took=%v\n",
"ServeErrorPage", err, time.Since(begin))
2019-12-13 20:08:26 +02:00
}(time.Now())
2020-05-24 07:38:34 +03:00
s.Service.ServeErrorPage(c, err)
2019-12-13 20:08:26 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) ServeSigninPage(c *model.Client) (err error) {
2019-12-13 20:08:26 +02:00
defer func(begin time.Time) {
2020-01-28 19:51:00 +02:00
s.logger.Printf("method=%v, took=%v, err=%v\n",
"ServeSigninPage", time.Since(begin), err)
2019-12-13 20:08:26 +02:00
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.ServeSigninPage(c)
2019-12-13 20:08:26 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) ServeRootPage(c *model.Client) (err error) {
2020-02-19 00:15:37 +02:00
defer func(begin time.Time) {
s.logger.Printf("method=%v, took=%v, err=%v\n",
"ServeRootPage", time.Since(begin), err)
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.ServeRootPage(c)
2020-02-19 00:15:37 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) ServeNavPage(c *model.Client) (err error) {
2020-02-19 00:15:37 +02:00
defer func(begin time.Time) {
s.logger.Printf("method=%v, took=%v, err=%v\n",
"ServeNavPage", time.Since(begin), err)
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.ServeNavPage(c)
2020-02-19 00:15:37 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) ServeTimelinePage(c *model.Client, tType string,
2020-01-28 19:51:00 +02:00
maxID string, minID string) (err error) {
2019-12-13 20:08:26 +02:00
defer func(begin time.Time) {
2020-01-28 19:51:00 +02:00
s.logger.Printf("method=%v, type=%v, took=%v, err=%v\n",
"ServeTimelinePage", tType, time.Since(begin), err)
2019-12-13 20:08:26 +02:00
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.ServeTimelinePage(c, tType, maxID, minID)
2019-12-13 20:08:26 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) ServeThreadPage(c *model.Client, id string,
2020-01-28 19:51:00 +02:00
reply bool) (err error) {
2019-12-13 20:08:26 +02:00
defer func(begin time.Time) {
2020-01-28 19:51:00 +02:00
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
"ServeThreadPage", id, time.Since(begin), err)
2019-12-13 20:08:26 +02:00
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.ServeThreadPage(c, id, reply)
2019-12-13 20:08:26 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) ServeLikedByPage(c *model.Client, id string) (err error) {
2019-12-13 20:08:26 +02:00
defer func(begin time.Time) {
2020-01-28 19:51:00 +02:00
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
"ServeLikedByPage", id, time.Since(begin), err)
2019-12-13 20:08:26 +02:00
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.ServeLikedByPage(c, id)
2019-12-13 20:08:26 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) ServeRetweetedByPage(c *model.Client, id string) (err error) {
2019-12-13 20:08:26 +02:00
defer func(begin time.Time) {
2020-01-28 19:51:00 +02:00
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
"ServeRetweetedByPage", id, time.Since(begin), err)
2019-12-13 20:08:26 +02:00
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.ServeRetweetedByPage(c, id)
2019-12-13 20:08:26 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) ServeNotificationPage(c *model.Client,
2020-01-28 19:51:00 +02:00
maxID string, minID string) (err error) {
2019-12-21 07:48:48 +02:00
defer func(begin time.Time) {
s.logger.Printf("method=%v, took=%v, err=%v\n",
2020-01-28 19:51:00 +02:00
"ServeNotificationPage", time.Since(begin), err)
2019-12-21 07:48:48 +02:00
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.ServeNotificationPage(c, maxID, minID)
2019-12-21 07:48:48 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) ServeUserPage(c *model.Client, id string,
pageType string, maxID string, minID string) (err error) {
2019-12-22 20:10:42 +02:00
defer func(begin time.Time) {
s.logger.Printf("method=%v, id=%v, type=%v, took=%v, err=%v\n",
"ServeUserPage", id, pageType, time.Since(begin), err)
2019-12-22 20:10:42 +02:00
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.ServeUserPage(c, id, pageType, maxID, minID)
2019-12-22 20:10:42 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) ServeAboutPage(c *model.Client) (err error) {
2019-12-26 11:11:24 +02:00
defer func(begin time.Time) {
2020-01-28 19:51:00 +02:00
s.logger.Printf("method=%v, took=%v, err=%v\n",
"ServeAboutPage", time.Since(begin), err)
2019-12-26 11:11:24 +02:00
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.ServeAboutPage(c)
2019-12-26 11:11:24 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) ServeEmojiPage(c *model.Client) (err error) {
2019-12-26 11:11:24 +02:00
defer func(begin time.Time) {
2020-01-28 19:51:00 +02:00
s.logger.Printf("method=%v, took=%v, err=%v\n",
"ServeEmojiPage", time.Since(begin), err)
2019-12-26 11:11:24 +02:00
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.ServeEmojiPage(c)
2019-12-26 11:11:24 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) ServeSearchPage(c *model.Client, q string,
2020-01-28 19:51:00 +02:00
qType string, offset int) (err error) {
2019-12-29 05:43:57 +02:00
defer func(begin time.Time) {
2020-01-28 19:51:00 +02:00
s.logger.Printf("method=%v, took=%v, err=%v\n",
"ServeSearchPage", time.Since(begin), err)
2019-12-29 05:43:57 +02:00
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.ServeSearchPage(c, q, qType, offset)
2019-12-29 05:43:57 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) ServeUserSearchPage(c *model.Client,
2020-01-30 17:32:37 +02:00
id string, q string, offset int) (err error) {
defer func(begin time.Time) {
s.logger.Printf("method=%v, took=%v, err=%v\n",
"ServeUserSearchPage", time.Since(begin), err)
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.ServeUserSearchPage(c, id, q, offset)
2020-01-30 17:32:37 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) ServeSettingsPage(c *model.Client) (err error) {
2019-12-29 05:43:57 +02:00
defer func(begin time.Time) {
2020-01-28 19:51:00 +02:00
s.logger.Printf("method=%v, took=%v, err=%v\n",
"ServeSettingsPage", time.Since(begin), err)
2019-12-29 05:43:57 +02:00
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.ServeSettingsPage(c)
2019-12-29 05:43:57 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) NewSession(instance string) (redirectUrl string,
2020-01-28 19:51:00 +02:00
sessionID string, err error) {
2019-12-26 21:18:09 +02:00
defer func(begin time.Time) {
2020-01-28 19:51:00 +02:00
s.logger.Printf("method=%v, instance=%v, took=%v, err=%v\n",
"NewSession", instance, time.Since(begin), err)
2019-12-26 21:18:09 +02:00
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.NewSession(instance)
2019-12-26 21:18:09 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) Signin(c *model.Client, sessionID string,
2020-02-02 10:30:40 +02:00
code string) (token string, userID string, err error) {
2019-12-27 10:06:43 +02:00
defer func(begin time.Time) {
2020-01-28 19:51:00 +02:00
s.logger.Printf("method=%v, session_id=%v, took=%v, err=%v\n",
"Signin", sessionID, time.Since(begin), err)
2019-12-27 10:06:43 +02:00
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.Signin(c, sessionID, code)
2019-12-27 10:06:43 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) Signout(c *model.Client) (err error) {
2020-03-04 17:59:59 +02:00
defer func(begin time.Time) {
s.logger.Printf("method=%v, took=%v, err=%v\n",
"Signout", time.Since(begin), err)
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.Signout(c)
2020-03-04 17:59:59 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) Post(c *model.Client, content string,
2020-01-28 19:51:00 +02:00
replyToID string, format string, visibility string, isNSFW bool,
files []*multipart.FileHeader) (id string, err error) {
2019-12-27 10:06:43 +02:00
defer func(begin time.Time) {
s.logger.Printf("method=%v, took=%v, err=%v\n",
2020-01-28 19:51:00 +02:00
"Post", time.Since(begin), err)
2019-12-27 10:06:43 +02:00
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.Post(c, content, replyToID, format,
2020-01-28 19:51:00 +02:00
visibility, isNSFW, files)
2019-12-27 10:06:43 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) Like(c *model.Client, id string) (count int64, err error) {
2019-12-13 20:08:26 +02:00
defer func(begin time.Time) {
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
"Like", id, time.Since(begin), err)
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.Like(c, id)
2019-12-13 20:08:26 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) UnLike(c *model.Client, id string) (count int64, err error) {
2019-12-13 20:08:26 +02:00
defer func(begin time.Time) {
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
"UnLike", id, time.Since(begin), err)
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.UnLike(c, id)
2019-12-13 20:08:26 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) Retweet(c *model.Client, id string) (count int64, err error) {
2019-12-13 20:08:26 +02:00
defer func(begin time.Time) {
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
"Retweet", id, time.Since(begin), err)
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.Retweet(c, id)
2019-12-13 20:08:26 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) UnRetweet(c *model.Client, id string) (count int64, err error) {
2019-12-13 20:08:26 +02:00
defer func(begin time.Time) {
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
"UnRetweet", id, time.Since(begin), err)
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.UnRetweet(c, id)
2019-12-13 20:08:26 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) Vote(c *model.Client, id string, choices []string) (err error) {
defer func(begin time.Time) {
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
"Vote", id, time.Since(begin), err)
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.Vote(c, id, choices)
}
2020-05-24 07:38:34 +03:00
func (s *ls) Follow(c *model.Client, id string, reblogs *bool) (err error) {
2019-12-13 20:08:26 +02:00
defer func(begin time.Time) {
2020-01-28 19:51:00 +02:00
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
"Follow", id, time.Since(begin), err)
2019-12-13 20:08:26 +02:00
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.Follow(c, id, reblogs)
2019-12-13 20:08:26 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) UnFollow(c *model.Client, id string) (err error) {
defer func(begin time.Time) {
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
2020-01-28 19:51:00 +02:00
"UnFollow", id, time.Since(begin), err)
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.UnFollow(c, id)
}
2020-05-24 07:38:34 +03:00
func (s *ls) Mute(c *model.Client, id string) (err error) {
2020-02-08 12:49:06 +02:00
defer func(begin time.Time) {
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
"Mute", id, time.Since(begin), err)
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.Mute(c, id)
2020-02-08 12:49:06 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) UnMute(c *model.Client, id string) (err error) {
2020-02-08 12:49:06 +02:00
defer func(begin time.Time) {
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
"UnMute", id, time.Since(begin), err)
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.UnMute(c, id)
2020-02-08 12:49:06 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) Block(c *model.Client, id string) (err error) {
2020-02-08 12:49:06 +02:00
defer func(begin time.Time) {
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
"Block", id, time.Since(begin), err)
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.Block(c, id)
2020-02-08 12:49:06 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) UnBlock(c *model.Client, id string) (err error) {
2020-02-08 12:49:06 +02:00
defer func(begin time.Time) {
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
"UnBlock", id, time.Since(begin), err)
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.UnBlock(c, id)
2020-02-08 12:49:06 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) Subscribe(c *model.Client, id string) (err error) {
2020-04-17 20:19:11 +03:00
defer func(begin time.Time) {
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
"Subscribe", id, time.Since(begin), err)
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.Subscribe(c, id)
2020-04-17 20:19:11 +03:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) UnSubscribe(c *model.Client, id string) (err error) {
2020-04-17 20:19:11 +03:00
defer func(begin time.Time) {
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
"UnSubscribe", id, time.Since(begin), err)
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.UnSubscribe(c, id)
2020-04-17 20:19:11 +03:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) SaveSettings(c *model.Client, settings *model.Settings) (err error) {
defer func(begin time.Time) {
2020-01-28 19:51:00 +02:00
s.logger.Printf("method=%v, took=%v, err=%v\n",
"SaveSettings", time.Since(begin), err)
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.SaveSettings(c, settings)
}
2020-02-02 09:24:06 +02:00
2020-05-24 07:38:34 +03:00
func (s *ls) MuteConversation(c *model.Client, id string) (err error) {
2020-02-02 09:24:06 +02:00
defer func(begin time.Time) {
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
"MuteConversation", id, time.Since(begin), err)
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.MuteConversation(c, id)
2020-02-02 09:24:06 +02:00
}
2020-05-24 07:38:34 +03:00
func (s *ls) UnMuteConversation(c *model.Client, id string) (err error) {
2020-02-02 09:24:06 +02:00
defer func(begin time.Time) {
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
"UnMuteConversation", id, time.Since(begin), err)
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.UnMuteConversation(c, id)
2020-02-02 09:24:06 +02:00
}
2020-02-02 10:30:40 +02:00
2020-05-24 07:38:34 +03:00
func (s *ls) Delete(c *model.Client, id string) (err error) {
2020-02-02 10:30:40 +02:00
defer func(begin time.Time) {
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
"Delete", id, time.Since(begin), err)
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.Delete(c, id)
2020-02-02 10:30:40 +02:00
}
2020-02-19 00:15:37 +02:00
func (s *ls) ReadNotifications(c *model.Client, maxID string) (err error) {
2020-02-19 00:15:37 +02:00
defer func(begin time.Time) {
s.logger.Printf("method=%v, max_id=%v, took=%v, err=%v\n",
"ReadNotifications", maxID, time.Since(begin), err)
}(time.Now())
2020-05-24 07:38:34 +03:00
return s.Service.ReadNotifications(c, maxID)
2020-02-19 00:15:37 +02:00
}
func (s *ls) Bookmark(c *model.Client, id string) (err error) {
defer func(begin time.Time) {
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
"Bookmark", id, time.Since(begin), err)
}(time.Now())
return s.Service.Bookmark(c, id)
}
func (s *ls) UnBookmark(c *model.Client, id string) (err error) {
defer func(begin time.Time) {
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
"UnBookmark", id, time.Since(begin), err)
}(time.Now())
return s.Service.UnBookmark(c, id)
}