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