2015-01-18 08:59:10 +03:00
|
|
|
// Copyright (c) 2014-2015, b3log.org
|
2014-12-20 12:53:37 +03:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
package log
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2014-12-21 07:07:33 +03:00
|
|
|
// Logger.
|
2014-12-20 12:53:37 +03:00
|
|
|
var logger = NewLogger(os.Stdout)
|
|
|
|
|
|
|
|
func TestSetLevel(t *testing.T) {
|
|
|
|
SetLevel("trace")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTrace(t *testing.T) {
|
2014-12-21 06:06:10 +03:00
|
|
|
logger.SetLevel("trace")
|
|
|
|
logger.Trace("trace")
|
|
|
|
logger.SetLevel("off")
|
2014-12-20 12:53:37 +03:00
|
|
|
logger.Trace("trace")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTracef(t *testing.T) {
|
2014-12-21 06:06:10 +03:00
|
|
|
logger.SetLevel("trace")
|
|
|
|
logger.Tracef("tracef")
|
|
|
|
logger.SetLevel("off")
|
2014-12-20 12:53:37 +03:00
|
|
|
logger.Tracef("tracef")
|
|
|
|
}
|
|
|
|
|
2014-12-21 06:06:10 +03:00
|
|
|
func TestDebug(t *testing.T) {
|
|
|
|
logger.SetLevel("debug")
|
|
|
|
logger.Debug("debug")
|
|
|
|
logger.SetLevel("off")
|
|
|
|
logger.Debug("debug")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDebugf(t *testing.T) {
|
|
|
|
logger.SetLevel("debug")
|
|
|
|
logger.Debugf("debugf")
|
|
|
|
logger.SetLevel("off")
|
|
|
|
logger.Debug("debug")
|
|
|
|
}
|
|
|
|
|
2014-12-20 12:53:37 +03:00
|
|
|
func TestInfo(t *testing.T) {
|
2014-12-21 06:06:10 +03:00
|
|
|
logger.SetLevel("info")
|
|
|
|
logger.Info("info")
|
|
|
|
logger.SetLevel("off")
|
2014-12-20 12:53:37 +03:00
|
|
|
logger.Info("info")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInfof(t *testing.T) {
|
2014-12-21 06:06:10 +03:00
|
|
|
logger.SetLevel("info")
|
|
|
|
logger.Infof("infof")
|
|
|
|
logger.SetLevel("off")
|
2014-12-20 12:53:37 +03:00
|
|
|
logger.Infof("infof")
|
|
|
|
}
|
2014-12-21 05:33:27 +03:00
|
|
|
|
|
|
|
func TestWarn(t *testing.T) {
|
2014-12-21 06:06:10 +03:00
|
|
|
logger.SetLevel("warn")
|
|
|
|
logger.Warn("warn")
|
|
|
|
logger.SetLevel("off")
|
2014-12-21 05:33:27 +03:00
|
|
|
logger.Warn("warn")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWarnf(t *testing.T) {
|
2014-12-21 06:06:10 +03:00
|
|
|
logger.SetLevel("warn")
|
|
|
|
logger.Warnf("warnf")
|
|
|
|
logger.SetLevel("off")
|
2014-12-21 05:33:27 +03:00
|
|
|
logger.Warnf("warnf")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestError(t *testing.T) {
|
2014-12-21 06:06:10 +03:00
|
|
|
logger.SetLevel("error")
|
|
|
|
logger.Error("error")
|
|
|
|
logger.SetLevel("off")
|
2014-12-21 05:33:27 +03:00
|
|
|
logger.Error("error")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestErrorf(t *testing.T) {
|
2014-12-21 06:06:10 +03:00
|
|
|
logger.SetLevel("error")
|
|
|
|
logger.Errorf("errorf")
|
|
|
|
logger.SetLevel("off")
|
2014-12-21 05:33:27 +03:00
|
|
|
logger.Errorf("errorf")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetLevel(t *testing.T) {
|
2014-12-21 06:06:10 +03:00
|
|
|
if getLevel("trace") != Trace {
|
|
|
|
t.FailNow()
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if getLevel("debug") != Debug {
|
|
|
|
t.FailNow()
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if getLevel("info") != Info {
|
|
|
|
t.FailNow()
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if getLevel("warn") != Warn {
|
|
|
|
t.FailNow()
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if getLevel("error") != Error {
|
|
|
|
t.FailNow()
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
2014-12-21 05:33:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoggerSetLevel(t *testing.T) {
|
2014-12-21 06:32:22 +03:00
|
|
|
logger.SetLevel("trace")
|
2014-12-21 05:33:27 +03:00
|
|
|
|
2014-12-21 06:32:22 +03:00
|
|
|
if logger.level != Trace {
|
2014-12-21 05:33:27 +03:00
|
|
|
t.FailNow()
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsTraceEnabled(t *testing.T) {
|
|
|
|
logger.SetLevel("trace")
|
|
|
|
|
|
|
|
if !logger.IsTraceEnabled() {
|
|
|
|
t.FailNow()
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsDebugEnabled(t *testing.T) {
|
|
|
|
logger.SetLevel("debug")
|
|
|
|
|
|
|
|
if !logger.IsDebugEnabled() {
|
|
|
|
t.FailNow()
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2014-12-21 06:06:10 +03:00
|
|
|
|
|
|
|
func TestIsWarnEnabled(t *testing.T) {
|
|
|
|
logger.SetLevel("warn")
|
|
|
|
|
|
|
|
if !logger.IsWarnEnabled() {
|
|
|
|
t.FailNow()
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|