gf/os/glog/glog_instance.go

32 lines
805 B
Go
Raw Normal View History

2021-01-17 21:46:25 +08:00
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package glog
import "github.com/gogf/gf/container/gmap"
const (
2021-07-15 21:20:29 +08:00
// DefaultName is the default group name for instance usage.
DefaultName = "default"
)
var (
// Instances map.
instances = gmap.NewStrAnyMap(true)
)
// Instance returns an instance of Logger with default settings.
2021-08-08 13:56:26 +08:00
// The parameter `name` is the name for the instance.
func Instance(name ...string) *Logger {
key := DefaultName
if len(name) > 0 && name[0] != "" {
key = name[0]
}
return instances.GetOrSetFuncLock(key, func() interface{} {
return New()
}).(*Logger)
}