Merge lp:~pedronis/ubuntu-push/log-line-nums into lp:ubuntu-push/automatic

Proposed by Samuele Pedroni
Status: Merged
Approved by: Samuele Pedroni
Approved revision: 365
Merged at revision: 363
Proposed branch: lp:~pedronis/ubuntu-push/log-line-nums
Merge into: lp:ubuntu-push/automatic
Diff against target: 98 lines (+25/-8)
3 files modified
logger/logger.go (+12/-7)
logger/logger_test.go (+12/-0)
server/acceptance/suites/helpers.go (+1/-1)
To merge this branch: bzr merge lp:~pedronis/ubuntu-push/log-line-nums
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
Review via email: mp+248912@code.launchpad.net

Commit message

log line nums, enabled when logLevel = debug

Description of the change

basically lp:~noise/ubuntu-push/log-line-nums plus fixing acceptance tests

To post a comment you must log in.
Revision history for this message
John Lenton (chipaca) :
review: Approve
365. By Samuele Pedroni

nits

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'logger/logger.go'
2--- logger/logger.go 2014-04-11 23:17:40 +0000
3+++ logger/logger.go 2015-02-06 13:56:07 +0000
4@@ -50,7 +50,8 @@
5 }
6
7 const (
8- lError = iota
9+ calldepthBase = 3
10+ lError = iota
11 lInfo
12 lDebug
13 )
14@@ -81,8 +82,12 @@
15 // level. The level can be, in order: "error", "info", "debug". It takes an
16 // io.Writer.
17 func NewSimpleLogger(w io.Writer, level string) Logger {
18+ flags := log.Ldate | log.Ltime | log.Lmicroseconds
19+ if levelToNLevel[level] >= lDebug {
20+ flags = flags | log.Lshortfile
21+ }
22 return NewSimpleLoggerFromMinimalLogger(
23- log.New(w, "", log.Ldate|log.Ltime|log.Lmicroseconds),
24+ log.New(w, "", flags),
25 level,
26 )
27 }
28@@ -92,13 +97,13 @@
29 }
30
31 func (lg *simpleLogger) Errorf(format string, v ...interface{}) {
32- lg.outputFunc(2, fmt.Sprintf("ERROR "+format, v...))
33+ lg.outputFunc(calldepthBase, fmt.Sprintf("ERROR "+format, v...))
34 }
35
36 var osExit = os.Exit // for testing
37
38 func (lg *simpleLogger) Fatalf(format string, v ...interface{}) {
39- lg.outputFunc(2, fmt.Sprintf("ERROR "+format, v...))
40+ lg.outputFunc(calldepthBase, fmt.Sprintf("ERROR "+format, v...))
41 osExit(1)
42 }
43
44@@ -107,18 +112,18 @@
45 stack := make([]byte, 8*1024) // Stack writes less but doesn't fail
46 stackWritten := runtime.Stack(stack, false)
47 stack = stack[:stackWritten]
48- lg.outputFunc(2, fmt.Sprintf("ERROR(PANIC) %s:\n%s", msg, stack))
49+ lg.outputFunc(calldepthBase, fmt.Sprintf("ERROR(PANIC) %s:\n%s", msg, stack))
50 }
51
52 func (lg *simpleLogger) Infof(format string, v ...interface{}) {
53 if lg.nlevel >= lInfo {
54- lg.outputFunc(2, fmt.Sprintf("INFO "+format, v...))
55+ lg.outputFunc(calldepthBase, fmt.Sprintf("INFO "+format, v...))
56 }
57 }
58
59 func (lg *simpleLogger) Debugf(format string, v ...interface{}) {
60 if lg.nlevel >= lDebug {
61- lg.outputFunc(2, fmt.Sprintf("DEBUG "+format, v...))
62+ lg.outputFunc(calldepthBase, fmt.Sprintf("DEBUG "+format, v...))
63 }
64 }
65
66
67=== modified file 'logger/logger_test.go'
68--- logger/logger_test.go 2014-04-11 19:05:35 +0000
69+++ logger/logger_test.go 2015-02-06 13:56:07 +0000
70@@ -163,3 +163,15 @@
71 checkError(`{"lvl": 1}`, "lvl:.*type string")
72 checkError(`{"lvl": "foo"}`, "lvl: not a log level: foo")
73 }
74+
75+func (s *loggerSuite) TestLogLineNo(c *C) {
76+ buf := &bytes.Buffer{}
77+ logger := NewSimpleLogger(buf, "debug")
78+ logger.Output(1, "foobaz")
79+ c.Check(buf.String(), Matches, ".* .* logger_test.go:[0-9]+: foobaz\n")
80+
81+ buf.Reset()
82+ logger = NewSimpleLogger(buf, "error")
83+ logger.Output(1, "foobaz")
84+ c.Check(buf.String(), Matches, ".* .* foobaz\n")
85+}
86
87=== modified file 'server/acceptance/suites/helpers.go'
88--- server/acceptance/suites/helpers.go 2014-11-04 16:29:31 +0000
89+++ server/acceptance/suites/helpers.go 2015-02-06 13:56:07 +0000
90@@ -80,7 +80,7 @@
91 return cfgFpath
92 }
93
94-var rxLineInfo = regexp.MustCompile("^.*? ([[:alpha:]].*)\n")
95+var rxLineInfo = regexp.MustCompile("^.*?(?: .+\\.go:\\d+:)? ([[:alpha:]].*)\n")
96
97 // RunAndObserve runs cmdName and returns a channel that will receive
98 // cmdName stderr logging and a function to kill the process.

Subscribers

People subscribed via source and target branches