Browse Source

Add documentation for logger

tags/v2.0.0-rc1
9seconds 5 years ago
parent
commit
0dd890a09d
4 changed files with 33 additions and 0 deletions
  1. 9
    0
      logger/init.go
  2. 1
    0
      logger/noop.go
  3. 1
    0
      logger/zerolog.go
  4. 22
    0
      mtglib/init.go

+ 9
- 0
logger/init.go View File

@@ -1,5 +1,14 @@
1
+// Package logger has implementation of loggers for mtglib.Logger
2
+// interface.
3
+//
4
+// Please see a description of that interface to get some agreements
5
+// which are used by mtglib.
1 6
 package logger
2 7
 
8
+// StdLikeLogger is an interface which is close to log.Logger. This is
9
+// commonly used by many 3pp tools. While mtglib itself does not need
10
+// it, it is always a good idea to support it and have a transient end
11
+// to end logging.
3 12
 type StdLikeLogger interface {
4 13
 	Printf(format string, args ...interface{})
5 14
 }

+ 1
- 0
logger/noop.go View File

@@ -15,6 +15,7 @@ func (n noopLogger) InfoError(_ string, _ error)           {}
15 15
 func (n noopLogger) WarningError(_ string, _ error)        {}
16 16
 func (n noopLogger) DebugError(_ string, _ error)          {}
17 17
 
18
+// NewNoopLogger returns a logger which discards all events.
18 19
 func NewNoopLogger() mtglib.Logger {
19 20
 	return noopLogger{}
20 21
 }

+ 1
- 0
logger/zerolog.go View File

@@ -114,6 +114,7 @@ func (z *zeroLogContext) attachCtx(evt *zerolog.Event) {
114 114
 	}
115 115
 }
116 116
 
117
+// NewZeroLogger returns a logger which is using rs/zerolog library.
117 118
 func NewZeroLogger(log zerolog.Logger) mtglib.Logger {
118 119
 	return &zeroLogContext{
119 120
 		log: &log,

+ 22
- 0
mtglib/init.go View File

@@ -76,6 +76,8 @@ type AntiReplayCache interface {
76 76
 // a worker pool, so in worst cases you can expect that you invoke this
77 77
 // object more frequent than defined proxy concurrency.
78 78
 type IPBlocklist interface {
79
+	// Contains checks if given IP address belongs to this blocklist If.
80
+	// it is, a connection is terminated                               .
79 81
 	Contains(net.IP) bool
80 82
 }
81 83
 
@@ -107,6 +109,26 @@ type TimeAttackDetector interface {
107 109
 	Valid(time.Time) error
108 110
 }
109 111
 
112
+// Logger defines an interface of the logger used by mtglib.
113
+//
114
+// Each logger has a name. It is possible to stack names to organize
115
+// poor-man namespaces. Also, each logger must be able to bind
116
+// parameters to avoid pushing them all the time.
117
+//
118
+// Example
119
+//
120
+//     logger := SomeLogger{}
121
+//     logger = logger.BindStr("ip", net.IP{127, 0, 0, 1})
122
+//     logger.Info("Hello")
123
+//
124
+// In that case, ip is bound as a parameter. It is a great idea to
125
+// put this parameter somewhere in a log message.
126
+//
127
+//     logger1 = logger.BindStr("param1", "11")
128
+//     logger2 = logger.BindInt("param2", 11)
129
+//
130
+// logger1 should see no param2 and vice versa, logger2 should not see param1
131
+// If you attach a parameter to a logger, parents should not know about that.
110 132
 type Logger interface {
111 133
 	Named(name string) Logger
112 134
 

Loading…
Cancel
Save