示例#1
0
func TestStdLoggerFormat(t *testing.T) {

	var buf bytes.Buffer
	var bufInfo bytes.Buffer
	sl := log.NewStdLogger(
		log.SetStdLevel(log.StdLevelDebug),
		log.SetStdWriter(&buf),
		log.SetStdInfo(&bufInfo, "TEST-INFO ", std.LstdFlags),
	)

	sl.Debug("my Debug", 3.14152)
	sl.Debug("my Debug2", "", 2.14152)
	sl.Debug("my Debug3", "key3", 3105, 4711, "Hello")
	sl.Info("InfoTEST")
	sl.Info("InfoTEST", "keyI", 117, 2009)
	sl.Info("InfoTEST", "Now we have the salad")

	logs := buf.String()
	logsInfo := bufInfo.String()

	assert.Contains(t, logs, "Debug2")
	assert.Contains(t, logs, "BAD_KEY_AT_INDEX_0")
	assert.Contains(t, logs, `key3: 3105 BAD_KEY_AT_INDEX_2: "Hello"`)

	assert.Contains(t, logsInfo, "InfoTEST")
	assert.Contains(t, logsInfo, `_: "Now we have the salad`)
	assert.Contains(t, logsInfo, `FIX_IMBALANCED_PAIRS: []interface {}{"keyI", 117, 2009}`)
}
示例#2
0
func init() {
	debugLogBuf = new(log.MutexBuffer)
	infoLogBuf = new(log.MutexBuffer)

	element.PkgLog = log.NewStdLogger(
		log.SetStdDebug(debugLogBuf, "testDebug: ", std.Lshortfile),
		log.SetStdInfo(infoLogBuf, "testInfo: ", std.Lshortfile),
	)
	element.PkgLog.SetLevel(log.StdLevelDebug)
}
示例#3
0
func TestContext(t *testing.T) {
	l := log.NewStdLogger()
	ctx := context.Background()
	ctx = ctxlog.WithContext(ctx, l)

	haveL := ctxlog.FromContext(ctx)
	assert.Exactly(t, l, haveL)

	haveL2 := ctxlog.FromContext(context.TODO())
	assert.Exactly(t, log.BlackHole{}, haveL2)
}
示例#4
0
func init() {
	debugLogBuf = new(log.MutexBuffer)
	infoLogBuf = new(log.MutexBuffer)

	model.PkgLog = log.NewStdLogger(
		log.SetStdDebug(debugLogBuf, "testDebug: ", std.Lshortfile),
		log.SetStdInfo(infoLogBuf, "testInfo: ", std.Lshortfile),
		log.SetStdDisableStackTrace(),
	)
	model.PkgLog.SetLevel(log.StdLevelDebug)
}
示例#5
0
func TestStdLoggerFatal(t *testing.T) {

	defer func() {
		if r := recover(); r != nil {
			assert.Contains(t, r.(string), "This is sparta")
		}
	}()

	var buf bytes.Buffer
	sl := log.NewStdLogger(
		log.SetStdWriter(&buf),
	)
	sl.Fatal("This is sparta")
}
示例#6
0
func TestStdLoggerNewPanic(t *testing.T) {

	defer func() {
		if r := recover(); r != nil {
			if msg, ok := r.(string); ok {
				assert.EqualValues(t, "Arguments to New() can only be StdOption types!", msg)
			} else {
				t.Error("Expecting a string")
			}
		}
	}()

	var buf bytes.Buffer
	sl := log.NewStdLogger(
		log.SetStdWriter(&buf),
	)
	sl.New(log.SetStdLevel(log.StdLevelDebug), 1)
}
示例#7
0
func TestStdLoggerGlobals(t *testing.T) {

	var buf bytes.Buffer
	sl := log.NewStdLogger(
		log.SetStdLevel(log.StdLevelDebug),
		log.SetStdWriter(&buf),
		log.SetStdFlag(std.Ldate),
	)
	sl.Debug("my Debug", "float", 3.14152)
	sl.Debug("my Debug2", 2.14152)
	sl.Info("InfoTEST")

	logs := buf.String()

	assert.NotContains(t, logs, "trace2")
	assert.Contains(t, logs, "InfoTEST")
	assert.NotContains(t, logs, "trace1")
	assert.Contains(t, logs, "Debug2")
}
示例#8
0
func TestStdLogger(t *testing.T) {

	var buf bytes.Buffer

	sl := log.NewStdLogger(
		log.SetStdLevel(log.StdLevelDebug),
		log.SetStdDebug(&buf, "TEST-DEBUG ", std.LstdFlags),
		log.SetStdInfo(&buf, "TEST-INFO ", std.LstdFlags),
		log.SetStdFatal(&buf, "TEST-FATAL ", std.LstdFlags),
	)
	sl.SetLevel(log.StdLevelInfo)
	assert.False(t, sl.IsDebug())
	assert.True(t, sl.IsInfo())

	sl.Debug("my Debug", "float", 3.14152)
	sl.Debug("my Debug2", 2.14152)
	sl.Info("InfoTEST")

	logs := buf.String()

	assert.Contains(t, logs, "InfoTEST")
	assert.NotContains(t, logs, "Debug2")

	buf.Reset()
	sl.SetLevel(log.StdLevelDebug)
	assert.True(t, sl.IsDebug())
	assert.True(t, sl.IsInfo())
	sl.Debug("my Debug", "float", 3.14152)
	sl.Debug("my Debug2", 2.14152)
	sl.Info("InfoTEST")

	logs = buf.String()

	assert.Contains(t, logs, "InfoTEST")
	assert.Contains(t, logs, "Debug2")

}
func initStore() {
	store.PkgLog = log.NewStdLogger(
		log.SetStdDebug(&testDebugLogBuf, "testErr: ", std.Lshortfile),
	)
	store.PkgLog.SetLevel(log.StdLevelDebug)

	testStoreService = store.MustNewService(
		scope.Option{
			Website: scope.MockID(1), // bound to website ID 1 = Europe
		},
		store.MustNewStorage(
			// Storage gets usually loaded from the database tables containing
			// website, group and store. For the sake of this example the storage
			// is hard coded.
			store.SetStorageWebsites(
				&store.TableWebsite{WebsiteID: 0, Code: dbr.NewNullString("admin"), Name: dbr.NewNullString("Admin"), SortOrder: 0, DefaultGroupID: 0, IsDefault: dbr.NewNullBool(false)},
				&store.TableWebsite{WebsiteID: 1, Code: dbr.NewNullString("euro"), Name: dbr.NewNullString("Europe"), SortOrder: 0, DefaultGroupID: 1, IsDefault: dbr.NewNullBool(true)},
				&store.TableWebsite{WebsiteID: 2, Code: dbr.NewNullString("oz"), Name: dbr.NewNullString("OZ"), SortOrder: 20, DefaultGroupID: 3, IsDefault: dbr.NewNullBool(false)},
			),
			store.SetStorageGroups(
				&store.TableGroup{GroupID: 3, WebsiteID: 2, Name: "Australia", RootCategoryID: 2, DefaultStoreID: 5},
				&store.TableGroup{GroupID: 1, WebsiteID: 1, Name: "DACH Group", RootCategoryID: 2, DefaultStoreID: 2},
				&store.TableGroup{GroupID: 0, WebsiteID: 0, Name: "Default", RootCategoryID: 0, DefaultStoreID: 0},
				&store.TableGroup{GroupID: 2, WebsiteID: 1, Name: "UK Group", RootCategoryID: 2, DefaultStoreID: 4},
			),
			store.SetStorageStores(
				&store.TableStore{StoreID: 0, Code: dbr.NewNullString("admin"), WebsiteID: 0, GroupID: 0, Name: "Admin", SortOrder: 0, IsActive: true},
				&store.TableStore{StoreID: 5, Code: dbr.NewNullString("au"), WebsiteID: 2, GroupID: 3, Name: "Australia", SortOrder: 10, IsActive: true},
				&store.TableStore{StoreID: 1, Code: dbr.NewNullString("de"), WebsiteID: 1, GroupID: 1, Name: "Germany", SortOrder: 10, IsActive: true},
				&store.TableStore{StoreID: 4, Code: dbr.NewNullString("uk"), WebsiteID: 1, GroupID: 2, Name: "UK", SortOrder: 10, IsActive: true},
				&store.TableStore{StoreID: 2, Code: dbr.NewNullString("at"), WebsiteID: 1, GroupID: 1, Name: "Österreich", SortOrder: 20, IsActive: true},
				&store.TableStore{StoreID: 6, Code: dbr.NewNullString("nz"), WebsiteID: 2, GroupID: 3, Name: "Kiwi", SortOrder: 30, IsActive: true},
				&store.TableStore{IsActive: false, StoreID: 3, Code: dbr.NewNullString("ch"), WebsiteID: 1, GroupID: 1, Name: "Schweiz", SortOrder: 30},
			),
		),
	)
}
示例#10
0
文件: main.go 项目: joao-parana/csfw
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
	"sync"

	"github.com/corestoreio/csfw/codegen"
	"github.com/corestoreio/csfw/storage/csdb"
	"github.com/corestoreio/csfw/util/log"
)

// PkgLog global package based logger
var PkgLog log.Logger = log.NewStdLogger(
	log.SetStdLevel(log.StdLevelFatal),
	//log.SetStdLevel(log.StdLevelDebug),
)

func init() {
	codegen.PkgLog = PkgLog
	log.PkgLog = PkgLog
}

func main() {
	defer log.WhenDone(PkgLog).Info("Stats")
	dbc, err := csdb.Connect()
	codegen.LogFatal(err)
	defer dbc.Close()
	var wg sync.WaitGroup

	mageV1, mageV2 := detectMagentoVersion(dbc.NewSession())
示例#11
0
func init() {
	store.PkgLog = log.NewStdLogger(
		log.SetStdDebug(&errLogBuf, "testErr: ", std.Lshortfile),
	)
	store.PkgLog.SetLevel(log.StdLevelDebug)
}