bloat/service/logging.go

239 lines
7.9 KiB
Go
Raw Normal View History

2019-12-13 20:08:26 +02:00
package service
import (
"context"
"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-01-28 19:51:00 +02:00
func (s *ls) ServeErrorPage(ctx context.Context, 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-01-28 19:51:00 +02:00
s.Service.ServeErrorPage(ctx, c, err)
2019-12-13 20:08:26 +02:00
}
2020-01-28 19:51:00 +02:00
func (s *ls) ServeSigninPage(ctx context.Context, 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-01-28 19:51:00 +02:00
return s.Service.ServeSigninPage(ctx, c)
2019-12-13 20:08:26 +02:00
}
2020-01-28 19:51:00 +02:00
func (s *ls) ServeTimelinePage(ctx context.Context, c *model.Client, tType string,
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-01-28 19:51:00 +02:00
return s.Service.ServeTimelinePage(ctx, c, tType, maxID, minID)
2019-12-13 20:08:26 +02:00
}
2020-01-28 19:51:00 +02:00
func (s *ls) ServeThreadPage(ctx context.Context, c *model.Client, id string,
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-01-28 19:51:00 +02:00
return s.Service.ServeThreadPage(ctx, c, id, reply)
2019-12-13 20:08:26 +02:00
}
2020-01-28 19:51:00 +02:00
func (s *ls) ServeLikedByPage(ctx context.Context, 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-01-28 19:51:00 +02:00
return s.Service.ServeLikedByPage(ctx, c, id)
2019-12-13 20:08:26 +02:00
}
2020-01-28 19:51:00 +02:00
func (s *ls) ServeRetweetedByPage(ctx context.Context, 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-01-28 19:51:00 +02:00
return s.Service.ServeRetweetedByPage(ctx, c, id)
2019-12-13 20:08:26 +02:00
}
2020-01-28 19:51:00 +02:00
func (s *ls) ServeNotificationPage(ctx context.Context, c *model.Client,
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-01-28 19:51:00 +02:00
return s.Service.ServeNotificationPage(ctx, c, maxID, minID)
2019-12-21 07:48:48 +02:00
}
func (s *ls) ServeUserPage(ctx context.Context, 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())
return s.Service.ServeUserPage(ctx, c, id, pageType, maxID, minID)
2019-12-22 20:10:42 +02:00
}
2020-01-28 19:51:00 +02:00
func (s *ls) ServeAboutPage(ctx context.Context, 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-01-28 19:51:00 +02:00
return s.Service.ServeAboutPage(ctx, c)
2019-12-26 11:11:24 +02:00
}
2020-01-28 19:51:00 +02:00
func (s *ls) ServeEmojiPage(ctx context.Context, 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-01-28 19:51:00 +02:00
return s.Service.ServeEmojiPage(ctx, c)
2019-12-26 11:11:24 +02:00
}
2020-01-28 19:51:00 +02:00
func (s *ls) ServeSearchPage(ctx context.Context, c *model.Client, q string,
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-01-28 19:51:00 +02:00
return s.Service.ServeSearchPage(ctx, c, q, qType, offset)
2019-12-29 05:43:57 +02:00
}
2020-01-30 17:32:37 +02:00
func (s *ls) ServeUserSearchPage(ctx context.Context, c *model.Client,
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())
return s.Service.ServeUserSearchPage(ctx, c, id, q, offset)
}
2020-01-28 19:51:00 +02:00
func (s *ls) ServeSettingsPage(ctx context.Context, 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-01-28 19:51:00 +02:00
return s.Service.ServeSettingsPage(ctx, c)
2019-12-29 05:43:57 +02:00
}
2020-01-28 19:51:00 +02:00
func (s *ls) NewSession(ctx context.Context, instance string) (redirectUrl string,
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-01-28 19:51:00 +02:00
return s.Service.NewSession(ctx, instance)
2019-12-26 21:18:09 +02:00
}
2020-01-28 19:51:00 +02:00
func (s *ls) Signin(ctx context.Context, 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-01-28 19:51:00 +02:00
return s.Service.Signin(ctx, c, sessionID, code)
2019-12-27 10:06:43 +02:00
}
2020-01-28 19:51:00 +02:00
func (s *ls) Post(ctx context.Context, c *model.Client, content string,
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-01-28 19:51:00 +02:00
return s.Service.Post(ctx, c, content, replyToID, format,
visibility, isNSFW, files)
2019-12-27 10:06:43 +02:00
}
2020-01-28 19:51:00 +02:00
func (s *ls) Like(ctx context.Context, 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-01-28 19:51:00 +02:00
return s.Service.Like(ctx, c, id)
2019-12-13 20:08:26 +02:00
}
2020-01-28 19:51:00 +02:00
func (s *ls) UnLike(ctx context.Context, 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-01-28 19:51:00 +02:00
return s.Service.UnLike(ctx, c, id)
2019-12-13 20:08:26 +02:00
}
2020-01-28 19:51:00 +02:00
func (s *ls) Retweet(ctx context.Context, 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-01-28 19:51:00 +02:00
return s.Service.Retweet(ctx, c, id)
2019-12-13 20:08:26 +02:00
}
2020-01-28 19:51:00 +02:00
func (s *ls) UnRetweet(ctx context.Context, 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-01-28 19:51:00 +02:00
return s.Service.UnRetweet(ctx, c, id)
2019-12-13 20:08:26 +02:00
}
2020-01-28 19:51:00 +02:00
func (s *ls) Follow(ctx context.Context, 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",
"Follow", id, time.Since(begin), err)
2019-12-13 20:08:26 +02:00
}(time.Now())
2020-01-28 19:51:00 +02:00
return s.Service.Follow(ctx, c, id)
2019-12-13 20:08:26 +02:00
}
2020-01-28 19:51:00 +02:00
func (s *ls) UnFollow(ctx context.Context, 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-01-28 19:51:00 +02:00
return s.Service.UnFollow(ctx, c, id)
}
2020-01-28 19:51:00 +02:00
func (s *ls) SaveSettings(ctx context.Context, 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-01-28 19:51:00 +02:00
return s.Service.SaveSettings(ctx, c, settings)
}
2020-02-02 09:24:06 +02:00
func (s *ls) MuteConversation(ctx context.Context, c *model.Client, id string) (err error) {
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())
return s.Service.MuteConversation(ctx, c, id)
}
func (s *ls) UnMuteConversation(ctx context.Context, c *model.Client, id string) (err error) {
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())
return s.Service.UnMuteConversation(ctx, c, id)
}
2020-02-02 10:30:40 +02:00
func (s *ls) Delete(ctx context.Context, c *model.Client, id string) (err error) {
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())
return s.Service.Delete(ctx, c, id)
}