| 39 | } |
| 40 | |
| 41 | func (l *Logger) Log(level int, format string, args ...interface{}) { |
| 42 | l.Lock() |
| 43 | defer l.Unlock() |
| 44 | |
| 45 | if level == DEBUG && !l.debug { |
| 46 | return |
| 47 | } |
| 48 | |
| 49 | if c, ok := LogColors[level]; ok { |
| 50 | c.Printf(format+"\n", args...) |
| 51 | } else { |
| 52 | fmt.Printf(format+"\n", args...) |
| 53 | } |
| 54 | |
| 55 | if level > INFO && session.Config.SlackWebhook != "" { |
| 56 | values := map[string]string{"text": fmt.Sprintf(format+"\n", args...)} |
| 57 | jsonValue, _ := json.Marshal(values) |
| 58 | http.Post(session.Config.SlackWebhook, "application/json", bytes.NewBuffer(jsonValue)) |
| 59 | } |
| 60 | |
| 61 | if level == FATAL { |
| 62 | os.Exit(1) |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | func (l *Logger) Fatal(format string, args ...interface{}) { |
| 67 | l.Log(FATAL, format, args...) |