Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "fmt" |
Shinichiro Hamaji | 0ec0770 | 2015-03-31 00:50:32 +0900 | [diff] [blame] | 6 | "os" |
Shinichiro Hamaji | b0a0cf6 | 2015-04-11 10:25:36 +0900 | [diff] [blame] | 7 | "runtime/pprof" |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 8 | ) |
| 9 | |
Shinichiro Hamaji | 294a58b | 2015-04-14 15:31:52 +0900 | [diff] [blame] | 10 | func log(f string, a ...interface{}) { |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 11 | var buf bytes.Buffer |
| 12 | buf.WriteString("*kati*: ") |
| 13 | buf.WriteString(f) |
| 14 | buf.WriteByte('\n') |
| 15 | fmt.Printf(buf.String(), a...) |
| 16 | } |
| 17 | |
Shinichiro Hamaji | 750988e | 2015-04-12 10:14:32 +0900 | [diff] [blame] | 18 | func LogStats(f string, a ...interface{}) { |
| 19 | if !katiLogFlag && !katiStatsFlag { |
| 20 | return |
| 21 | } |
| 22 | log(f, a...) |
| 23 | } |
| 24 | |
| 25 | func Log(f string, a ...interface{}) { |
| 26 | if !katiLogFlag { |
| 27 | return |
| 28 | } |
| 29 | log(f, a...) |
| 30 | } |
| 31 | |
Shinichiro Hamaji | 7c4e325 | 2015-03-30 23:04:25 +0900 | [diff] [blame] | 32 | func Warn(filename string, lineno int, f string, a ...interface{}) { |
| 33 | f = fmt.Sprintf("%s:%d: warning: %s\n", filename, lineno, f) |
| 34 | fmt.Printf(f, a...) |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 35 | } |
| 36 | |
Shinichiro Hamaji | a06760f | 2015-04-07 13:13:45 +0900 | [diff] [blame] | 37 | func WarnNoPrefix(filename string, lineno int, f string, a ...interface{}) { |
| 38 | f = fmt.Sprintf("%s:%d: %s\n", filename, lineno, f) |
| 39 | fmt.Printf(f, a...) |
| 40 | } |
| 41 | |
Shinichiro Hamaji | 0ec0770 | 2015-03-31 00:50:32 +0900 | [diff] [blame] | 42 | func Error(filename string, lineno int, f string, a ...interface{}) { |
Shinichiro Hamaji | b0a0cf6 | 2015-04-11 10:25:36 +0900 | [diff] [blame] | 43 | f = fmt.Sprintf("%s:%d: %s", filename, lineno, f) |
Shinichiro Hamaji | 5ff9b34 | 2015-04-12 04:17:10 +0900 | [diff] [blame] | 44 | maybeWriteHeapProfile() |
Shinichiro Hamaji | b0a0cf6 | 2015-04-11 10:25:36 +0900 | [diff] [blame] | 45 | ErrorNoLocation(f, a...) |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 46 | } |
Shinichiro Hamaji | b2fd38d | 2015-04-01 01:12:19 +0900 | [diff] [blame] | 47 | |
| 48 | func ErrorNoLocation(f string, a ...interface{}) { |
| 49 | f = fmt.Sprintf("%s\n", f) |
| 50 | fmt.Printf(f, a...) |
Shinichiro Hamaji | b0a0cf6 | 2015-04-11 10:25:36 +0900 | [diff] [blame] | 51 | if cpuprofile != "" { |
| 52 | pprof.StopCPUProfile() |
| 53 | } |
Shinichiro Hamaji | 5ff9b34 | 2015-04-12 04:17:10 +0900 | [diff] [blame] | 54 | maybeWriteHeapProfile() |
Fumitoshi Ukai | 6ac7f69 | 2015-04-15 17:13:51 +0900 | [diff] [blame] | 55 | dumpStats() |
Shinichiro Hamaji | b2fd38d | 2015-04-01 01:12:19 +0900 | [diff] [blame] | 56 | os.Exit(2) |
| 57 | } |