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 | |
| 10 | func Log(f string, a ...interface{}) { |
Fumitoshi Ukai | b07bcc3 | 2015-04-07 12:03:31 +0900 | [diff] [blame] | 11 | if !katiLogFlag { |
Shinichiro Hamaji | 07259e0 | 2015-04-02 03:14:41 +0900 | [diff] [blame] | 12 | return |
| 13 | } |
| 14 | |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 15 | var buf bytes.Buffer |
| 16 | buf.WriteString("*kati*: ") |
| 17 | buf.WriteString(f) |
| 18 | buf.WriteByte('\n') |
| 19 | fmt.Printf(buf.String(), a...) |
| 20 | } |
| 21 | |
Shinichiro Hamaji | 7c4e325 | 2015-03-30 23:04:25 +0900 | [diff] [blame] | 22 | func Warn(filename string, lineno int, f string, a ...interface{}) { |
| 23 | f = fmt.Sprintf("%s:%d: warning: %s\n", filename, lineno, f) |
| 24 | fmt.Printf(f, a...) |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 25 | } |
| 26 | |
Shinichiro Hamaji | a06760f | 2015-04-07 13:13:45 +0900 | [diff] [blame] | 27 | func WarnNoPrefix(filename string, lineno int, f string, a ...interface{}) { |
| 28 | f = fmt.Sprintf("%s:%d: %s\n", filename, lineno, f) |
| 29 | fmt.Printf(f, a...) |
| 30 | } |
| 31 | |
Shinichiro Hamaji | 0ec0770 | 2015-03-31 00:50:32 +0900 | [diff] [blame] | 32 | func Error(filename string, lineno int, f string, a ...interface{}) { |
Shinichiro Hamaji | b0a0cf6 | 2015-04-11 10:25:36 +0900 | [diff] [blame] | 33 | f = fmt.Sprintf("%s:%d: %s", filename, lineno, f) |
| 34 | ErrorNoLocation(f, a...) |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 35 | } |
Shinichiro Hamaji | b2fd38d | 2015-04-01 01:12:19 +0900 | [diff] [blame] | 36 | |
| 37 | func ErrorNoLocation(f string, a ...interface{}) { |
| 38 | f = fmt.Sprintf("%s\n", f) |
| 39 | fmt.Printf(f, a...) |
Shinichiro Hamaji | b0a0cf6 | 2015-04-11 10:25:36 +0900 | [diff] [blame] | 40 | if cpuprofile != "" { |
| 41 | pprof.StopCPUProfile() |
| 42 | } |
Shinichiro Hamaji | b2fd38d | 2015-04-01 01:12:19 +0900 | [diff] [blame] | 43 | os.Exit(2) |
| 44 | } |