Parcourir la source

Add documentation for logger

tags/v2.0.0-rc1
9seconds il y a 5 ans
Parent
révision
0dd890a09d
4 fichiers modifiés avec 33 ajouts et 0 suppressions
  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 Voir le fichier

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
 package logger
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
 type StdLikeLogger interface {
12
 type StdLikeLogger interface {
4
 	Printf(format string, args ...interface{})
13
 	Printf(format string, args ...interface{})
5
 }
14
 }

+ 1
- 0
logger/noop.go Voir le fichier

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

+ 1
- 0
logger/zerolog.go Voir le fichier

114
 	}
114
 	}
115
 }
115
 }
116
 
116
 
117
+// NewZeroLogger returns a logger which is using rs/zerolog library.
117
 func NewZeroLogger(log zerolog.Logger) mtglib.Logger {
118
 func NewZeroLogger(log zerolog.Logger) mtglib.Logger {
118
 	return &zeroLogContext{
119
 	return &zeroLogContext{
119
 		log: &log,
120
 		log: &log,

+ 22
- 0
mtglib/init.go Voir le fichier

76
 // a worker pool, so in worst cases you can expect that you invoke this
76
 // a worker pool, so in worst cases you can expect that you invoke this
77
 // object more frequent than defined proxy concurrency.
77
 // object more frequent than defined proxy concurrency.
78
 type IPBlocklist interface {
78
 type IPBlocklist interface {
79
+	// Contains checks if given IP address belongs to this blocklist If.
80
+	// it is, a connection is terminated                               .
79
 	Contains(net.IP) bool
81
 	Contains(net.IP) bool
80
 }
82
 }
81
 
83
 
107
 	Valid(time.Time) error
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
 type Logger interface {
132
 type Logger interface {
111
 	Named(name string) Logger
133
 	Named(name string) Logger
112
 
134
 

Chargement…
Annuler
Enregistrer