@cryptotaxi247 / kubo / commits / 6bc9086b4

Decimate prefixlog

License: MIT Signed-off-by: rht <rhtbot@gmail.com>

rht committed Jun 11, 2015 at 23:44 UTC 6bc9086b4c0aac49b6b12b386eaab2600c3910f0
1 file changed -151
util/prefixlog/prefixlog.go deleted
-151
@@ -1,151 +0,0 @@
1 -package eventlog
2 -
3 -import (
4 - "strings"
5 -
6 - "github.com/ipfs/go-ipfs/util"
7 -)
8 -
9 -// StandardLogger provides API compatibility with standard printf loggers
10 -// eg. go-logging
11 -type StandardLogger interface {
12 - Critical(args ...interface{})
13 - Criticalf(format string, args ...interface{})
14 - Debug(args ...interface{})
15 - Debugf(format string, args ...interface{})
16 - Error(args ...interface{})
17 - Errorf(format string, args ...interface{})
18 - Fatal(args ...interface{})
19 - Fatalf(format string, args ...interface{})
20 - Info(args ...interface{})
21 - Infof(format string, args ...interface{})
22 - Notice(args ...interface{})
23 - Noticef(format string, args ...interface{})
24 - Panic(args ...interface{})
25 - Panicf(format string, args ...interface{})
26 - Warning(args ...interface{})
27 - Warningf(format string, args ...interface{})
28 -}
29 -
30 -// StandardLogger provides API compatibility with standard printf loggers
31 -// eg. go-logging
32 -type PrefixLogger interface {
33 - StandardLogger
34 -
35 - Format() string
36 - Args() []interface{}
37 -
38 - Prefix(fmt string, args ...interface{}) PrefixLogger
39 -}
40 -
41 -// Logger retrieves an event logger by name
42 -func Logger(system string) PrefixLogger {
43 -
44 - // TODO if we would like to adjust log levels at run-time. Store this event
45 - // logger in a map (just like the util.Logger impl)
46 -
47 - logger := util.Logger(system)
48 - return Prefix(logger, "")
49 -}
50 -
51 -func Prefix(l StandardLogger, format string, args ...interface{}) PrefixLogger {
52 - return &prefixLogger{logger: l, format: format, args: args}
53 -}
54 -
55 -type prefixLogger struct {
56 - logger StandardLogger
57 - format string
58 - args []interface{}
59 -}
60 -
61 -func (pl *prefixLogger) Format() string {
62 - return pl.format
63 -}
64 -
65 -func (pl *prefixLogger) Args() []interface{} {
66 - return pl.args
67 -}
68 -
69 -func (pl *prefixLogger) Prefix(fmt string, args ...interface{}) PrefixLogger {
70 - return Prefix(pl, fmt, args...)
71 -}
72 -
73 -func (pl *prefixLogger) prepend(fmt string, args []interface{}) (string, []interface{}) {
74 - together := make([]interface{}, 0, len(pl.args)+len(args))
75 - together = append(together, pl.args...)
76 - together = append(together, args...)
77 - if len(pl.format) > 0 {
78 - fmt = pl.format + " " + fmt
79 - }
80 - return fmt, together
81 -}
82 -
83 -func valfmtn(count int) string {
84 - s := strings.Repeat("%v ", count)
85 - s = s[:len(s)-1] // remove last space
86 - return s
87 -}
88 -
89 -type logFunc func(args ...interface{})
90 -type logFuncf func(fmt string, args ...interface{})
91 -
92 -func (pl *prefixLogger) logFunc(f logFuncf, args ...interface{}) {
93 - // need to actually use the format version, with extra fmt strings appended
94 - fmt := valfmtn(len(args))
95 - pl.logFuncf(f, fmt, args...)
96 -}
97 -
98 -func (pl *prefixLogger) logFuncf(f logFuncf, format string, args ...interface{}) {
99 - format, args = pl.prepend(format, args)
100 - f(format, args...)
101 -}
102 -
103 -func (pl *prefixLogger) Critical(args ...interface{}) {
104 - pl.logFunc(pl.logger.Criticalf, args...)
105 -}
106 -func (pl *prefixLogger) Debug(args ...interface{}) {
107 - pl.logFunc(pl.logger.Debugf, args...)
108 -}
109 -func (pl *prefixLogger) Error(args ...interface{}) {
110 - pl.logFunc(pl.logger.Errorf, args...)
111 -}
112 -func (pl *prefixLogger) Fatal(args ...interface{}) {
113 - pl.logFunc(pl.logger.Fatalf, args...)
114 -}
115 -func (pl *prefixLogger) Info(args ...interface{}) {
116 - pl.logFunc(pl.logger.Infof, args...)
117 -}
118 -func (pl *prefixLogger) Notice(args ...interface{}) {
119 - pl.logFunc(pl.logger.Noticef, args...)
120 -}
121 -func (pl *prefixLogger) Panic(args ...interface{}) {
122 - pl.logFunc(pl.logger.Panicf, args...)
123 -}
124 -func (pl *prefixLogger) Warning(args ...interface{}) {
125 - pl.logFunc(pl.logger.Warningf, args...)
126 -}
127 -
128 -func (pl *prefixLogger) Criticalf(format string, args ...interface{}) {
129 - pl.logFuncf(pl.logger.Criticalf, format, args...)
130 -}
131 -func (pl *prefixLogger) Debugf(format string, args ...interface{}) {
132 - pl.logFuncf(pl.logger.Debugf, format, args...)
133 -}
134 -func (pl *prefixLogger) Errorf(format string, args ...interface{}) {
135 - pl.logFuncf(pl.logger.Errorf, format, args...)
136 -}
137 -func (pl *prefixLogger) Fatalf(format string, args ...interface{}) {
138 - pl.logFuncf(pl.logger.Fatalf, format, args...)
139 -}
140 -func (pl *prefixLogger) Infof(format string, args ...interface{}) {
141 - pl.logFuncf(pl.logger.Infof, format, args...)
142 -}
143 -func (pl *prefixLogger) Noticef(format string, args ...interface{}) {
144 - pl.logFuncf(pl.logger.Noticef, format, args...)
145 -}
146 -func (pl *prefixLogger) Panicf(format string, args ...interface{}) {
147 - pl.logFuncf(pl.logger.Panicf, format, args...)
148 -}
149 -func (pl *prefixLogger) Warningf(format string, args ...interface{}) {
150 - pl.logFuncf(pl.logger.Warningf, format, args...)
151 -}