Merge branch 'master' of https://git.freesoftwareextremist.com/bloat
[bloat] / service / logging.go
1 package service
2
3 import (
4         "log"
5         "mime/multipart"
6         "time"
7
8         "bloat/model"
9 )
10
11 type ls struct {
12         logger *log.Logger
13         Service
14 }
15
16 func NewLoggingService(logger *log.Logger, s Service) Service {
17         return &ls{logger, s}
18 }
19
20 func (s *ls) ServeErrorPage(c *model.Client, err error) {
21         defer func(begin time.Time) {
22                 s.logger.Printf("method=%v, err=%v, took=%v\n",
23                         "ServeErrorPage", err, time.Since(begin))
24         }(time.Now())
25         s.Service.ServeErrorPage(c, err)
26 }
27
28 func (s *ls) ServeSigninPage(c *model.Client) (err error) {
29         defer func(begin time.Time) {
30                 s.logger.Printf("method=%v, took=%v, err=%v\n",
31                         "ServeSigninPage", time.Since(begin), err)
32         }(time.Now())
33         return s.Service.ServeSigninPage(c)
34 }
35
36 func (s *ls) ServeRootPage(c *model.Client) (err error) {
37         defer func(begin time.Time) {
38                 s.logger.Printf("method=%v, took=%v, err=%v\n",
39                         "ServeRootPage", time.Since(begin), err)
40         }(time.Now())
41         return s.Service.ServeRootPage(c)
42 }
43
44 func (s *ls) ServeNavPage(c *model.Client) (err error) {
45         defer func(begin time.Time) {
46                 s.logger.Printf("method=%v, took=%v, err=%v\n",
47                         "ServeNavPage", time.Since(begin), err)
48         }(time.Now())
49         return s.Service.ServeNavPage(c)
50 }
51
52 func (s *ls) ServeTimelinePage(c *model.Client, tType string,
53         maxID string, minID string) (err error) {
54         defer func(begin time.Time) {
55                 s.logger.Printf("method=%v, type=%v, took=%v, err=%v\n",
56                         "ServeTimelinePage", tType, time.Since(begin), err)
57         }(time.Now())
58         return s.Service.ServeTimelinePage(c, tType, maxID, minID)
59 }
60
61 func (s *ls) ServeThreadPage(c *model.Client, id string,
62         reply bool) (err error) {
63         defer func(begin time.Time) {
64                 s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
65                         "ServeThreadPage", id, time.Since(begin), err)
66         }(time.Now())
67         return s.Service.ServeThreadPage(c, id, reply)
68 }
69
70 func (s *ls) ServeLikedByPage(c *model.Client, id string) (err error) {
71         defer func(begin time.Time) {
72                 s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
73                         "ServeLikedByPage", id, time.Since(begin), err)
74         }(time.Now())
75         return s.Service.ServeLikedByPage(c, id)
76 }
77
78 func (s *ls) ServeRetweetedByPage(c *model.Client, id string) (err error) {
79         defer func(begin time.Time) {
80                 s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
81                         "ServeRetweetedByPage", id, time.Since(begin), err)
82         }(time.Now())
83         return s.Service.ServeRetweetedByPage(c, id)
84 }
85
86 func (s *ls) ServeNotificationPage(c *model.Client,
87         maxID string, minID string) (err error) {
88         defer func(begin time.Time) {
89                 s.logger.Printf("method=%v, took=%v, err=%v\n",
90                         "ServeNotificationPage", time.Since(begin), err)
91         }(time.Now())
92         return s.Service.ServeNotificationPage(c, maxID, minID)
93 }
94
95 func (s *ls) ServeUserPage(c *model.Client, id string,
96         pageType string, maxID string, minID string) (err error) {
97         defer func(begin time.Time) {
98                 s.logger.Printf("method=%v, id=%v, type=%v, took=%v, err=%v\n",
99                         "ServeUserPage", id, pageType, time.Since(begin), err)
100         }(time.Now())
101         return s.Service.ServeUserPage(c, id, pageType, maxID, minID)
102 }
103
104 func (s *ls) ServeAboutPage(c *model.Client) (err error) {
105         defer func(begin time.Time) {
106                 s.logger.Printf("method=%v, took=%v, err=%v\n",
107                         "ServeAboutPage", time.Since(begin), err)
108         }(time.Now())
109         return s.Service.ServeAboutPage(c)
110 }
111
112 func (s *ls) ServeEmojiPage(c *model.Client) (err error) {
113         defer func(begin time.Time) {
114                 s.logger.Printf("method=%v, took=%v, err=%v\n",
115                         "ServeEmojiPage", time.Since(begin), err)
116         }(time.Now())
117         return s.Service.ServeEmojiPage(c)
118 }
119
120 func (s *ls) ServeSearchPage(c *model.Client, q string,
121         qType string, offset int) (err error) {
122         defer func(begin time.Time) {
123                 s.logger.Printf("method=%v, took=%v, err=%v\n",
124                         "ServeSearchPage", time.Since(begin), err)
125         }(time.Now())
126         return s.Service.ServeSearchPage(c, q, qType, offset)
127 }
128
129 func (s *ls) ServeUserSearchPage(c *model.Client,
130         id string, q string, offset int) (err error) {
131         defer func(begin time.Time) {
132                 s.logger.Printf("method=%v, took=%v, err=%v\n",
133                         "ServeUserSearchPage", time.Since(begin), err)
134         }(time.Now())
135         return s.Service.ServeUserSearchPage(c, id, q, offset)
136 }
137
138 func (s *ls) ServeSettingsPage(c *model.Client) (err error) {
139         defer func(begin time.Time) {
140                 s.logger.Printf("method=%v, took=%v, err=%v\n",
141                         "ServeSettingsPage", time.Since(begin), err)
142         }(time.Now())
143         return s.Service.ServeSettingsPage(c)
144 }
145
146 func (s *ls) NewSession(instance string) (redirectUrl string,
147         sessionID string, err error) {
148         defer func(begin time.Time) {
149                 s.logger.Printf("method=%v, instance=%v, took=%v, err=%v\n",
150                         "NewSession", instance, time.Since(begin), err)
151         }(time.Now())
152         return s.Service.NewSession(instance)
153 }
154
155 func (s *ls) Signin(c *model.Client, sessionID string,
156         code string) (token string, userID string, err error) {
157         defer func(begin time.Time) {
158                 s.logger.Printf("method=%v, session_id=%v, took=%v, err=%v\n",
159                         "Signin", sessionID, time.Since(begin), err)
160         }(time.Now())
161         return s.Service.Signin(c, sessionID, code)
162 }
163
164 func (s *ls) Signout(c *model.Client) (err error) {
165         defer func(begin time.Time) {
166                 s.logger.Printf("method=%v, took=%v, err=%v\n",
167                         "Signout", time.Since(begin), err)
168         }(time.Now())
169         return s.Service.Signout(c)
170 }
171
172 func (s *ls) Post(c *model.Client, content string,
173         replyToID string, format string, visibility string, isNSFW bool,
174         files []*multipart.FileHeader) (id string, err error) {
175         defer func(begin time.Time) {
176                 s.logger.Printf("method=%v, took=%v, err=%v\n",
177                         "Post", time.Since(begin), err)
178         }(time.Now())
179         return s.Service.Post(c, content, replyToID, format,
180                 visibility, isNSFW, files)
181 }
182
183 func (s *ls) Like(c *model.Client, id string) (count int64, err error) {
184         defer func(begin time.Time) {
185                 s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
186                         "Like", id, time.Since(begin), err)
187         }(time.Now())
188         return s.Service.Like(c, id)
189 }
190
191 func (s *ls) UnLike(c *model.Client, id string) (count int64, err error) {
192         defer func(begin time.Time) {
193                 s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
194                         "UnLike", id, time.Since(begin), err)
195         }(time.Now())
196         return s.Service.UnLike(c, id)
197 }
198
199 func (s *ls) Retweet(c *model.Client, id string) (count int64, err error) {
200         defer func(begin time.Time) {
201                 s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
202                         "Retweet", id, time.Since(begin), err)
203         }(time.Now())
204         return s.Service.Retweet(c, id)
205 }
206
207 func (s *ls) UnRetweet(c *model.Client, id string) (count int64, err error) {
208         defer func(begin time.Time) {
209                 s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
210                         "UnRetweet", id, time.Since(begin), err)
211         }(time.Now())
212         return s.Service.UnRetweet(c, id)
213 }
214
215 func (s *ls) Vote(c *model.Client, id string, choices []string) (err error) {
216         defer func(begin time.Time) {
217                 s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
218                         "Vote", id, time.Since(begin), err)
219         }(time.Now())
220         return s.Service.Vote(c, id, choices)
221 }
222
223 func (s *ls) Follow(c *model.Client, id string, reblogs *bool) (err error) {
224         defer func(begin time.Time) {
225                 s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
226                         "Follow", id, time.Since(begin), err)
227         }(time.Now())
228         return s.Service.Follow(c, id, reblogs)
229 }
230
231 func (s *ls) UnFollow(c *model.Client, id string) (err error) {
232         defer func(begin time.Time) {
233                 s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
234                         "UnFollow", id, time.Since(begin), err)
235         }(time.Now())
236         return s.Service.UnFollow(c, id)
237 }
238
239 func (s *ls) Mute(c *model.Client, id string) (err error) {
240         defer func(begin time.Time) {
241                 s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
242                         "Mute", id, time.Since(begin), err)
243         }(time.Now())
244         return s.Service.Mute(c, id)
245 }
246
247 func (s *ls) UnMute(c *model.Client, id string) (err error) {
248         defer func(begin time.Time) {
249                 s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
250                         "UnMute", id, time.Since(begin), err)
251         }(time.Now())
252         return s.Service.UnMute(c, id)
253 }
254
255 func (s *ls) Block(c *model.Client, id string) (err error) {
256         defer func(begin time.Time) {
257                 s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
258                         "Block", id, time.Since(begin), err)
259         }(time.Now())
260         return s.Service.Block(c, id)
261 }
262
263 func (s *ls) UnBlock(c *model.Client, id string) (err error) {
264         defer func(begin time.Time) {
265                 s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
266                         "UnBlock", id, time.Since(begin), err)
267         }(time.Now())
268         return s.Service.UnBlock(c, id)
269 }
270
271 func (s *ls) Subscribe(c *model.Client, id string) (err error) {
272         defer func(begin time.Time) {
273                 s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
274                         "Subscribe", id, time.Since(begin), err)
275         }(time.Now())
276         return s.Service.Subscribe(c, id)
277 }
278
279 func (s *ls) UnSubscribe(c *model.Client, id string) (err error) {
280         defer func(begin time.Time) {
281                 s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
282                         "UnSubscribe", id, time.Since(begin), err)
283         }(time.Now())
284         return s.Service.UnSubscribe(c, id)
285 }
286
287 func (s *ls) SaveSettings(c *model.Client, settings *model.Settings) (err error) {
288         defer func(begin time.Time) {
289                 s.logger.Printf("method=%v, took=%v, err=%v\n",
290                         "SaveSettings", time.Since(begin), err)
291         }(time.Now())
292         return s.Service.SaveSettings(c, settings)
293 }
294
295 func (s *ls) MuteConversation(c *model.Client, id string) (err error) {
296         defer func(begin time.Time) {
297                 s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
298                         "MuteConversation", id, time.Since(begin), err)
299         }(time.Now())
300         return s.Service.MuteConversation(c, id)
301 }
302
303 func (s *ls) UnMuteConversation(c *model.Client, id string) (err error) {
304         defer func(begin time.Time) {
305                 s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
306                         "UnMuteConversation", id, time.Since(begin), err)
307         }(time.Now())
308         return s.Service.UnMuteConversation(c, id)
309 }
310
311 func (s *ls) Delete(c *model.Client, id string) (err error) {
312         defer func(begin time.Time) {
313                 s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
314                         "Delete", id, time.Since(begin), err)
315         }(time.Now())
316         return s.Service.Delete(c, id)
317 }
318
319 func (s *ls) ReadNotifications(c *model.Client, maxID string) (err error) {
320         defer func(begin time.Time) {
321                 s.logger.Printf("method=%v, max_id=%v, took=%v, err=%v\n",
322                         "ReadNotifications", maxID, time.Since(begin), err)
323         }(time.Now())
324         return s.Service.ReadNotifications(c, maxID)
325 }
326
327 func (s *ls) Bookmark(c *model.Client, id string) (err error) {
328         defer func(begin time.Time) {
329                 s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
330                         "Bookmark", id, time.Since(begin), err)
331         }(time.Now())
332         return s.Service.Bookmark(c, id)
333 }
334
335 func (s *ls) UnBookmark(c *model.Client, id string) (err error) {
336         defer func(begin time.Time) {
337                 s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
338                         "UnBookmark", id, time.Since(begin), err)
339         }(time.Now())
340         return s.Service.UnBookmark(c, id)
341 }