vendor: sirupsen/logrus v1.5.0
full diff: https://github.com/sirupsen/logrus/compare/v1.4.1...v1.5.0 - Ability to DisableHTMLEscape when using the JSON formatter - Support/fixes for go 1.14 - Many many bugfixes Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
		
							
								
								
									
										44
									
								
								vendor/github.com/sirupsen/logrus/README.md
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										44
									
								
								vendor/github.com/sirupsen/logrus/README.md
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -1,8 +1,28 @@ | ||||
| # Logrus <img src="http://i.imgur.com/hTeVwmJ.png" width="40" height="40" alt=":walrus:" class="emoji" title=":walrus:"/> [](https://travis-ci.org/sirupsen/logrus) [](https://godoc.org/github.com/sirupsen/logrus) | ||||
| # Logrus <img src="http://i.imgur.com/hTeVwmJ.png" width="40" height="40" alt=":walrus:" class="emoji" title=":walrus:"/> [](https://travis-ci.org/sirupsen/logrus) [](https://godoc.org/github.com/sirupsen/logrus) | ||||
|  | ||||
| Logrus is a structured logger for Go (golang), completely API compatible with | ||||
| the standard library logger. | ||||
|  | ||||
| **Logrus is in maintenance-mode.** We will not be introducing new features. It's | ||||
| simply too hard to do in a way that won't break many people's projects, which is | ||||
| the last thing you want from your Logging library (again...). | ||||
|  | ||||
| This does not mean Logrus is dead. Logrus will continue to be maintained for | ||||
| security, (backwards compatible) bug fixes, and performance (where we are | ||||
| limited by the interface).  | ||||
|  | ||||
| I believe Logrus' biggest contribution is to have played a part in today's | ||||
| widespread use of structured logging in Golang. There doesn't seem to be a | ||||
| reason to do a major, breaking iteration into Logrus V2, since the fantastic Go | ||||
| community has built those independently. Many fantastic alternatives have sprung | ||||
| up. Logrus would look like those, had it been re-designed with what we know | ||||
| about structured logging in Go today. Check out, for example, | ||||
| [Zerolog][zerolog], [Zap][zap], and [Apex][apex]. | ||||
|  | ||||
| [zerolog]: https://github.com/rs/zerolog | ||||
| [zap]: https://github.com/uber-go/zap | ||||
| [apex]: https://github.com/apex/log | ||||
|  | ||||
| **Seeing weird case-sensitive problems?** It's in the past been possible to | ||||
| import Logrus as both upper- and lower-case. Due to the Go package environment, | ||||
| this caused issues in the community and we needed a standard. Some environments | ||||
| @@ -15,11 +35,6 @@ comments](https://github.com/sirupsen/logrus/issues/553#issuecomment-306591437). | ||||
| For an in-depth explanation of the casing issue, see [this | ||||
| comment](https://github.com/sirupsen/logrus/issues/570#issuecomment-313933276). | ||||
|  | ||||
| **Are you interested in assisting in maintaining Logrus?** Currently I have a | ||||
| lot of obligations, and I am unable to provide Logrus with the maintainership it | ||||
| needs. If you'd like to help, please reach out to me at `simon at author's | ||||
| username dot com`. | ||||
|  | ||||
| Nicely color-coded in development (when a TTY is attached, otherwise just | ||||
| plain text): | ||||
|  | ||||
| @@ -187,7 +202,7 @@ func main() { | ||||
|   log.Out = os.Stdout | ||||
|  | ||||
|   // You could set this to any `io.Writer` such as a file | ||||
|   // file, err := os.OpenFile("logrus.log", os.O_CREATE|os.O_WRONLY, 0666) | ||||
|   // file, err := os.OpenFile("logrus.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) | ||||
|   // if err == nil { | ||||
|   //  log.Out = file | ||||
|   // } else { | ||||
| @@ -272,7 +287,7 @@ func init() { | ||||
| ``` | ||||
| Note: Syslog hook also support connecting to local syslog (Ex. "/dev/log" or "/var/run/syslog" or "/var/run/log"). For the detail, please check the [syslog hook README](hooks/syslog/README.md). | ||||
|  | ||||
| A list of currently known of service hook can be found in this wiki [page](https://github.com/sirupsen/logrus/wiki/Hooks) | ||||
| A list of currently known service hooks can be found in this wiki [page](https://github.com/sirupsen/logrus/wiki/Hooks) | ||||
|  | ||||
|  | ||||
| #### Level logging | ||||
| @@ -354,6 +369,7 @@ The built-in logging formatters are: | ||||
|     [github.com/mattn/go-colorable](https://github.com/mattn/go-colorable). | ||||
|   * When colors are enabled, levels are truncated to 4 characters by default. To disable | ||||
|     truncation set the `DisableLevelTruncation` field to `true`. | ||||
|   * When outputting to a TTY, it's often helpful to visually scan down a column where all the levels are the same width. Setting the `PadLevelText` field to `true` enables this behavior, by adding padding to the level text. | ||||
|   * All options are listed in the [generated docs](https://godoc.org/github.com/sirupsen/logrus#TextFormatter). | ||||
| * `logrus.JSONFormatter`. Logs fields as JSON. | ||||
|   * All options are listed in the [generated docs](https://godoc.org/github.com/sirupsen/logrus#JSONFormatter). | ||||
| @@ -364,8 +380,10 @@ Third party logging formatters: | ||||
| * [`GELF`](https://github.com/fabienm/go-logrus-formatters). Formats entries so they comply to Graylog's [GELF 1.1 specification](http://docs.graylog.org/en/2.4/pages/gelf.html). | ||||
| * [`logstash`](https://github.com/bshuster-repo/logrus-logstash-hook). Logs fields as [Logstash](http://logstash.net) Events. | ||||
| * [`prefixed`](https://github.com/x-cray/logrus-prefixed-formatter). Displays log entry source along with alternative layout. | ||||
| * [`zalgo`](https://github.com/aybabtme/logzalgo). Invoking the P͉̫o̳̼̊w̖͈̰͎e̬͔̭͂r͚̼̹̲ ̫͓͉̳͈ō̠͕͖̚f̝͍̠ ͕̲̞͖͑Z̖̫̤̫ͪa͉̬͈̗l͖͎g̳̥o̰̥̅!̣͔̲̻͊̄ ̙̘̦̹̦. | ||||
| * [`zalgo`](https://github.com/aybabtme/logzalgo). Invoking the Power of Zalgo. | ||||
| * [`nested-logrus-formatter`](https://github.com/antonfisher/nested-logrus-formatter). Converts logrus fields to a nested structure. | ||||
| * [`powerful-logrus-formatter`](https://github.com/zput/zxcTool). get fileName, log's line number and the latest function's name when print log; Sava log to files. | ||||
| * [`caption-json-formatter`](https://github.com/nolleh/caption_json_formatter). logrus's message json formatter with human-readable caption added. | ||||
|  | ||||
| You can define your formatter by implementing the `Formatter` interface, | ||||
| requiring a `Format` method. `Format` takes an `*Entry`. `entry.Data` is a | ||||
| @@ -430,14 +448,14 @@ entries. It should not be a feature of the application-level logger. | ||||
|  | ||||
| | Tool | Description | | ||||
| | ---- | ----------- | | ||||
| |[Logrus Mate](https://github.com/gogap/logrus_mate)|Logrus mate is a tool for Logrus to manage loggers, you can initial logger's level, hook and formatter by config file, the logger will generated with different config at different environment.| | ||||
| |[Logrus Mate](https://github.com/gogap/logrus_mate)|Logrus mate is a tool for Logrus to manage loggers, you can initial logger's level, hook and formatter by config file, the logger will be generated with different configs in different environments.| | ||||
| |[Logrus Viper Helper](https://github.com/heirko/go-contrib/tree/master/logrusHelper)|An Helper around Logrus to wrap with spf13/Viper to load configuration with fangs! And to simplify Logrus configuration use some behavior of [Logrus Mate](https://github.com/gogap/logrus_mate). [sample](https://github.com/heirko/iris-contrib/blob/master/middleware/logrus-logger/example) | | ||||
|  | ||||
| #### Testing | ||||
|  | ||||
| Logrus has a built in facility for asserting the presence of log messages. This is implemented through the `test` hook and provides: | ||||
|  | ||||
| * decorators for existing logger (`test.NewLocal` and `test.NewGlobal`) which basically just add the `test` hook | ||||
| * decorators for existing logger (`test.NewLocal` and `test.NewGlobal`) which basically just adds the `test` hook | ||||
| * a test logger (`test.NewNullLogger`) that just records log messages (and does not output any): | ||||
|  | ||||
| ```go | ||||
| @@ -465,7 +483,7 @@ func TestSomething(t*testing.T){ | ||||
|  | ||||
| Logrus can register one or more functions that will be called when any `fatal` | ||||
| level message is logged. The registered handlers will be executed before | ||||
| logrus performs a `os.Exit(1)`. This behavior may be helpful if callers need | ||||
| logrus performs an `os.Exit(1)`. This behavior may be helpful if callers need | ||||
| to gracefully shutdown. Unlike a `panic("Something went wrong...")` call which can be intercepted with a deferred `recover` a call to `os.Exit(1)` can not be intercepted. | ||||
|  | ||||
| ``` | ||||
| @@ -490,6 +508,6 @@ Situation when locking is not needed includes: | ||||
|  | ||||
|   1) logger.Out is protected by locks. | ||||
|  | ||||
|   2) logger.Out is a os.File handler opened with `O_APPEND` flag, and every write is smaller than 4k. (This allow multi-thread/multi-process writing) | ||||
|   2) logger.Out is an os.File handler opened with `O_APPEND` flag, and every write is smaller than 4k. (This allows multi-thread/multi-process writing) | ||||
|  | ||||
|      (Refer to http://www.notthewizard.com/2014/06/17/are-files-appends-really-atomic/) | ||||
|   | ||||
							
								
								
									
										49
									
								
								vendor/github.com/sirupsen/logrus/entry.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										49
									
								
								vendor/github.com/sirupsen/logrus/entry.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -85,10 +85,15 @@ func NewEntry(logger *Logger) *Entry { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // Returns the bytes representation of this entry from the formatter. | ||||
| func (entry *Entry) Bytes() ([]byte, error) { | ||||
| 	return entry.Logger.Formatter.Format(entry) | ||||
| } | ||||
|  | ||||
| // Returns the string representation from the reader and ultimately the | ||||
| // formatter. | ||||
| func (entry *Entry) String() (string, error) { | ||||
| 	serialized, err := entry.Logger.Formatter.Format(entry) | ||||
| 	serialized, err := entry.Bytes() | ||||
| 	if err != nil { | ||||
| 		return "", err | ||||
| 	} | ||||
| @@ -103,7 +108,11 @@ func (entry *Entry) WithError(err error) *Entry { | ||||
|  | ||||
| // Add a context to the Entry. | ||||
| func (entry *Entry) WithContext(ctx context.Context) *Entry { | ||||
| 	return &Entry{Logger: entry.Logger, Data: entry.Data, Time: entry.Time, err: entry.err, Context: ctx} | ||||
| 	dataCopy := make(Fields, len(entry.Data)) | ||||
| 	for k, v := range entry.Data { | ||||
| 		dataCopy[k] = v | ||||
| 	} | ||||
| 	return &Entry{Logger: entry.Logger, Data: dataCopy, Time: entry.Time, err: entry.err, Context: ctx} | ||||
| } | ||||
|  | ||||
| // Add a single field to the Entry. | ||||
| @@ -113,6 +122,8 @@ func (entry *Entry) WithField(key string, value interface{}) *Entry { | ||||
|  | ||||
| // Add a map of fields to the Entry. | ||||
| func (entry *Entry) WithFields(fields Fields) *Entry { | ||||
| 	entry.Logger.mu.Lock() | ||||
| 	defer entry.Logger.mu.Unlock() | ||||
| 	data := make(Fields, len(entry.Data)+len(fields)) | ||||
| 	for k, v := range entry.Data { | ||||
| 		data[k] = v | ||||
| @@ -144,7 +155,11 @@ func (entry *Entry) WithFields(fields Fields) *Entry { | ||||
|  | ||||
| // Overrides the time of the Entry. | ||||
| func (entry *Entry) WithTime(t time.Time) *Entry { | ||||
| 	return &Entry{Logger: entry.Logger, Data: entry.Data, Time: t, err: entry.err, Context: entry.Context} | ||||
| 	dataCopy := make(Fields, len(entry.Data)) | ||||
| 	for k, v := range entry.Data { | ||||
| 		dataCopy[k] = v | ||||
| 	} | ||||
| 	return &Entry{Logger: entry.Logger, Data: dataCopy, Time: t, err: entry.err, Context: entry.Context} | ||||
| } | ||||
|  | ||||
| // getPackageName reduces a fully qualified function name to the package name | ||||
| @@ -165,15 +180,20 @@ func getPackageName(f string) string { | ||||
|  | ||||
| // getCaller retrieves the name of the first non-logrus calling function | ||||
| func getCaller() *runtime.Frame { | ||||
|  | ||||
| 	// cache this package's fully-qualified name | ||||
| 	callerInitOnce.Do(func() { | ||||
| 		pcs := make([]uintptr, 2) | ||||
| 		pcs := make([]uintptr, maximumCallerDepth) | ||||
| 		_ = runtime.Callers(0, pcs) | ||||
| 		logrusPackage = getPackageName(runtime.FuncForPC(pcs[1]).Name()) | ||||
|  | ||||
| 		// now that we have the cache, we can skip a minimum count of known-logrus functions | ||||
| 		// XXX this is dubious, the number of frames may vary | ||||
| 		// dynamic get the package name and the minimum caller depth | ||||
| 		for i := 0; i < maximumCallerDepth; i++ { | ||||
| 			funcName := runtime.FuncForPC(pcs[i]).Name() | ||||
| 			if strings.Contains(funcName, "getCaller") { | ||||
| 				logrusPackage = getPackageName(funcName) | ||||
| 				break | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		minimumCallerDepth = knownLogrusFrames | ||||
| 	}) | ||||
|  | ||||
| @@ -187,7 +207,7 @@ func getCaller() *runtime.Frame { | ||||
|  | ||||
| 		// If the caller isn't part of this package, we're done | ||||
| 		if pkg != logrusPackage { | ||||
| 			return &f | ||||
| 			return &f //nolint:scopelint | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| @@ -217,9 +237,11 @@ func (entry Entry) log(level Level, msg string) { | ||||
|  | ||||
| 	entry.Level = level | ||||
| 	entry.Message = msg | ||||
| 	entry.Logger.mu.Lock() | ||||
| 	if entry.Logger.ReportCaller { | ||||
| 		entry.Caller = getCaller() | ||||
| 	} | ||||
| 	entry.Logger.mu.Unlock() | ||||
|  | ||||
| 	entry.fireHooks() | ||||
|  | ||||
| @@ -255,11 +277,10 @@ func (entry *Entry) write() { | ||||
| 	serialized, err := entry.Logger.Formatter.Format(entry) | ||||
| 	if err != nil { | ||||
| 		fmt.Fprintf(os.Stderr, "Failed to obtain reader, %v\n", err) | ||||
| 	} else { | ||||
| 		_, err = entry.Logger.Out.Write(serialized) | ||||
| 		if err != nil { | ||||
| 			fmt.Fprintf(os.Stderr, "Failed to write to log, %v\n", err) | ||||
| 		} | ||||
| 		return | ||||
| 	} | ||||
| 	if _, err = entry.Logger.Out.Write(serialized); err != nil { | ||||
| 		fmt.Fprintf(os.Stderr, "Failed to write to log, %v\n", err) | ||||
| 	} | ||||
| } | ||||
|  | ||||
|   | ||||
							
								
								
									
										2
									
								
								vendor/github.com/sirupsen/logrus/exported.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/github.com/sirupsen/logrus/exported.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -80,7 +80,7 @@ func WithFields(fields Fields) *Entry { | ||||
| 	return std.WithFields(fields) | ||||
| } | ||||
|  | ||||
| // WithTime creats an entry from the standard logger and overrides the time of | ||||
| // WithTime creates an entry from the standard logger and overrides the time of | ||||
| // logs generated with it. | ||||
| // | ||||
| // Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal | ||||
|   | ||||
							
								
								
									
										5
									
								
								vendor/github.com/sirupsen/logrus/go.mod
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								vendor/github.com/sirupsen/logrus/go.mod
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -4,7 +4,8 @@ require ( | ||||
| 	github.com/davecgh/go-spew v1.1.1 // indirect | ||||
| 	github.com/konsorten/go-windows-terminal-sequences v1.0.1 | ||||
| 	github.com/pmezard/go-difflib v1.0.0 // indirect | ||||
| 	github.com/stretchr/objx v0.1.1 // indirect | ||||
| 	github.com/stretchr/testify v1.2.2 | ||||
| 	golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 | ||||
| 	golang.org/x/sys v0.0.0-20190422165155-953cdadca894 | ||||
| ) | ||||
|  | ||||
| go 1.13 | ||||
|   | ||||
							
								
								
									
										4
									
								
								vendor/github.com/sirupsen/logrus/json_formatter.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								vendor/github.com/sirupsen/logrus/json_formatter.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -28,6 +28,9 @@ type JSONFormatter struct { | ||||
| 	// DisableTimestamp allows disabling automatic timestamps in output | ||||
| 	DisableTimestamp bool | ||||
|  | ||||
| 	// DisableHTMLEscape allows disabling html escaping in output | ||||
| 	DisableHTMLEscape bool | ||||
|  | ||||
| 	// DataKey allows users to put all the log entry parameters into a nested dictionary at a given key. | ||||
| 	DataKey string | ||||
|  | ||||
| @@ -110,6 +113,7 @@ func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) { | ||||
| 	} | ||||
|  | ||||
| 	encoder := json.NewEncoder(b) | ||||
| 	encoder.SetEscapeHTML(!f.DisableHTMLEscape) | ||||
| 	if f.PrettyPrint { | ||||
| 		encoder.SetIndent("", "  ") | ||||
| 	} | ||||
|   | ||||
							
								
								
									
										11
									
								
								vendor/github.com/sirupsen/logrus/logger.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										11
									
								
								vendor/github.com/sirupsen/logrus/logger.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -68,10 +68,10 @@ func (mw *MutexWrap) Disable() { | ||||
| // `Out` and `Hooks` directly on the default logger instance. You can also just | ||||
| // instantiate your own: | ||||
| // | ||||
| //    var log = &Logger{ | ||||
| //    var log = &logrus.Logger{ | ||||
| //      Out: os.Stderr, | ||||
| //      Formatter: new(JSONFormatter), | ||||
| //      Hooks: make(LevelHooks), | ||||
| //      Formatter: new(logrus.JSONFormatter), | ||||
| //      Hooks: make(logrus.LevelHooks), | ||||
| //      Level: logrus.DebugLevel, | ||||
| //    } | ||||
| // | ||||
| @@ -100,8 +100,9 @@ func (logger *Logger) releaseEntry(entry *Entry) { | ||||
| 	logger.entryPool.Put(entry) | ||||
| } | ||||
|  | ||||
| // Adds a field to the log entry, note that it doesn't log until you call | ||||
| // Debug, Print, Info, Warn, Error, Fatal or Panic. It only creates a log entry. | ||||
| // WithField allocates a new entry and adds a field to it. | ||||
| // Debug, Print, Info, Warn, Error, Fatal or Panic must be then applied to | ||||
| // this new returned entry. | ||||
| // If you want multiple fields, use `WithFields`. | ||||
| func (logger *Logger) WithField(key string, value interface{}) *Entry { | ||||
| 	entry := logger.newEntry() | ||||
|   | ||||
							
								
								
									
										2
									
								
								vendor/github.com/sirupsen/logrus/logrus.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/github.com/sirupsen/logrus/logrus.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -51,7 +51,7 @@ func (level *Level) UnmarshalText(text []byte) error { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	*level = Level(l) | ||||
| 	*level = l | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|   | ||||
							
								
								
									
										2
									
								
								vendor/github.com/sirupsen/logrus/terminal_check_bsd.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/github.com/sirupsen/logrus/terminal_check_bsd.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -1,4 +1,5 @@ | ||||
| // +build darwin dragonfly freebsd netbsd openbsd | ||||
| // +build !js | ||||
|  | ||||
| package logrus | ||||
|  | ||||
| @@ -10,4 +11,3 @@ func isTerminal(fd int) bool { | ||||
| 	_, err := unix.IoctlGetTermios(fd, ioctlReadTermios) | ||||
| 	return err == nil | ||||
| } | ||||
|  | ||||
|   | ||||
							
								
								
									
										6
									
								
								vendor/github.com/sirupsen/logrus/terminal_check_js.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								vendor/github.com/sirupsen/logrus/terminal_check_js.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -2,10 +2,6 @@ | ||||
|  | ||||
| package logrus | ||||
|  | ||||
| import ( | ||||
| 	"io" | ||||
| ) | ||||
|  | ||||
| func checkIfTerminal(w io.Writer) bool { | ||||
| func isTerminal(fd int) bool { | ||||
| 	return false | ||||
| } | ||||
|   | ||||
							
								
								
									
										11
									
								
								vendor/github.com/sirupsen/logrus/terminal_check_no_terminal.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								vendor/github.com/sirupsen/logrus/terminal_check_no_terminal.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| // +build js nacl plan9 | ||||
|  | ||||
| package logrus | ||||
|  | ||||
| import ( | ||||
| 	"io" | ||||
| ) | ||||
|  | ||||
| func checkIfTerminal(w io.Writer) bool { | ||||
| 	return false | ||||
| } | ||||
							
								
								
									
										2
									
								
								vendor/github.com/sirupsen/logrus/terminal_check_notappengine.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/github.com/sirupsen/logrus/terminal_check_notappengine.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -1,4 +1,4 @@ | ||||
| // +build !appengine,!js,!windows | ||||
| // +build !appengine,!js,!windows,!nacl,!plan9 | ||||
|  | ||||
| package logrus | ||||
|  | ||||
|   | ||||
							
								
								
									
										11
									
								
								vendor/github.com/sirupsen/logrus/terminal_check_solaris.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								vendor/github.com/sirupsen/logrus/terminal_check_solaris.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| package logrus | ||||
|  | ||||
| import ( | ||||
| 	"golang.org/x/sys/unix" | ||||
| ) | ||||
|  | ||||
| // IsTerminal returns true if the given file descriptor is a terminal. | ||||
| func isTerminal(fd int) bool { | ||||
| 	_, err := unix.IoctlGetTermio(fd, unix.TCGETA) | ||||
| 	return err == nil | ||||
| } | ||||
							
								
								
									
										2
									
								
								vendor/github.com/sirupsen/logrus/terminal_check_unix.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/github.com/sirupsen/logrus/terminal_check_unix.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -1,4 +1,5 @@ | ||||
| // +build linux aix | ||||
| // +build !js | ||||
|  | ||||
| package logrus | ||||
|  | ||||
| @@ -10,4 +11,3 @@ func isTerminal(fd int) bool { | ||||
| 	_, err := unix.IoctlGetTermios(fd, ioctlReadTermios) | ||||
| 	return err == nil | ||||
| } | ||||
|  | ||||
|   | ||||
							
								
								
									
										18
									
								
								vendor/github.com/sirupsen/logrus/terminal_check_windows.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										18
									
								
								vendor/github.com/sirupsen/logrus/terminal_check_windows.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -6,15 +6,29 @@ import ( | ||||
| 	"io" | ||||
| 	"os" | ||||
| 	"syscall" | ||||
|  | ||||
| 	sequences "github.com/konsorten/go-windows-terminal-sequences" | ||||
| ) | ||||
|  | ||||
| func initTerminal(w io.Writer) { | ||||
| 	switch v := w.(type) { | ||||
| 	case *os.File: | ||||
| 		sequences.EnableVirtualTerminalProcessing(syscall.Handle(v.Fd()), true) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func checkIfTerminal(w io.Writer) bool { | ||||
| 	var ret bool | ||||
| 	switch v := w.(type) { | ||||
| 	case *os.File: | ||||
| 		var mode uint32 | ||||
| 		err := syscall.GetConsoleMode(syscall.Handle(v.Fd()), &mode) | ||||
| 		return err == nil | ||||
| 		ret = (err == nil) | ||||
| 	default: | ||||
| 		return false | ||||
| 		ret = false | ||||
| 	} | ||||
| 	if ret { | ||||
| 		initTerminal(w) | ||||
| 	} | ||||
| 	return ret | ||||
| } | ||||
|   | ||||
							
								
								
									
										8
									
								
								vendor/github.com/sirupsen/logrus/terminal_notwindows.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										8
									
								
								vendor/github.com/sirupsen/logrus/terminal_notwindows.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -1,8 +0,0 @@ | ||||
| // +build !windows | ||||
|  | ||||
| package logrus | ||||
|  | ||||
| import "io" | ||||
|  | ||||
| func initTerminal(w io.Writer) { | ||||
| } | ||||
							
								
								
									
										18
									
								
								vendor/github.com/sirupsen/logrus/terminal_windows.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										18
									
								
								vendor/github.com/sirupsen/logrus/terminal_windows.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -1,18 +0,0 @@ | ||||
| // +build !appengine,!js,windows | ||||
|  | ||||
| package logrus | ||||
|  | ||||
| import ( | ||||
| 	"io" | ||||
| 	"os" | ||||
| 	"syscall" | ||||
|  | ||||
| 	sequences "github.com/konsorten/go-windows-terminal-sequences" | ||||
| ) | ||||
|  | ||||
| func initTerminal(w io.Writer) { | ||||
| 	switch v := w.(type) { | ||||
| 	case *os.File: | ||||
| 		sequences.EnableVirtualTerminalProcessing(syscall.Handle(v.Fd()), true) | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										49
									
								
								vendor/github.com/sirupsen/logrus/text_formatter.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										49
									
								
								vendor/github.com/sirupsen/logrus/text_formatter.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -6,9 +6,11 @@ import ( | ||||
| 	"os" | ||||
| 	"runtime" | ||||
| 	"sort" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| 	"sync" | ||||
| 	"time" | ||||
| 	"unicode/utf8" | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| @@ -32,6 +34,9 @@ type TextFormatter struct { | ||||
| 	// Force disabling colors. | ||||
| 	DisableColors bool | ||||
|  | ||||
| 	// Force quoting of all values | ||||
| 	ForceQuote bool | ||||
|  | ||||
| 	// Override coloring based on CLICOLOR and CLICOLOR_FORCE. - https://bixense.com/clicolors/ | ||||
| 	EnvironmentOverrideColors bool | ||||
|  | ||||
| @@ -57,6 +62,10 @@ type TextFormatter struct { | ||||
| 	// Disables the truncation of the level text to 4 characters. | ||||
| 	DisableLevelTruncation bool | ||||
|  | ||||
| 	// PadLevelText Adds padding the level text so that all the levels output at the same length | ||||
| 	// PadLevelText is a superset of the DisableLevelTruncation option | ||||
| 	PadLevelText bool | ||||
|  | ||||
| 	// QuoteEmptyFields will wrap empty fields in quotes if true | ||||
| 	QuoteEmptyFields bool | ||||
|  | ||||
| @@ -79,14 +88,20 @@ type TextFormatter struct { | ||||
| 	CallerPrettyfier func(*runtime.Frame) (function string, file string) | ||||
|  | ||||
| 	terminalInitOnce sync.Once | ||||
|  | ||||
| 	// The max length of the level text, generated dynamically on init | ||||
| 	levelTextMaxLength int | ||||
| } | ||||
|  | ||||
| func (f *TextFormatter) init(entry *Entry) { | ||||
| 	if entry.Logger != nil { | ||||
| 		f.isTerminal = checkIfTerminal(entry.Logger.Out) | ||||
|  | ||||
| 		if f.isTerminal { | ||||
| 			initTerminal(entry.Logger.Out) | ||||
| 	} | ||||
| 	// Get the max length of the level text | ||||
| 	for _, level := range AllLevels { | ||||
| 		levelTextLength := utf8.RuneCount([]byte(level.String())) | ||||
| 		if levelTextLength > f.levelTextMaxLength { | ||||
| 			f.levelTextMaxLength = levelTextLength | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @@ -95,11 +110,10 @@ func (f *TextFormatter) isColored() bool { | ||||
| 	isColored := f.ForceColors || (f.isTerminal && (runtime.GOOS != "windows")) | ||||
|  | ||||
| 	if f.EnvironmentOverrideColors { | ||||
| 		if force, ok := os.LookupEnv("CLICOLOR_FORCE"); ok && force != "0" { | ||||
| 		switch force, ok := os.LookupEnv("CLICOLOR_FORCE"); { | ||||
| 		case ok && force != "0": | ||||
| 			isColored = true | ||||
| 		} else if ok && force == "0" { | ||||
| 			isColored = false | ||||
| 		} else if os.Getenv("CLICOLOR") == "0" { | ||||
| 		case ok && force == "0", os.Getenv("CLICOLOR") == "0": | ||||
| 			isColored = false | ||||
| 		} | ||||
| 	} | ||||
| @@ -221,9 +235,18 @@ func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []strin | ||||
| 	} | ||||
|  | ||||
| 	levelText := strings.ToUpper(entry.Level.String()) | ||||
| 	if !f.DisableLevelTruncation { | ||||
| 	if !f.DisableLevelTruncation && !f.PadLevelText { | ||||
| 		levelText = levelText[0:4] | ||||
| 	} | ||||
| 	if f.PadLevelText { | ||||
| 		// Generates the format string used in the next line, for example "%-6s" or "%-7s". | ||||
| 		// Based on the max level text length. | ||||
| 		formatString := "%-" + strconv.Itoa(f.levelTextMaxLength) + "s" | ||||
| 		// Formats the level text by appending spaces up to the max length, for example: | ||||
| 		// 	- "INFO   " | ||||
| 		//	- "WARNING" | ||||
| 		levelText = fmt.Sprintf(formatString, levelText) | ||||
| 	} | ||||
|  | ||||
| 	// Remove a single newline if it already exists in the message to keep | ||||
| 	// the behavior of logrus text_formatter the same as the stdlib log package | ||||
| @@ -247,11 +270,12 @@ func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []strin | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if f.DisableTimestamp { | ||||
| 	switch { | ||||
| 	case f.DisableTimestamp: | ||||
| 		fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m%s %-44s ", levelColor, levelText, caller, entry.Message) | ||||
| 	} else if !f.FullTimestamp { | ||||
| 	case !f.FullTimestamp: | ||||
| 		fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%04d]%s %-44s ", levelColor, levelText, int(entry.Time.Sub(baseTimestamp)/time.Second), caller, entry.Message) | ||||
| 	} else { | ||||
| 	default: | ||||
| 		fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s]%s %-44s ", levelColor, levelText, entry.Time.Format(timestampFormat), caller, entry.Message) | ||||
| 	} | ||||
| 	for _, k := range keys { | ||||
| @@ -262,6 +286,9 @@ func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []strin | ||||
| } | ||||
|  | ||||
| func (f *TextFormatter) needsQuoting(text string) bool { | ||||
| 	if f.ForceQuote { | ||||
| 		return true | ||||
| 	} | ||||
| 	if f.QuoteEmptyFields && len(text) == 0 { | ||||
| 		return true | ||||
| 	} | ||||
|   | ||||
							
								
								
									
										6
									
								
								vendor/github.com/sirupsen/logrus/writer.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								vendor/github.com/sirupsen/logrus/writer.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -6,10 +6,16 @@ import ( | ||||
| 	"runtime" | ||||
| ) | ||||
|  | ||||
| // Writer at INFO level. See WriterLevel for details. | ||||
| func (logger *Logger) Writer() *io.PipeWriter { | ||||
| 	return logger.WriterLevel(InfoLevel) | ||||
| } | ||||
|  | ||||
| // WriterLevel returns an io.Writer that can be used to write arbitrary text to | ||||
| // the logger at the given log level. Each line written to the writer will be | ||||
| // printed in the usual way using formatters and hooks. The writer is part of an | ||||
| // io.Pipe and it is the callers responsibility to close the writer when done. | ||||
| // This can be used to override the standard library logger easily. | ||||
| func (logger *Logger) WriterLevel(level Level) *io.PipeWriter { | ||||
| 	return NewEntry(logger).WriterLevel(level) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Sebastiaan van Stijn
					Sebastiaan van Stijn