當前位置: 首頁>>代碼示例>>Golang>>正文


Golang logging.NewCustom函數代碼示例

本文整理匯總了Golang中github.com/koding/logging.NewCustom函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewCustom函數的具體用法?Golang NewCustom怎麽用?Golang NewCustom使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewCustom函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: newDoBaseStack

func newDoBaseStack() (*provider.BaseStack, error) {
	log := logging.NewCustom("test", true)

	testTemplate := `{
    "variable": {
        "username": {
            "default": "testuser"
        }
    },
    "provider": {
        "digitalocean": {
            "token": "${var.digitalocean_access_token}"
        }
    },
    "resource": {
        "digitalocean_droplet": {
            "example": {
                "name": "web-1",
                "image": "ubuntu-14-04-x64",
                "region": "nyc2",
                "size": "512mb",
                "user_data": "sudo apt-get install sl -y\ntouch /tmp/${var.username}.txt"
            }
        }
    }
}`

	template, err := provider.ParseTemplate(testTemplate, log)
	if err != nil {
		return nil, err
	}

	return &provider.BaseStack{
		Provider: doProvider,
		Req: &kite.Request{
			Username: "testuser",
		},
		Arg: &stack.BootstrapRequest{
			Provider:  "digitalocean",
			GroupName: "testgroup",
		},
		Keys: &publickeys.Keys{
			PublicKey: "random-publickey",
		},
		Builder: &provider.Builder{
			Template: template,
		},
		Session: &session.Session{
			Userdata: &userdata.Userdata{
				KlientURL: "https://example-klient.com",
				Keycreator: &keycreator.Key{
					KontrolURL:        "https://example-kontrol.com",
					KontrolPrivateKey: testkeys.Private,
					KontrolPublicKey:  testkeys.Public,
				},
			},
		},
		KlientIDs: stack.KiteMap(map[string]string{}),
	}, nil
}
開發者ID:koding,項目名稱:koding,代碼行數:60,代碼來源:stack_test.go

示例2: NewClient

// NewClient returns client with required properties for accessing remote
// klient.
func NewClient() (*Client, error) {
	// Parse kite.key only once.
	if err := once.Do(newConfig); err != nil {
		return nil, err
	}

	k := kite.New(Name, Version)
	k.Config = config.Copy()

	if debug {
		k.SetLogLevel(kite.DEBUG)
	}

	c := &Client{
		Kite: k,
		Log:  logging.NewCustom(Name, debug),
	}

	c.Log.Debug("starting provider-vagrant in debug mode")

	c.Vagrant = &vagrantapi.Klient{
		Kite:  k,
		Log:   c.Log.New("vagrantapi"),
		Debug: debug,
	}

	return c, nil
}
開發者ID:koding,項目名稱:koding,代碼行數:30,代碼來源:config.go

示例3: main

func main() {
	if accessKey == "" {
		die("AWS_ACCESS_KEY is not set")
	}
	if secretKey == "" {
		die("AWS_SECRET_KEY is not set")
	}
	if hostedZone == "" {
		die("ROUTE53_HOSTED_ZONE is not set")
	}

	opts := &dnsclient.Options{
		Creds:       credentials.NewStaticCredentials(accessKey, secretKey, ""),
		HostedZone:  hostedZone,
		Log:         logging.NewCustom("dnsclient", os.Getenv("ROUTE53_DEBUG") == "1"),
		SyncTimeout: 5 * time.Minute,
	}

	if d, err := time.ParseDuration(os.Getenv("ROUTE53_TIMEOUT")); err == nil {
		opts.SyncTimeout = d
	}

	opts.Log.Debug("Options: %# v", opts)

	var err error
	client, err = dnsclient.NewRoute53Client(opts)
	if err != nil {
		die(err)
	}

	if err := Resources.Main(os.Args[1:]); err != nil {
		die(err)
	}
}
開發者ID:koding,項目名稱:koding,代碼行數:34,代碼來源:main.go

示例4: BaseStack

// BaseStack builds new base stack for the given context value.
func (s *Stacker) BaseStack(ctx context.Context) (*BaseStack, error) {
	bs := &BaseStack{
		Planner: &Planner{
			Provider:     s.Provider.Name,
			ResourceType: s.Provider.resourceName(),
			Log:          s.Log,
		},
		Provider:  s.Provider,
		KlientIDs: make(stack.KiteMap),
		Klients:   make(map[string]*DialState),
		TunnelURL: s.TunnelURL,
		Keys:      s.SSHKey,
	}

	var ok bool
	if bs.Req, ok = request.FromContext(ctx); !ok {
		return nil, errors.New("request not available in context")
	}

	req, ok := stack.TeamRequestFromContext(ctx)
	if !ok {
		return nil, errors.New("team request not available in context")
	}

	if bs.Session, ok = session.FromContext(ctx); !ok {
		return nil, errors.New("session not available in context")
	}

	bs.Log = s.Log.New(req.GroupName)

	if traceID, ok := stack.TraceFromContext(ctx); ok {
		bs.Log = logging.NewCustom("kloud-"+req.Provider, true).New(traceID)
		bs.TraceID = traceID
	}

	if keys, ok := publickeys.FromContext(ctx); ok {
		bs.Keys = keys
	}

	if ev, ok := eventer.FromContext(ctx); ok {
		bs.Eventer = ev
	}

	builderOpts := &BuilderOptions{
		Log:       s.Log.New("stackplan"),
		CredStore: s.CredStore,
	}

	bs.Builder = NewBuilder(builderOpts)

	if err := bs.Builder.BuildTeam(req.GroupName); err != nil {
		return nil, err
	}

	if !bs.Builder.Team.IsSubActive() {
		return nil, stack.NewError(stack.ErrTeamSubIsNotActive)
	}

	return bs, nil
}
開發者ID:koding,項目名稱:koding,代碼行數:61,代碼來源:stacker.go

示例5: BuildBaseMachine

func (s *Stacker) BuildBaseMachine(ctx context.Context, m *models.Machine) (*BaseMachine, error) {
	req, ok := request.FromContext(ctx)
	if !ok {
		return nil, errors.New("request context is not available")
	}

	bm := &BaseMachine{
		Machine: m,
		Session: &session.Session{
			DB:       s.DB,
			Kite:     s.Kite,
			Userdata: s.Userdata,
			Log:      s.Log.New(m.ObjectId.Hex()),
		},
		Credential: s.Provider.newCredential(),
		Bootstrap:  s.Provider.newBootstrap(),
		Metadata:   s.Provider.newMetadata(nil),
		Req:        req,
		Provider:   s.Provider.Name,
		Debug:      s.Debug,
	}

	// NOTE(rjeczalik): "internal" method is used by (*Queue).CheckAWS
	if req.Method != "internal" {
		// get user model which contains user ssh keys or the list of users that
		// are allowed to use this machine
		if len(m.Users) == 0 {
			return nil, errors.New("permitted users list is empty")
		}

		// get the user from the permitted list. If the list contains more than one
		// allowed person, fetch the one that is the same as requesterName, if
		// not pick up the first one.
		var err error
		bm.User, err = modelhelper.GetPermittedUser(req.Username, bm.Users)
		if err != nil {
			return nil, err
		}

		if err := s.ValidateUser(bm.User, bm.Users, req); err != nil {
			return nil, err
		}
	}

	if traceID, ok := stack.TraceFromContext(ctx); ok {
		bm.Log = logging.NewCustom("kloud-"+s.Provider.Name, true).New(m.ObjectId.Hex()).New(traceID)
		bm.Debug = true
		bm.TraceID = traceID
	}

	ev, ok := eventer.FromContext(ctx)
	if ok {
		bm.Eventer = ev
	}

	s.Log.Debug("BaseMachine: %+v", bm)

	return bm, nil
}
開發者ID:koding,項目名稱:koding,代碼行數:59,代碼來源:stacker.go

示例6: NewIterOptions

// NewIterOptions Sets the default values for iterOptions
func NewIterOptions() *iterOptions {
	return &iterOptions{
		Skip:       0,
		Limit:      1000,
		Filter:     modelhelper.Selector{},
		RetryCount: 50,
		Log:        logging.NewCustom("Iter", false),
	}
}
開發者ID:koding,項目名稱:koding,代碼行數:10,代碼來源:iter.go

示例7: NewClient

// NewClient gives new, unstarted tunnel client for the given options.
func NewClient(opts *ClientOptions) (*Client, error) {
	optsCopy := *opts

	if optsCopy.Log == nil {
		optsCopy.Log = logging.NewCustom("tunnelclient", optsCopy.Debug)
	}

	// TODO(rjeczalik): fix production to use WebSocket by default
	//
	// BUG(rjeczalik): starting a kite that is not registered to
	// kontrol will prevent the kite from updating it's keypair,
	// when it changes in kontrol - the only fix is to restart
	// kite process.
	k := kite.New("tunnelclient", "0.0.1")
	k.Config = optsCopy.Kite.Config.Copy()
	k.Config.Transport = config.WebSocket

	c := &Client{
		kite:          k,
		opts:          &optsCopy,
		tunnelKiteURL: optsCopy.tunnelKiteURL(),
		stateChanges:  make(chan *tunnel.ClientStateChange, 128),
		regserv:       make(chan map[string]*Tunnel, 1),
		services:      make(Services),
		routes:        make(map[int]string),
	}

	// If VirtualHost was configured, try to connect to it first.
	if c.opts.LastVirtualHost != "" {
		c.tunnelKiteURL = fmt.Sprintf("http://%s/kite", c.opts.LastVirtualHost)
		c.connected = &RegisterResult{
			VirtualHost: c.opts.LastVirtualHost,
			ServerAddr:  c.opts.LastVirtualHost,
		}
	}

	c.kite.ClientFunc = httputil.ClientFunc(opts.Debug)

	cfg := &tunnel.ClientConfig{
		FetchIdentifier: c.fetchIdent,
		FetchServerAddr: c.fetchServerAddr,
		FetchLocalAddr:  c.fetchLocalAddr,
		LocalAddr:       c.opts.LocalAddr,
		Debug:           c.opts.Debug,
		Log:             c.opts.Log.New("transport"),
		StateChanges:    c.stateChanges,
	}

	client, err := tunnel.NewClient(cfg)
	if err != nil {
		return nil, err
	}

	c.client = client

	return c, nil
}
開發者ID:koding,項目名稱:koding,代碼行數:58,代碼來源:client.go

示例8: Config

// Config creates new gateway.Config value from the given flags.
func (f *Flags) Config() *keygen.Config {
	return &keygen.Config{
		AccessKey:  f.AccessKey,
		SecretKey:  f.SecretKey,
		Bucket:     f.Bucket,
		AuthExpire: f.Expire,
		Region:     f.Region,
		Log:        logging.NewCustom("gateway-test", testing.Verbose()),
	}
}
開發者ID:koding,項目名稱:koding,代碼行數:11,代碼來源:keygentest.go

示例9: Action

// Action is an entry point for "vagrant" subcommand.
func (v *Vagrant) Action(args []string) error {
	k, err := kloudClient()
	if err != nil {
		return err
	}
	vapi := &vagrantapi.Klient{
		Kite:  k.LocalKite,
		Log:   logging.NewCustom("vagrant", flagDebug),
		Debug: true,
	}

	ctx := context.Background()
	ctx = context.WithValue(ctx, vapiKey, vapi)
	v.Resource.ContextFunc = func([]string) context.Context { return ctx }
	return v.Resource.Main(args)
}
開發者ID:koding,項目名稱:koding,代碼行數:17,代碼來源:vagrant.go

示例10: main

func main() {
	conf := &terraformer.Config{}

	mc := multiconfig.New()
	mc.Loader = multiconfig.MultiLoader(
		&multiconfig.TagLoader{},
		&multiconfig.EnvironmentLoader{},
		&multiconfig.EnvironmentLoader{Prefix: "KONFIG_TERRAFORMER"},
		&multiconfig.FlagLoader{},
	)

	mc.MustLoad(conf)

	if !conf.TerraformDebug {
		// hashicorp.terraform outputs many logs, discard them
		log.SetOutput(ioutil.Discard)
	}

	log := logging.NewCustom(terraformer.Name, conf.Debug)

	// init terraformer
	t, err := terraformer.New(conf, log)
	if err != nil {
		log.Fatal(err.Error())
	}

	k, err := terraformer.NewKite(t, conf)
	if err != nil {
		log.Fatal(err.Error())
	}

	if err := k.RegisterForever(k.RegisterURL(true)); err != nil {
		log.Fatal(err.Error())
	}

	go k.Run()
	<-k.ServerReadyNotify()
	log.Debug("Kite Started Listening")

	// terraformer can only be closed with signals, wait for any signal
	if err := t.Wait(); err != nil {
		log.Error("Err after waiting terraformer %s", err)
	}

	k.Close()
}
開發者ID:koding,項目名稱:koding,代碼行數:46,代碼來源:main.go

示例11: Valid

func (cmd *GroupFixDomain) Valid() error {
	if err := cmd.groupValues.Valid(); err != nil {
		return err
	}

	if len(cmd.values) == 0 {
		return errors.New("no usernames provided for -users flag")
	}

	if cmd.machine == "" {
		return errors.New("no value provided for -machine flag")
	}

	if cmd.env == "" {
		return errors.New("no value provided for -env flag")
	}

	zone := dnsZones[cmd.env]
	if zone == "" {
		return errors.New("invalid value provided for -env flag")
	}

	if cmd.access == "" {
		return errors.New("no value provided for -access flag")
	}

	if cmd.secret == "" {
		return errors.New("no value provided for -secret flag")
	}

	dnsOpts := &dnsclient.Options{
		Creds:      credentials.NewStaticCredentials(cmd.access, cmd.secret, ""),
		HostedZone: zone,
		Log:        logging.NewCustom("dns", flagDebug),
	}

	dns, err := dnsclient.NewRoute53Client(dnsOpts)
	if err != nil {
		return err
	}

	cmd.dns = dns

	return nil
}
開發者ID:koding,項目名稱:koding,代碼行數:45,代碼來源:group.go

示例12: TestMain

func TestMain(m *testing.M) {
	rand.Seed(time.Now().UnixNano() + int64(os.Getpid()))
	argsTesting, argsConfig := splitArgs()
	flag.CommandLine.Parse(argsTesting)

	l := multiconfig.MultiLoader(
		&multiconfig.EnvironmentLoader{
			Prefix: "e2etest",
		},
		&multiconfig.FlagLoader{
			EnvPrefix: "e2etest",
			Args:      argsConfig,
		},
	)

	if err := l.Load(&Test); err != nil {
		die("unable to load configuration", err)
	}

	Test.Log = logging.NewCustom("test", Test.Debug)
	Test.setDefaults()

	if Test.Debug {
		fmt.Printf("e2etest.Test = %s\n", &Test)
	}

	ktrl := NewKontrol()
	ktrl.Start()

	exit := m.Run()

	if !Test.NoClean {
		Test.cleanupRoute53()
	}

	ktrl.Close()

	os.Exit(exit)
}
開發者ID:koding,項目名稱:koding,代碼行數:39,代碼來源:e2e_test.go

示例13: newSession

func newSession(conf *Config, k *kite.Kite) (*session.Session, error) {
	c := credentials.NewStaticCredentials(conf.AWSAccessKeyId, conf.AWSSecretAccessKey, "")

	kontrolPrivateKey, kontrolPublicKey := kontrolKeys(conf)

	klientFolder := "development/latest"
	if conf.ProdMode {
		k.Log.Info("Prod mode enabled")
		klientFolder = "production/latest"
	}

	k.Log.Info("Klient distribution channel is: %s", klientFolder)

	// Credential belongs to the `koding-kloud` user in AWS IAM's
	sess := &session.Session{
		DB:   modelhelper.Mongo,
		Kite: k,
		Userdata: &userdata.Userdata{
			Keycreator: &keycreator.Key{
				KontrolURL:        getKontrolURL(conf.KontrolURL),
				KontrolPrivateKey: kontrolPrivateKey,
				KontrolPublicKey:  kontrolPublicKey,
			},
			KlientURL: conf.KlientURL,
			TunnelURL: conf.TunnelURL,
			Bucket:    userdata.NewBucket("koding-klient", klientFolder, c),
		},
		Terraformer: &terraformer.Options{
			Endpoint:  "http://127.0.0.1:2300/kite",
			SecretKey: conf.TerraformerSecretKey,
			Kite:      k,
		},
		Log: logging.NewCustom("kloud", conf.DebugMode),
	}

	sess.DNSStorage = dnsstorage.NewMongodbStorage(sess.DB)

	return sess, nil
}
開發者ID:koding,項目名稱:koding,代碼行數:39,代碼來源:kloud.go

示例14: withKite

func withKite(t *testing.T, f func(k *kite.Kite) error) {
	conf := &Config{}
	// Load the config, reads environment variables or from flags
	multiconfig.New().MustLoad(conf)

	// enable test mode
	conf.Test = true

	if !conf.Debug {
		// hashicorp.terraform outputs many logs, discard them
		log.SetOutput(ioutil.Discard)
	}

	log := logging.NewCustom(Name, conf.Debug)

	// init terraformer
	tr, err := New(conf, log)
	if err != nil {
		t.Errorf("err while creating terraformer %s", err.Error())
	}

	// init terraformer's kite
	k, err := NewKite(tr, conf)
	if err != nil {
		t.Errorf(err.Error())
	}
	k.Config.DisableAuthentication = true
	go k.Run()
	<-k.ServerReadyNotify()

	err = f(k)
	tr.Close()
	tr.Wait()
	k.Close()
	if err != nil {
		t.Errorf("failed with %s", err.Error())
	}
}
開發者ID:koding,項目名稱:koding,代碼行數:38,代碼來源:kite_test.go

示例15: kloudWithProviders

func kloudWithProviders(a *awsprovider.Provider, s *softlayer.Provider) *kloud.Kloud {
	kloudLogger := logging.NewCustom("kloud", true)
	sess := &session.Session{
		DB:         a.DB,
		Kite:       a.Kite,
		DNSClient:  a.DNSClient,
		DNSStorage: a.DNSStorage,
		AWSClients: a.EC2Clients,
		Userdata:   a.Userdata,
		Log:        kloudLogger,
	}

	kld := kloud.New()
	kld.ContextCreator = func(ctx context.Context) context.Context {
		return session.NewContext(ctx, sess)
	}

	userPrivateKey, userPublicKey := userMachinesKeys(
		os.Getenv("KLOUD_USER_PUBLICKEY"),
		os.Getenv("KLOUD_USER_PRIVATEKEY"),
	)

	kld.PublicKeys = &publickeys.Keys{
		KeyName:    publickeys.DeployKeyName,
		PrivateKey: userPrivateKey,
		PublicKey:  userPublicKey,
	}
	kld.Log = kloudLogger
	kld.DomainStorage = p.DNSStorage
	kld.Domainer = p.DNSClient
	kld.Locker = p
	kld.AddProvider("koding", p)
	kld.AddProvider("aws", a)
	kld.AddProvider("softlayer", s)
	return kld
}
開發者ID:koding,項目名稱:koding,代碼行數:36,代碼來源:main_test.go


注:本文中的github.com/koding/logging.NewCustom函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。