mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
Merge pull request #730 from harshavardhana/pr_out_rename_definitions_to_log_go_add_valid_prefixes
This commit is contained in:
commit
39026cb64b
@ -22,10 +22,8 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/dustin/go-humanize"
|
|
||||||
"github.com/minio/minio/pkg/iodine"
|
"github.com/minio/minio/pkg/iodine"
|
||||||
"github.com/minio/minio/pkg/utils/log"
|
"github.com/minio/minio/pkg/utils/log"
|
||||||
)
|
)
|
||||||
@ -40,7 +38,6 @@ type logMessage struct {
|
|||||||
StartTime time.Time
|
StartTime time.Time
|
||||||
Duration time.Duration
|
Duration time.Duration
|
||||||
StatusMessage string // human readable http status message
|
StatusMessage string // human readable http status message
|
||||||
ContentLength string // human readable content length
|
|
||||||
|
|
||||||
// HTTP detailed message
|
// HTTP detailed message
|
||||||
HTTP struct {
|
HTTP struct {
|
||||||
@ -85,9 +82,6 @@ func getLogMessage(logMessage *logMessage, w http.ResponseWriter, req *http.Requ
|
|||||||
logMessage.HTTP.ResponseHeaders = w.Header()
|
logMessage.HTTP.ResponseHeaders = w.Header()
|
||||||
logMessage.HTTP.Request = req
|
logMessage.HTTP.Request = req
|
||||||
|
|
||||||
// humanize content-length to be printed in logs
|
|
||||||
contentLength, _ := strconv.Atoi(logMessage.HTTP.ResponseHeaders.Get("Content-Length"))
|
|
||||||
logMessage.ContentLength = humanize.IBytes(uint64(contentLength))
|
|
||||||
logMessage.Duration = time.Now().UTC().Sub(logMessage.StartTime)
|
logMessage.Duration = time.Now().UTC().Sub(logMessage.StartTime)
|
||||||
js, _ := json.Marshal(logMessage)
|
js, _ := json.Marshal(logMessage)
|
||||||
js = append(js, byte('\n')) // append a new line
|
js = append(js, byte('\n')) // append a new line
|
||||||
@ -110,7 +104,7 @@ func fileLogger(filename string) (chan<- []byte, error) {
|
|||||||
go func() {
|
go func() {
|
||||||
for message := range ch {
|
for message := range ch {
|
||||||
if _, err := io.Copy(file, bytes.NewBuffer(message)); err != nil {
|
if _, err := io.Copy(file, bytes.NewBuffer(message)); err != nil {
|
||||||
log.Println(iodine.New(err, nil))
|
log.Errorln(iodine.New(err, nil))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -1,6 +1,26 @@
|
|||||||
|
//
|
||||||
|
// Minimalist Object Storage, (C) 2015 Minio, Inc.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
// Copyright 2009 The Go Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
// Golang project:
|
||||||
|
// https://github.com/golang/go/blob/master/LICENSE
|
||||||
|
|
||||||
|
// Using this part of Minio codebase under the license
|
||||||
|
// Apache License Version 2.0 with modifications
|
||||||
|
|
||||||
// Package log implements a simple logging package. It defines a type, Logger,
|
// Package log implements a simple logging package. It defines a type, Logger,
|
||||||
// with methods for formatting output. It also has a predefined 'standard'
|
// with methods for formatting output. It also has a predefined 'standard'
|
||||||
@ -171,30 +191,55 @@ func (l *Logger) Printf(format string, v ...interface{}) {
|
|||||||
|
|
||||||
// Print calls l.Output to print to the logger.
|
// Print calls l.Output to print to the logger.
|
||||||
// Arguments are handled in the manner of fmt.Print.
|
// Arguments are handled in the manner of fmt.Print.
|
||||||
func (l *Logger) Print(v ...interface{}) { l.Output(2, fmt.Sprint(v...)) }
|
func (l *Logger) Print(v ...interface{}) {
|
||||||
|
l.Output(2, fmt.Sprint(v...))
|
||||||
|
}
|
||||||
|
|
||||||
// Println calls l.Output to print to the logger.
|
// Println calls l.Output to print to the logger.
|
||||||
// Arguments are handled in the manner of fmt.Println.
|
// Arguments are handled in the manner of fmt.Println.
|
||||||
func (l *Logger) Println(v ...interface{}) { l.Output(2, fmt.Sprintln(v...)) }
|
func (l *Logger) Println(v ...interface{}) {
|
||||||
|
l.Output(2, fmt.Sprintln(v...))
|
||||||
|
}
|
||||||
|
|
||||||
// Fatal is equivalent to l.Print() followed by a call to os.Exit(1).
|
// Fatal is equivalent to l.Print() followed by a call to os.Exit(1).
|
||||||
func (l *Logger) Fatal(v ...interface{}) {
|
func (l *Logger) Fatal(v ...interface{}) {
|
||||||
|
l.SetPrefix("FATAL:")
|
||||||
l.Output(2, fmt.Sprint(v...))
|
l.Output(2, fmt.Sprint(v...))
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fatalf is equivalent to l.Printf() followed by a call to os.Exit(1).
|
// Fatalf is equivalent to l.Printf() followed by a call to os.Exit(1).
|
||||||
func (l *Logger) Fatalf(format string, v ...interface{}) {
|
func (l *Logger) Fatalf(format string, v ...interface{}) {
|
||||||
|
l.SetPrefix("FATAL:")
|
||||||
l.Output(2, fmt.Sprintf(format, v...))
|
l.Output(2, fmt.Sprintf(format, v...))
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fatalln is equivalent to l.Println() followed by a call to os.Exit(1).
|
// Fatalln is equivalent to l.Println() followed by a call to os.Exit(1).
|
||||||
func (l *Logger) Fatalln(v ...interface{}) {
|
func (l *Logger) Fatalln(v ...interface{}) {
|
||||||
|
l.SetPrefix("FATAL:")
|
||||||
l.Output(2, fmt.Sprintln(v...))
|
l.Output(2, fmt.Sprintln(v...))
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Error is equivalent to l.Print() followed by a call to os.Exit(1).
|
||||||
|
func (l *Logger) Error(v ...interface{}) {
|
||||||
|
l.SetPrefix("ERROR:")
|
||||||
|
l.Output(2, fmt.Sprint(v...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Errorf is equivalent to l.Printf() followed by a call to os.Exit(1).
|
||||||
|
func (l *Logger) Errorf(format string, v ...interface{}) {
|
||||||
|
l.SetPrefix("ERROR:")
|
||||||
|
l.Output(2, fmt.Sprintf(format, v...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Errorln is equivalent to l.Println() followed by a call to os.Exit(1).
|
||||||
|
func (l *Logger) Errorln(v ...interface{}) {
|
||||||
|
l.SetPrefix("ERROR:")
|
||||||
|
l.Output(2, fmt.Sprintln(v...))
|
||||||
|
}
|
||||||
|
|
||||||
// Panic is equivalent to l.Print() followed by a call to panic().
|
// Panic is equivalent to l.Print() followed by a call to panic().
|
||||||
func (l *Logger) Panic(v ...interface{}) {
|
func (l *Logger) Panic(v ...interface{}) {
|
||||||
s := fmt.Sprint(v...)
|
s := fmt.Sprint(v...)
|
||||||
@ -293,22 +338,37 @@ func Println(v ...interface{}) {
|
|||||||
|
|
||||||
// Fatal is equivalent to Print() followed by a call to os.Exit(1).
|
// Fatal is equivalent to Print() followed by a call to os.Exit(1).
|
||||||
func Fatal(v ...interface{}) {
|
func Fatal(v ...interface{}) {
|
||||||
|
std.SetPrefix("FATAL:")
|
||||||
std.Output(2, fmt.Sprint(v...))
|
std.Output(2, fmt.Sprint(v...))
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fatalf is equivalent to Printf() followed by a call to os.Exit(1).
|
// Fatalf is equivalent to Printf() followed by a call to os.Exit(1).
|
||||||
func Fatalf(format string, v ...interface{}) {
|
func Fatalf(format string, v ...interface{}) {
|
||||||
|
std.SetPrefix("FATAL:")
|
||||||
std.Output(2, fmt.Sprintf(format, v...))
|
std.Output(2, fmt.Sprintf(format, v...))
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fatalln is equivalent to Println() followed by a call to os.Exit(1).
|
// Fatalln is equivalent to Println() followed by a call to os.Exit(1).
|
||||||
func Fatalln(v ...interface{}) {
|
func Fatalln(v ...interface{}) {
|
||||||
|
std.SetPrefix("FATAL:")
|
||||||
std.Output(2, fmt.Sprintln(v...))
|
std.Output(2, fmt.Sprintln(v...))
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Errorf is equivalent to Printf() followed by a call to os.Exit(1).
|
||||||
|
func Errorf(format string, v ...interface{}) {
|
||||||
|
std.SetPrefix("ERROR:")
|
||||||
|
std.Output(2, fmt.Sprintf(format, v...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Errorln is equivalent to Println() followed by a call to os.Exit(1).
|
||||||
|
func Errorln(v ...interface{}) {
|
||||||
|
std.SetPrefix("ERROR:")
|
||||||
|
std.Output(2, fmt.Sprintln(v...))
|
||||||
|
}
|
||||||
|
|
||||||
// Panic is equivalent to Print() followed by a call to panic().
|
// Panic is equivalent to Print() followed by a call to panic().
|
||||||
func Panic(v ...interface{}) {
|
func Panic(v ...interface{}) {
|
||||||
s := fmt.Sprint(v...)
|
s := fmt.Sprint(v...)
|
Loading…
Reference in New Issue
Block a user