本文整理匯總了Golang中github.com/koding/logging.NewLogger函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewLogger函數的具體用法?Golang NewLogger怎麽用?Golang NewLogger使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewLogger函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
// Default logger
logging.Debug("Debug")
logging.Info("Info")
logging.Notice("Notice")
logging.Warning("Warning")
logging.Error("Error")
logging.Critical("Critical")
// Custom logger with default handler
l := logging.NewLogger("test")
l.Debug("Debug")
l.Info("Info")
l.Notice("Notice")
l.Warning("Warning")
l.Error("Error")
l.Critical("Critical")
// Custom logger with custom handler
l2 := logging.NewLogger("test2")
l2.SetHandler(&MyHandler{})
l2.Debug("Debug")
l2.Info("Info")
l2.Notice("Notice")
l2.Warning("Warning")
l2.Error("Error")
l2.Critical("Critical")
}
示例2: NewRemote
func NewRemote(machine string) (*Remote, error) {
log := logging.NewLogger("fusetest")
opts := sshCmd.SSHCommandOpts{Ask: true}
s, err := sshCmd.NewSSHCommand(log, opts)
if err != nil {
return nil, err
}
info, err := getMachineInfo(s, machine)
if err != nil {
return nil, err
}
if len(info.Mounts) == 0 {
return nil, errors.New("Machine has no mount. Please mount and try again.")
}
conn, err := dialSSH(s.PrivateKeyPath(), info.Hostname, info.IP)
if err != nil {
return nil, err
}
return &Remote{
SSHConn: conn,
remote: info.Mounts[0].RemotePath,
local: info.Mounts[0].LocalPath,
}, nil
}
示例3: NewPool
func NewPool(k *kite.Kite) *KlientPool {
return &KlientPool{
kite: k,
klients: make(map[string]*Klient),
log: logging.NewLogger("klientpool"),
}
}
示例4: newLogger
func newLogger(name string, debug bool) logging.Logger {
log := logging.NewLogger(name)
logHandler := logging.NewWriterHandler(os.Stderr)
logHandler.Colorize = true
log.SetHandler(logHandler)
if debug {
log.SetLevel(logging.DEBUG)
logHandler.SetLevel(logging.DEBUG)
}
return log
}
示例5: ReadDirectoryHandler
// ReadDirectoryHandler calls a remote machine's fs.readDirectory method with
// the given args.
func (r *Remote) ReadDirectoryHandler(kreq *kite.Request) (interface{}, error) {
log := logging.NewLogger("remote").New("remote.readDirectory")
var params req.ReadDirectoryOptions
if kreq.Args == nil {
return nil, errors.New("arguments are not passed")
}
if err := kreq.Args.One().Unmarshal(¶ms); err != nil {
err = fmt.Errorf(
"remote.readDirectory: Error '%s' while unmarshalling request '%s'\n",
err, kreq.Args.One(),
)
r.log.Error(err.Error())
return nil, err
}
switch {
case params.Machine == "":
return nil, errors.New("Missing required argument `machine`.")
}
log = log.New(
"machineName", params.Machine,
"remotePath", params.Path,
)
remoteMachine, err := r.GetDialedMachine(params.Machine)
if err != nil {
log.Error("Error getting dialed, valid machine. err:%s", err)
return nil, err
}
if params.Path == "" {
home, err := remoteMachine.HomeWithDefault()
if err != nil {
return nil, err
}
params.Path = home
}
if !filepath.IsAbs(params.Path) {
home, err := remoteMachine.HomeWithDefault()
if err != nil {
return nil, err
}
params.Path = path.Join(home, params.Path)
}
return remoteMachine.Tell("fs.readDirectory", params)
}
示例6: New
// New creates a new Kloud instance without initializing the default providers.
func New() *Kloud {
log := logging.NewLogger(NAME)
kld := &Kloud{
idlock: idlock.New(),
Log: log,
Eventers: make(map[string]eventer.Eventer),
providers: make(map[string]Provider),
statusCache: cache.NewMemoryWithTTL(time.Second * 10),
}
kld.statusCache.StartGC(time.Second * 5)
return kld
}
示例7: newLogger
// newLogger returns a new kite logger based on koding/logging package and a
// SetLogLvel function. The current logLevel is INFO by default, which can be
// changed with KITE_LOG_LEVEL environment variable.
func newLogger(name string) (Logger, func(Level)) {
logger := logging.NewLogger(name)
logger.SetLevel(convertLevel(getLogLevel()))
if os.Getenv("KITE_LOG_NOCOLOR") != "" {
logging.StdoutHandler.Colorize = false
logging.StderrHandler.Colorize = false
}
setLevel := func(l Level) {
logger.SetLevel(convertLevel(l))
logging.DefaultHandler.SetLevel(convertLevel(l))
}
return logger, setLevel
}
示例8: TestMain
func TestMain(m *testing.M) {
var err error
vg, err = NewVagrant(vagrantName)
if err != nil {
log.Fatalln(err)
}
vg.Log = logging.NewLogger("vagrantutil_test")
vg.Log.SetLevel(logging.DEBUG)
h := logging.NewWriterHandler(os.Stderr)
h.SetLevel(logging.DEBUG)
vg.Log.SetHandler(h)
ret := m.Run()
os.RemoveAll(vagrantName)
os.Exit(ret)
}
示例9: main
func main() {
rmq := rabbitmq.New(
&rabbitmq.Config{
Host: "localhost",
Port: 5672,
Username: "guest",
Password: "guest",
Vhost: "/",
},
logging.NewLogger("producer"),
)
exchange := rabbitmq.Exchange{
Name: "EXCHANGE_NAME",
}
queue := rabbitmq.Queue{}
publishingOptions := rabbitmq.PublishingOptions{
Tag: "ProducerTagHede",
RoutingKey: "naber",
}
publisher, err := rmq.NewProducer(exchange, queue, publishingOptions)
if err != nil {
panic(err)
}
defer publisher.Shutdown()
publisher.RegisterSignalHandler()
// may be we should autoconvert to byte array?
msg := amqp.Publishing{
Body: []byte("2"),
}
publisher.NotifyReturn(func(message amqp.Return) {
fmt.Println(message)
})
for i := 0; i < 10; i++ {
err = publisher.Publish(msg)
if err != nil {
fmt.Println(err, i)
}
}
}
示例10: main
func main() {
// command line parameter parsing
configfile := flag.String("cfg", "mambo.cfg", "Main configuration file")
flag.Parse()
logger := logging.NewLogger("Mambo")
logger.Notice("Mambo collector started")
logger.Notice("Loading configuration from %s", *configfile)
// The 'results' channel will recive the results of the mysqlWorker queries
results := make(chan string)
config, commands := configure(*configfile) // Loading configuration and commands from ini file
for _, command := range commands {
go controller(command, config, results) // every command will launch a command controller
}
logger.Notice("Data collector running")
for {
select {
// every time a MySQL worker yield data to the 'results' channel we call a statsdSender and we send that data to statsdserver
case msg := <-results:
{
statsdSender(config, msg)
}
}
}
}
示例11: NewRemote
// NewRemote creates a new Remote instance.
func NewRemote(opts *RemoteOptions) *Remote {
// TODO: Improve this usage. Basically i want a proper koding/logging struct,
// but we need to create it from somewhere. klient is always uses kite.Logger,
// which **should** always be implemented by a koding/logging.Logger.. but in
// the event that it's not, how do we handle it?
kodingLog, ok := opts.Log.(logging.Logger)
if !ok {
opts.Log.Error(
"Unable to convert koding/kite.Logger to koding/logging.Logger. Creating new logger",
)
kodingLog = logging.NewLogger("new-logger")
}
kodingLog = kodingLog.New("remote")
// Setting the handler to debug, because various Remote methods allow a
// debug option, and this saves us from having to set the handler level every time.
// This only sets handler, not the actual loglevel.
logging.DefaultHandler.SetLevel(logging.DEBUG)
r := &Remote{
localKite: opts.Kite,
kitesGetter: &KodingKite{Kite: opts.Kite},
storage: opts.Storage,
log: kodingLog,
machinesErrCacheMax: 5 * time.Minute,
machinesCacheMax: 10 * time.Second,
machineNamesCache: map[string]string{},
unmountPath: fuseklient.Unmount,
machines: machine.NewMachines(kodingLog, opts.Storage),
maxRestoreAttempts: defaultMaxRestoreAttempts,
restoreFailuresPause: defaultRestoreFailuresPause,
eventSub: opts.EventSub,
}
return r
}
示例12:
"strings"
"time"
"koding/kites/kloud/api/amazon"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/service/route53"
"github.com/cenkalti/backoff"
"github.com/dchest/validator"
"github.com/koding/logging"
)
var ErrNoRecord = errors.New("no records available")
var defaultLog = logging.NewLogger("kloud-dns")
type Route53 struct {
*route53.Route53
ZoneId string
opts *Options
}
type Options struct {
Creds *credentials.Credentials
HostedZone string
Log logging.Logger
// SyncTimeout tells at most how much time we're going to wait
// till DNS change is propageted on all Amazon servers.
示例13: NewAWS
package lookup
import (
"koding/kites/kloud/api/amazon"
"github.com/koding/logging"
)
var defaultLogger = logging.NewLogger("lookup")
type Lookup struct {
// values contains a list of instance tags that are identified as test
// instances. By default all instances are fetched.
values []string
clients *amazon.Clients
log logging.Logger
}
// NewAWS gives new Lookup client.
//
// When opts.Log is nil, defaultLogger is used instead.
func NewAWS(opts *amazon.ClientOptions) (*Lookup, error) {
optsCopy := *opts
if optsCopy.Log == nil {
optsCopy.Log = defaultLogger
}
clients, err := amazon.NewClients(&optsCopy)
if err != nil {
return nil, err
}
return &Lookup{
示例14: GetPathSize
// GetPathSize gets the size of a remote path.
func (r *Remote) GetPathSize(kreq *kite.Request) (interface{}, error) {
log := logging.NewLogger("remote").New("remote.getPathSize")
var opts req.GetPathSizeOptions
if kreq.Args == nil {
return nil, errors.New("arguments are not passed")
}
if err := kreq.Args.One().Unmarshal(&opts); err != nil {
err = fmt.Errorf(
"remote.getPathSize: %s, while unmarshalling request: %q\n",
err, kreq.Args.One(),
)
log.Error(err.Error())
return nil, err
}
if opts.Machine == "" {
return nil, errors.New("missing required argument: machine")
}
if opts.Debug {
log.SetLevel(logging.DEBUG)
}
log = log.New(
"machineName", opts.Machine,
"remotePath", opts.RemotePath,
)
remoteMachine, err := r.GetDialedMachine(opts.Machine)
if err != nil {
log.Error("Error getting dialed, valid machine. err:%s", err)
return nil, err
}
if opts.RemotePath == "" {
log.Debug("RemotePath option is empty, finding default.")
home, err := remoteMachine.HomeWithDefault()
if err != nil {
log.Error("Failed to get remote home. err:%s", err)
return nil, err
}
opts.RemotePath = home
}
if !filepath.IsAbs(opts.RemotePath) {
log.Debug("RemotePath is not absolute. Joining it to home.")
home, err := remoteMachine.HomeWithDefault()
if err != nil {
log.Error("Failed to get remote home. err:%s", err)
return nil, err
}
opts.RemotePath = path.Join(home, opts.RemotePath)
}
exists, err := remoteMachine.DoesRemotePathExist(opts.RemotePath)
if err != nil {
log.Error("Unable to determine if remote path exists. err:%s", err)
return nil, err
}
if !exists {
log.Error("Remote path does not exist. path:%s", opts.RemotePath)
return nil, mount.ErrRemotePathDoesNotExist
}
size, err := remoteMachine.GetFolderSize(opts.RemotePath)
if err != nil {
log.Error("Failed to get remote size. path:%s, err:%s", opts.RemotePath, err)
}
return size, err
}
示例15: realMain
func realMain() error {
conf := new(Config)
multiconfig.MustLoadWithPath("config.toml", conf)
db := mongodb.NewMongoDB(conf.MongoURL)
opts := &amazon.ClientOptions{
Credentials: credentials.NewStaticCredentials(conf.AccessKey, conf.SecretKey, ""),
Regions: amazon.ProductionRegions,
Log: logging.NewLogger("userdebug"),
}
ec2clients, err := amazon.NewClients(opts)
if err != nil {
panic(err)
}
w := new(tabwriter.Writer)
w.Init(os.Stdout, 10, 8, 0, '\t', 0)
defer w.Flush()
// search via username, mongodb -> aws
if conf.Username != "" {
ms, err := machinesFromUsername(db, conf.Username)
if err == nil {
ms.Print(w)
for _, m := range ms.docs {
// if the mongodb document has a region and instanceId, display it too
if m.Meta.Region != "" && m.Meta.InstanceId != "" {
client, err := ec2clients.Region(m.Meta.Region)
if err != nil {
return err
}
i, err := awsData(client, m.Meta.InstanceId)
if err != nil {
return err
}
i.Print(w)
}
}
} else {
fmt.Fprintf(os.Stderr, err.Error())
}
}
// search via instanceId, aws -> mongodb
if conf.InstanceId != "" {
for _, client := range ec2clients.Regions() {
i, err := awsData(client, conf.InstanceId)
if err != nil {
continue // if not found continue with next region
}
// if we find a mongoDB document display it
ms, err := machinesFromInstanceId(db, conf.InstanceId)
if err == nil {
ms.Print(w)
}
i.Print(w)
break
}
}
return nil
}