forked from pydio/cells
-
Notifications
You must be signed in to change notification settings - Fork 0
/
activity.go
111 lines (99 loc) · 3.43 KB
/
activity.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* Copyright (c) 2019-2021. Abstrium SAS <team (at) pydio.com>
* This file is part of Pydio Cells.
*
* Pydio Cells is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio Cells is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio Cells. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <https://pydio.com>.
*/
package activity
import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"github.com/pydio/cells/common"
)
/* activity.go file enriches default generated proto structs with some custom pydio methods to ease development */
/* LOGGING SUPPORT */
// MarshalLogObject implements custom marshalling for logs
func (s *Subscription) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
if s.UserId != "" {
encoder.AddString("UserId", s.UserId)
}
if s.ObjectId != "" {
encoder.AddString("ObjectId", s.ObjectId)
}
if s.Events != nil && len(s.Events) > 0 {
encoder.AddReflected("Events", s.Events)
}
if s.ObjectType != 0 {
encoder.AddInt32("ObjectType", int32(s.ObjectType))
}
return nil
}
// Zap simply returns a zapcore.Field object populated with this Activity Subscription under a standard key
func (s *Subscription) Zap() zapcore.Field {
return zap.Object(common.KeyActivitySubscription, s)
}
// MarshalLogObject implements custom marshalling for logs
func (s *StreamActivitiesRequest) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
if s.BoxName != "" {
encoder.AddString("BoxName", s.BoxName)
}
if s.Language != "" {
encoder.AddString("Language", s.Language)
}
if s.ContextData != "" {
encoder.AddString("ContextData", s.ContextData)
}
if s.StreamFilter != "" {
encoder.AddString("StreamFilter", s.StreamFilter)
}
if s.Offset != 0 {
encoder.AddInt64("Offset", int64(s.Offset))
}
if s.Limit != 0 {
encoder.AddInt64("Limit", int64(s.Limit))
}
encoder.AddBool("UnreadCountOnly", s.UnreadCountOnly)
encoder.AddBool("AsDigest", s.AsDigest)
return nil
}
// Zap simply returns a zapcore.Field object populated with this StreamActivitiesRequest under a standard key
func (s *StreamActivitiesRequest) Zap() zapcore.Field {
return zap.Object(common.KeyActivityStreamRequest, s)
}
// MarshalLogObject implements custom marshalling for logs
func (p *PostActivityEvent) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
if p.BoxName != "" {
encoder.AddString("BoxName", p.BoxName)
}
if p.JsonType != "" {
encoder.AddString("JsonType", p.JsonType)
}
if p.OwnerId != "" {
encoder.AddString("OwnerId", p.OwnerId)
}
if p.OwnerType != 0 {
encoder.AddInt32("OwnerType", int32(p.OwnerType))
}
return nil
}
// Zap simply returns a zapcore.Field object populated with this PostActivityEvent under a standard key
func (p *PostActivityEvent) Zap() zapcore.Field {
return zap.Object(common.KeyActivityPostEvent, p)
}
// // Zap simply returns a zapcore.Field object populated with this Activity OBJECT under a standard key
// func (o *Object) Zap() zapcore.Field {
// return zap.Any(common.KeyActivityObject, o)
// }