blob: 2994521aa8eb5019250c6c48973bbea4846a063f [file] [log] [blame]
Fumitoshi Ukai119dc912015-03-30 16:52:41 +09001package main
2
3import (
4 "bytes"
5 "fmt"
Shinichiro Hamaji0ec07702015-03-31 00:50:32 +09006 "os"
Shinichiro Hamajib0a0cf62015-04-11 10:25:36 +09007 "runtime/pprof"
Fumitoshi Ukai119dc912015-03-30 16:52:41 +09008)
9
Shinichiro Hamaji294a58b2015-04-14 15:31:52 +090010func log(f string, a ...interface{}) {
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090011 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 Hamaji750988e2015-04-12 10:14:32 +090018func LogStats(f string, a ...interface{}) {
19 if !katiLogFlag && !katiStatsFlag {
20 return
21 }
22 log(f, a...)
23}
24
25func Log(f string, a ...interface{}) {
26 if !katiLogFlag {
27 return
28 }
29 log(f, a...)
30}
31
Shinichiro Hamaji7c4e3252015-03-30 23:04:25 +090032func 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 Ukai119dc912015-03-30 16:52:41 +090035}
36
Shinichiro Hamajia06760f2015-04-07 13:13:45 +090037func 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 Hamaji0ec07702015-03-31 00:50:32 +090042func Error(filename string, lineno int, f string, a ...interface{}) {
Shinichiro Hamajib0a0cf62015-04-11 10:25:36 +090043 f = fmt.Sprintf("%s:%d: %s", filename, lineno, f)
Shinichiro Hamaji5ff9b342015-04-12 04:17:10 +090044 maybeWriteHeapProfile()
Shinichiro Hamajib0a0cf62015-04-11 10:25:36 +090045 ErrorNoLocation(f, a...)
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090046}
Shinichiro Hamajib2fd38d2015-04-01 01:12:19 +090047
48func ErrorNoLocation(f string, a ...interface{}) {
49 f = fmt.Sprintf("%s\n", f)
50 fmt.Printf(f, a...)
Shinichiro Hamajib0a0cf62015-04-11 10:25:36 +090051 if cpuprofile != "" {
52 pprof.StopCPUProfile()
53 }
Shinichiro Hamaji5ff9b342015-04-12 04:17:10 +090054 maybeWriteHeapProfile()
Shinichiro Hamajib2fd38d2015-04-01 01:12:19 +090055 os.Exit(2)
56}