Rename definitions to log.go, add valid prefixes

master
Harshavardhana 9 years ago
parent d7acf90b81
commit 7fa514351c
  1. 8
      pkg/server/api/logging-handlers.go
  2. 64
      pkg/utils/log/log.go

@ -22,10 +22,8 @@ import (
"io"
"net/http"
"os"
"strconv"
"time"
"github.com/dustin/go-humanize"
"github.com/minio/minio/pkg/iodine"
"github.com/minio/minio/pkg/utils/log"
)
@ -40,7 +38,6 @@ type logMessage struct {
StartTime time.Time
Duration time.Duration
StatusMessage string // human readable http status message
ContentLength string // human readable content length
// HTTP detailed message
HTTP struct {
@ -85,9 +82,6 @@ func getLogMessage(logMessage *logMessage, w http.ResponseWriter, req *http.Requ
logMessage.HTTP.ResponseHeaders = w.Header()
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)
js, _ := json.Marshal(logMessage)
js = append(js, byte('\n')) // append a new line
@ -110,7 +104,7 @@ func fileLogger(filename string) (chan<- []byte, error) {
go func() {
for message := range ch {
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.
// Use of this source code is governed by a BSD-style
// 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,
// 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.
// 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.
// 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).
func (l *Logger) Fatal(v ...interface{}) {
l.SetPrefix("FATAL:")
l.Output(2, fmt.Sprint(v...))
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{}) {
l.SetPrefix("FATAL:")
l.Output(2, fmt.Sprintf(format, v...))
os.Exit(1)
}
// Fatalln is equivalent to l.Println() followed by a call to os.Exit(1).
func (l *Logger) Fatalln(v ...interface{}) {
l.SetPrefix("FATAL:")
l.Output(2, fmt.Sprintln(v...))
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().
func (l *Logger) Panic(v ...interface{}) {
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).
func Fatal(v ...interface{}) {
std.SetPrefix("FATAL:")
std.Output(2, fmt.Sprint(v...))
os.Exit(1)
}
// Fatalf is equivalent to Printf() followed by a call to os.Exit(1).
func Fatalf(format string, v ...interface{}) {
std.SetPrefix("FATAL:")
std.Output(2, fmt.Sprintf(format, v...))
os.Exit(1)
}
// Fatalln is equivalent to Println() followed by a call to os.Exit(1).
func Fatalln(v ...interface{}) {
std.SetPrefix("FATAL:")
std.Output(2, fmt.Sprintln(v...))
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().
func Panic(v ...interface{}) {
s := fmt.Sprint(v...)
Loading…
Cancel
Save