| 
									
										
										
										
											2024-07-13 04:51:54 +08:00
										 |  |  | // Copyright (c) 2015-2024 MinIO, Inc.
 | 
					
						
							| 
									
										
										
										
											2021-04-19 03:41:13 +08:00
										 |  |  | //
 | 
					
						
							|  |  |  | // This file is part of MinIO Object Storage stack
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // This program is free software: you can redistribute it and/or modify
 | 
					
						
							|  |  |  | // it under the terms of the GNU Affero General Public License as published by
 | 
					
						
							|  |  |  | // the Free Software Foundation, either version 3 of the License, or
 | 
					
						
							|  |  |  | // (at your option) any later version.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					
						
							|  |  |  | // GNU Affero General Public License for more details.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU Affero General Public License
 | 
					
						
							|  |  |  | // along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							| 
									
										
										
										
											2018-07-20 06:55:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | package logger | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"encoding/json" | 
					
						
							|  |  |  | 	"fmt" | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | 	"os" | 
					
						
							| 
									
										
										
										
											2018-07-20 06:55:06 +08:00
										 |  |  | 	"strings" | 
					
						
							|  |  |  | 	"time" | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-02 05:59:40 +08:00
										 |  |  | 	"github.com/minio/minio/internal/color" | 
					
						
							| 
									
										
										
										
											2024-05-25 07:05:23 +08:00
										 |  |  | 	"github.com/minio/pkg/v3/logger/message/log" | 
					
						
							| 
									
										
										
										
											2018-07-20 06:55:06 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-18 09:50:10 +08:00
										 |  |  | // ConsoleLoggerTgt is a stringified value to represent console logging
 | 
					
						
							|  |  |  | const ConsoleLoggerTgt = "console+http" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-23 02:57:27 +08:00
										 |  |  | // ExitFunc is called by Fatal() class functions, by default it calls os.Exit()
 | 
					
						
							|  |  |  | var ExitFunc = os.Exit | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-08 13:47:56 +08:00
										 |  |  | // Logger interface describes the methods that need to be implemented to satisfy the interface requirements.
 | 
					
						
							|  |  |  | type Logger interface { | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | 	json(msg string, args ...interface{}) | 
					
						
							|  |  |  | 	quiet(msg string, args ...interface{}) | 
					
						
							|  |  |  | 	pretty(msg string, args ...interface{}) | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-07-20 06:55:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-08 13:47:56 +08:00
										 |  |  | func consoleLog(console Logger, msg string, args ...interface{}) { | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | 	switch { | 
					
						
							|  |  |  | 	case jsonFlag: | 
					
						
							|  |  |  | 		// Strip escape control characters from json message
 | 
					
						
							|  |  |  | 		msg = ansiRE.ReplaceAllLiteralString(msg, "") | 
					
						
							|  |  |  | 		console.json(msg, args...) | 
					
						
							|  |  |  | 	case quietFlag: | 
					
						
							| 
									
										
										
										
											2023-10-02 21:39:47 +08:00
										 |  |  | 		if len(msg) != 0 && len(args) == 0 { | 
					
						
							|  |  |  | 			args = append(args, msg) | 
					
						
							|  |  |  | 			msg = "%s" | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-06-05 02:11:30 +08:00
										 |  |  | 		console.quiet(msg+"\n", args...) | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2023-10-02 21:39:47 +08:00
										 |  |  | 		if len(msg) != 0 && len(args) == 0 { | 
					
						
							|  |  |  | 			args = append(args, msg) | 
					
						
							|  |  |  | 			msg = "%s" | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-06-05 02:11:30 +08:00
										 |  |  | 		console.pretty(msg+"\n", args...) | 
					
						
							| 
									
										
										
										
											2018-10-13 03:25:59 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Fatal prints only fatal error message with no stack trace
 | 
					
						
							|  |  |  | // it will be called for input validation failures
 | 
					
						
							|  |  |  | func Fatal(err error, msg string, data ...interface{}) { | 
					
						
							|  |  |  | 	fatal(err, msg, data...) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func fatal(err error, msg string, data ...interface{}) { | 
					
						
							| 
									
										
										
										
											2024-05-19 16:06:49 +08:00
										 |  |  | 	if msg == "" { | 
					
						
							|  |  |  | 		if len(data) > 0 { | 
					
						
							|  |  |  | 			msg = fmt.Sprint(data...) | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			msg = "a fatal error" | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2024-05-19 16:06:49 +08:00
										 |  |  | 		msg = fmt.Sprintf(msg, data...) | 
					
						
							| 
									
										
										
										
											2018-07-20 06:55:06 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-05-19 16:06:49 +08:00
										 |  |  | 	consoleLog(fatalMessage, errorFmtFunc(msg, err, jsonFlag)) | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-07-20 06:55:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | var fatalMessage fatalMsg | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-03 01:15:06 +08:00
										 |  |  | type fatalMsg struct{} | 
					
						
							| 
									
										
										
										
											2018-07-20 06:55:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | func (f fatalMsg) json(msg string, args ...interface{}) { | 
					
						
							| 
									
										
										
										
											2021-06-05 02:11:30 +08:00
										 |  |  | 	var message string | 
					
						
							|  |  |  | 	if msg != "" { | 
					
						
							|  |  |  | 		message = fmt.Sprintf(msg, args...) | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		message = fmt.Sprint(args...) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | 	logJSON, err := json.Marshal(&log.Entry{ | 
					
						
							| 
									
										
										
										
											2024-02-02 08:13:57 +08:00
										 |  |  | 		Level:   FatalKind, | 
					
						
							| 
									
										
										
										
											2021-06-05 02:11:30 +08:00
										 |  |  | 		Message: message, | 
					
						
							| 
									
										
										
										
											2021-12-24 07:33:54 +08:00
										 |  |  | 		Time:    time.Now().UTC(), | 
					
						
							| 
									
										
										
										
											2021-06-05 02:11:30 +08:00
										 |  |  | 		Trace:   &log.Trace{Message: message, Source: []string{getSource(6)}}, | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		panic(err) | 
					
						
							| 
									
										
										
										
											2018-07-20 06:55:06 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-05-02 01:57:52 +08:00
										 |  |  | 	fmt.Fprintln(Output, string(logJSON)) | 
					
						
							| 
									
										
										
										
											2022-09-23 02:57:27 +08:00
										 |  |  | 	ExitFunc(1) | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (f fatalMsg) quiet(msg string, args ...interface{}) { | 
					
						
							|  |  |  | 	f.pretty(msg, args...) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var ( | 
					
						
							| 
									
										
										
										
											2024-07-13 04:51:54 +08:00
										 |  |  | 	logTag      = "FATAL" | 
					
						
							| 
									
										
										
										
											2019-10-05 01:35:33 +08:00
										 |  |  | 	logBanner   = color.BgRed(color.FgWhite(color.Bold(logTag))) + " " | 
					
						
							|  |  |  | 	emptyBanner = color.BgRed(strings.Repeat(" ", len(logTag))) + " " | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | 	bannerWidth = len(logTag) + 1 | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (f fatalMsg) pretty(msg string, args ...interface{}) { | 
					
						
							|  |  |  | 	// Build the passed error message
 | 
					
						
							|  |  |  | 	errMsg := fmt.Sprintf(msg, args...) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tagPrinted := false | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Print the error message: the following code takes care
 | 
					
						
							|  |  |  | 	// of splitting error text and always pretty printing the
 | 
					
						
							|  |  |  | 	// red banner along with the error message. Since the error
 | 
					
						
							|  |  |  | 	// message itself contains some colored text, we needed
 | 
					
						
							|  |  |  | 	// to use some ANSI control escapes to cursor color state
 | 
					
						
							|  |  |  | 	// and freely move in the screen.
 | 
					
						
							|  |  |  | 	for _, line := range strings.Split(errMsg, "\n") { | 
					
						
							|  |  |  | 		if len(line) == 0 { | 
					
						
							|  |  |  | 			// No more text to print, just quit.
 | 
					
						
							|  |  |  | 			break | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for { | 
					
						
							|  |  |  | 			// Save the attributes of the current cursor helps
 | 
					
						
							|  |  |  | 			// us save the text color of the passed error message
 | 
					
						
							|  |  |  | 			ansiSaveAttributes() | 
					
						
							|  |  |  | 			// Print banner with or without the log tag
 | 
					
						
							|  |  |  | 			if !tagPrinted { | 
					
						
							| 
									
										
										
										
											2024-05-02 01:57:52 +08:00
										 |  |  | 				fmt.Fprint(Output, logBanner) | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | 				tagPrinted = true | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2024-05-02 01:57:52 +08:00
										 |  |  | 				fmt.Fprint(Output, emptyBanner) | 
					
						
							| 
									
										
										
										
											2018-07-20 06:55:06 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | 			// Restore the text color of the error message
 | 
					
						
							|  |  |  | 			ansiRestoreAttributes() | 
					
						
							|  |  |  | 			ansiMoveRight(bannerWidth) | 
					
						
							|  |  |  | 			// Continue  error message printing
 | 
					
						
							| 
									
										
										
										
											2024-05-02 01:57:52 +08:00
										 |  |  | 			fmt.Fprintln(Output, line) | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | 			break | 
					
						
							| 
									
										
										
										
											2018-07-20 06:55:06 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | 	// Exit because this is a fatal error message
 | 
					
						
							| 
									
										
										
										
											2022-09-23 02:57:27 +08:00
										 |  |  | 	ExitFunc(1) | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-07-20 06:55:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | type infoMsg struct{} | 
					
						
							| 
									
										
										
										
											2018-07-20 06:55:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | var info infoMsg | 
					
						
							| 
									
										
										
										
											2018-07-20 06:55:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | func (i infoMsg) json(msg string, args ...interface{}) { | 
					
						
							| 
									
										
										
										
											2021-06-05 02:11:30 +08:00
										 |  |  | 	var message string | 
					
						
							|  |  |  | 	if msg != "" { | 
					
						
							|  |  |  | 		message = fmt.Sprintf(msg, args...) | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		message = fmt.Sprint(args...) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | 	logJSON, err := json.Marshal(&log.Entry{ | 
					
						
							| 
									
										
										
										
											2024-02-02 08:13:57 +08:00
										 |  |  | 		Level:   InfoKind, | 
					
						
							| 
									
										
										
										
											2021-06-05 02:11:30 +08:00
										 |  |  | 		Message: message, | 
					
						
							| 
									
										
										
										
											2021-12-24 07:33:54 +08:00
										 |  |  | 		Time:    time.Now().UTC(), | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		panic(err) | 
					
						
							| 
									
										
										
										
											2018-07-20 06:55:06 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-05-02 01:57:52 +08:00
										 |  |  | 	fmt.Fprintln(Output, string(logJSON)) | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-07-20 06:55:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | func (i infoMsg) quiet(msg string, args ...interface{}) { | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-07-20 06:55:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | func (i infoMsg) pretty(msg string, args ...interface{}) { | 
					
						
							| 
									
										
										
										
											2021-06-05 02:11:30 +08:00
										 |  |  | 	if msg == "" { | 
					
						
							| 
									
										
										
										
											2024-05-02 01:57:52 +08:00
										 |  |  | 		fmt.Fprintln(Output, args...) | 
					
						
							| 
									
										
										
										
											2024-05-19 16:06:49 +08:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2024-07-13 04:51:54 +08:00
										 |  |  | 		fmt.Fprintf(Output, `INFO: `+msg, args...) | 
					
						
							| 
									
										
										
										
											2021-06-05 02:11:30 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-05 02:11:30 +08:00
										 |  |  | type errorMsg struct{} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-19 16:06:49 +08:00
										 |  |  | var errorMessage errorMsg | 
					
						
							| 
									
										
										
										
											2021-06-05 02:11:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | func (i errorMsg) json(msg string, args ...interface{}) { | 
					
						
							|  |  |  | 	var message string | 
					
						
							|  |  |  | 	if msg != "" { | 
					
						
							|  |  |  | 		message = fmt.Sprintf(msg, args...) | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		message = fmt.Sprint(args...) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	logJSON, err := json.Marshal(&log.Entry{ | 
					
						
							| 
									
										
										
										
											2024-02-02 08:13:57 +08:00
										 |  |  | 		Level:   ErrorKind, | 
					
						
							| 
									
										
										
										
											2021-06-05 02:11:30 +08:00
										 |  |  | 		Message: message, | 
					
						
							| 
									
										
										
										
											2021-12-24 07:33:54 +08:00
										 |  |  | 		Time:    time.Now().UTC(), | 
					
						
							| 
									
										
										
										
											2021-06-05 02:11:30 +08:00
										 |  |  | 		Trace:   &log.Trace{Message: message, Source: []string{getSource(6)}}, | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		panic(err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-05-02 01:57:52 +08:00
										 |  |  | 	fmt.Fprintln(Output, string(logJSON)) | 
					
						
							| 
									
										
										
										
											2021-06-05 02:11:30 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (i errorMsg) quiet(msg string, args ...interface{}) { | 
					
						
							|  |  |  | 	i.pretty(msg, args...) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (i errorMsg) pretty(msg string, args ...interface{}) { | 
					
						
							|  |  |  | 	if msg == "" { | 
					
						
							| 
									
										
										
										
											2024-05-02 01:57:52 +08:00
										 |  |  | 		fmt.Fprintln(Output, args...) | 
					
						
							| 
									
										
										
										
											2024-05-19 16:06:49 +08:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2024-07-13 04:51:54 +08:00
										 |  |  | 		fmt.Fprintf(Output, `ERRO: `+msg, args...) | 
					
						
							| 
									
										
										
										
											2021-06-05 02:11:30 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Error :
 | 
					
						
							|  |  |  | func Error(msg string, data ...interface{}) { | 
					
						
							| 
									
										
										
										
											2024-07-13 04:51:54 +08:00
										 |  |  | 	if DisableLog { | 
					
						
							| 
									
										
										
										
											2022-08-30 23:23:40 +08:00
										 |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-05-19 16:06:49 +08:00
										 |  |  | 	consoleLog(errorMessage, msg, data...) | 
					
						
							| 
									
										
										
										
											2021-06-05 02:11:30 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | // Info :
 | 
					
						
							|  |  |  | func Info(msg string, data ...interface{}) { | 
					
						
							| 
									
										
										
										
											2024-07-13 04:51:54 +08:00
										 |  |  | 	if DisableLog { | 
					
						
							| 
									
										
										
										
											2022-08-30 23:23:40 +08:00
										 |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-06-05 02:11:30 +08:00
										 |  |  | 	consoleLog(info, msg, data...) | 
					
						
							| 
									
										
										
										
											2018-11-20 06:47:03 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2024-07-13 04:51:54 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Startup :
 | 
					
						
							|  |  |  | func Startup(msg string, data ...interface{}) { | 
					
						
							|  |  |  | 	if DisableLog { | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	consoleLog(startup, msg, data...) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type startupMsg struct{} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var startup startupMsg | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (i startupMsg) json(msg string, args ...interface{}) { | 
					
						
							|  |  |  | 	var message string | 
					
						
							|  |  |  | 	if msg != "" { | 
					
						
							|  |  |  | 		message = fmt.Sprintf(msg, args...) | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		message = fmt.Sprint(args...) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	logJSON, err := json.Marshal(&log.Entry{ | 
					
						
							|  |  |  | 		Level:   InfoKind, | 
					
						
							|  |  |  | 		Message: message, | 
					
						
							|  |  |  | 		Time:    time.Now().UTC(), | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		panic(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	fmt.Fprintln(Output, string(logJSON)) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (i startupMsg) quiet(msg string, args ...interface{}) { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (i startupMsg) pretty(msg string, args ...interface{}) { | 
					
						
							|  |  |  | 	if msg == "" { | 
					
						
							|  |  |  | 		fmt.Fprintln(Output, args...) | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		fmt.Fprintf(Output, msg, args...) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type warningMsg struct{} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var warningMessage warningMsg | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (i warningMsg) json(msg string, args ...interface{}) { | 
					
						
							|  |  |  | 	var message string | 
					
						
							|  |  |  | 	if msg != "" { | 
					
						
							|  |  |  | 		message = fmt.Sprintf(msg, args...) | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		message = fmt.Sprint(args...) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	logJSON, err := json.Marshal(&log.Entry{ | 
					
						
							|  |  |  | 		Level:   WarningKind, | 
					
						
							|  |  |  | 		Message: message, | 
					
						
							|  |  |  | 		Time:    time.Now().UTC(), | 
					
						
							|  |  |  | 		Trace:   &log.Trace{Message: message, Source: []string{getSource(6)}}, | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		panic(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	fmt.Fprintln(Output, string(logJSON)) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (i warningMsg) quiet(msg string, args ...interface{}) { | 
					
						
							|  |  |  | 	i.pretty(msg, args...) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (i warningMsg) pretty(msg string, args ...interface{}) { | 
					
						
							|  |  |  | 	if msg == "" { | 
					
						
							|  |  |  | 		fmt.Fprintln(Output, args...) | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		fmt.Fprintf(Output, `WARN: `+msg, args...) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Warning :
 | 
					
						
							|  |  |  | func Warning(msg string, data ...interface{}) { | 
					
						
							|  |  |  | 	if DisableLog { | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	consoleLog(warningMessage, msg, data...) | 
					
						
							|  |  |  | } |