| 
									
										
										
										
											2021-04-19 03:41:13 +08:00
										 |  |  | // Copyright (c) 2015-2021 MinIO, Inc.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // 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-05-09 10:04:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | package logger | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2022-07-26 08:53:03 +08:00
										 |  |  | 	"context" | 
					
						
							|  |  |  | 	"errors" | 
					
						
							| 
									
										
										
										
											2018-05-09 10:04:36 +08:00
										 |  |  | 	"fmt" | 
					
						
							| 
									
										
										
										
											2022-07-26 08:53:03 +08:00
										 |  |  | 	"net/http" | 
					
						
							| 
									
										
										
										
											2018-05-09 10:04:36 +08:00
										 |  |  | 	"regexp" | 
					
						
							| 
									
										
										
										
											2020-01-14 05:05:51 +08:00
										 |  |  | 	"runtime" | 
					
						
							| 
									
										
										
										
											2018-05-09 10:04:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-02 05:59:40 +08:00
										 |  |  | 	"github.com/minio/minio/internal/color" | 
					
						
							| 
									
										
										
										
											2018-05-09 10:04:36 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var ansiRE = regexp.MustCompile("(\x1b[^m]*m)") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Print ANSI Control escape
 | 
					
						
							|  |  |  | func ansiEscape(format string, args ...interface{}) { | 
					
						
							| 
									
										
										
										
											2022-01-03 01:15:06 +08:00
										 |  |  | 	Esc := "\x1b" | 
					
						
							| 
									
										
										
										
											2018-05-09 10:04:36 +08:00
										 |  |  | 	fmt.Printf("%s%s", Esc, fmt.Sprintf(format, args...)) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func ansiMoveRight(n int) { | 
					
						
							| 
									
										
										
										
											2020-01-14 05:05:51 +08:00
										 |  |  | 	if runtime.GOOS == "windows" { | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-10-05 01:35:33 +08:00
										 |  |  | 	if color.IsTerminal() { | 
					
						
							| 
									
										
										
										
											2018-08-06 20:46:49 +08:00
										 |  |  | 		ansiEscape("[%dC", n) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-09 10:04:36 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func ansiSaveAttributes() { | 
					
						
							| 
									
										
										
										
											2020-01-14 05:05:51 +08:00
										 |  |  | 	if runtime.GOOS == "windows" { | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-10-05 01:35:33 +08:00
										 |  |  | 	if color.IsTerminal() { | 
					
						
							| 
									
										
										
										
											2018-08-06 20:46:49 +08:00
										 |  |  | 		ansiEscape("7") | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-09 10:04:36 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func ansiRestoreAttributes() { | 
					
						
							| 
									
										
										
										
											2020-01-14 05:05:51 +08:00
										 |  |  | 	if runtime.GOOS == "windows" { | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-10-05 01:35:33 +08:00
										 |  |  | 	if color.IsTerminal() { | 
					
						
							| 
									
										
										
										
											2018-08-06 20:46:49 +08:00
										 |  |  | 		ansiEscape("8") | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-19 03:04:46 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-07-26 08:53:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // logIgnoreError if true,the error will ignore.
 | 
					
						
							|  |  |  | func logIgnoreError(err error) bool { | 
					
						
							| 
									
										
										
										
											2022-08-05 07:10:08 +08:00
										 |  |  | 	return err == nil || errors.Is(err, context.Canceled) || errors.Is(err, http.ErrServerClosed) || err.Error() == "drive not found" | 
					
						
							| 
									
										
										
										
											2022-07-26 08:53:03 +08:00
										 |  |  | } |