当前位置: 首页>>代码示例>>Golang>>正文


Golang db.LogConn函数代码示例

本文整理汇总了Golang中github.com/tsuru/tsuru/db.LogConn函数的典型用法代码示例。如果您正苦于以下问题:Golang LogConn函数的具体用法?Golang LogConn怎么用?Golang LogConn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了LogConn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: LastLogs

// LastLogs returns a list of the last `lines` log of the app, matching the
// fields in the log instance received as an example.
func (app *App) LastLogs(lines int, filterLog Applog) ([]Applog, error) {
	logsProvisioner, ok := Provisioner.(provision.OptionalLogsProvisioner)
	if ok {
		enabled, doc, err := logsProvisioner.LogsEnabled(app)
		if err != nil {
			return nil, err
		}
		if !enabled {
			return nil, stderr.New(doc)
		}
	}
	conn, err := db.LogConn()
	if err != nil {
		return nil, err
	}
	defer conn.Close()
	logs := []Applog{}
	q := bson.M{}
	if filterLog.Source != "" {
		q["source"] = filterLog.Source
	}
	if filterLog.Unit != "" {
		q["unit"] = filterLog.Unit
	}
	err = conn.Logs(app.Name).Find(q).Sort("-$natural").Limit(lines).All(&logs)
	if err != nil {
		return nil, err
	}
	l := len(logs)
	for i := 0; i < l/2; i++ {
		logs[i], logs[l-1-i] = logs[l-1-i], logs[i]
	}
	return logs, nil
}
开发者ID:botvs,项目名称:tsuru,代码行数:36,代码来源:app.go

示例2: runFlusher

func (d *appLogDispatcher) runFlusher() {
	defer close(d.errCh)
	t := time.NewTimer(bulkMaxWaitTime)
	bulkBuffer := make([]interface{}, 0, 100)
	conn, err := db.LogConn()
	if err != nil {
		d.errCh <- err
		return
	}
	defer conn.Close()
	coll := conn.Logs(d.appName)
	for {
		var flush bool
		select {
		case <-d.done:
			return
		case msg := <-d.toFlush:
			bulkBuffer = append(bulkBuffer, msg)
			flush = len(bulkBuffer) == cap(bulkBuffer)
			if !flush {
				t.Reset(bulkMaxWaitTime)
			}
		case <-t.C:
			flush = len(bulkBuffer) > 0
		}
		if flush {
			err := coll.Insert(bulkBuffer...)
			if err != nil {
				d.errCh <- err
				return
			}
			bulkBuffer = bulkBuffer[:0]
		}
	}
}
开发者ID:gwmoura,项目名称:yati,代码行数:35,代码来源:log.go

示例3: LogReceiver

func LogReceiver() (chan<- *Applog, <-chan error) {
	ch := make(chan *Applog)
	errCh := make(chan error)
	go func() {
		collMap := map[string]*storage.Collection{}
		messages := make([]interface{}, 1)
		for msg := range ch {
			messages[0] = msg
			notify(msg.AppName, messages)
			coll := collMap[msg.AppName]
			if coll == nil {
				conn, err := db.LogConn()
				if err != nil {
					errCh <- err
					break
				}
				coll = conn.Logs(msg.AppName)
				collMap[msg.AppName] = coll
			}
			err := coll.Insert(msg)
			if err != nil {
				errCh <- err
				break
			}
		}
		for _, coll := range collMap {
			coll.Close()
		}
		close(errCh)
	}()
	return ch, errCh
}
开发者ID:4eek,项目名称:tsuru,代码行数:32,代码来源:log.go

示例4: Log

// Log adds a log message to the app. Specifying a good source is good so the
// user can filter where the message come from.
func (app *App) Log(message, source, unit string) error {
	messages := strings.Split(message, "\n")
	logs := make([]interface{}, 0, len(messages))
	for _, msg := range messages {
		if msg != "" {
			l := Applog{
				Date:    time.Now().In(time.UTC),
				Message: msg,
				Source:  source,
				AppName: app.Name,
				Unit:    unit,
			}
			logs = append(logs, l)
		}
	}
	if len(logs) > 0 {
		notify(app.Name, logs)
		conn, err := db.LogConn()
		if err != nil {
			return err
		}
		defer conn.Close()
		return conn.Logs(app.Name).Insert(logs...)
	}
	return nil
}
开发者ID:Zapelini,项目名称:tsuru,代码行数:28,代码来源:app.go

示例5: SetUpTest

func (s *S) SetUpTest(c *check.C) {
	routertest.FakeRouter.Reset()
	repositorytest.Reset()
	var err error
	s.conn, err = db.Conn()
	c.Assert(err, check.IsNil)
	dbtest.ClearAllCollections(s.conn.Apps().Database)
	s.logConn, err = db.LogConn()
	c.Assert(err, check.IsNil)
	s.createUserAndTeam(c)
	s.provisioner = provisiontest.NewFakeProvisioner()
	app.Provisioner = s.provisioner
	app.AuthScheme = nativeScheme
	p := app.Platform{Name: "zend"}
	s.conn.Platforms().Insert(p)
	s.Pool = "test1"
	opts := provision.AddPoolOptions{Name: "test1", Default: true}
	err = provision.AddPool(opts)
	c.Assert(err, check.IsNil)
	repository.Manager().CreateUser(s.user.Email)
	repository.Manager().CreateUser(s.adminuser.Email)
	factory, err := queue.Factory()
	c.Assert(err, check.IsNil)
	factory.Reset()
}
开发者ID:nicolas2bonfils,项目名称:tsuru,代码行数:25,代码来源:suite_test.go

示例6: SetUpTest

func (s *LogSuite) SetUpTest(c *check.C) {
	repositorytest.Reset()
	var err error
	s.conn, err = db.Conn()
	c.Assert(err, check.IsNil)
	dbtest.ClearAllCollections(s.conn.Apps().Database)
	s.logConn, err = db.LogConn()
	c.Assert(err, check.IsNil)
	s.createUserAndTeam(c)
}
开发者ID:reoring,项目名称:tsuru,代码行数:10,代码来源:log_test.go

示例7: TearDownSuite

func (s *LogSuite) TearDownSuite(c *check.C) {
	conn, err := db.Conn()
	c.Assert(err, check.IsNil)
	defer conn.Close()
	conn.Apps().Database.DropDatabase()
	logConn, err := db.LogConn()
	c.Assert(err, check.IsNil)
	defer logConn.Close()
	logConn.Logs("myapp").Database.DropDatabase()
}
开发者ID:reoring,项目名称:tsuru,代码行数:10,代码来源:log_test.go

示例8: SetUpSuite

func (s *DeploySuite) SetUpSuite(c *check.C) {
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "tsuru_deploy_api_tests")
	config.Set("auth:hash-cost", 4)
	config.Set("repo-manager", "fake")
	var err error
	s.conn, err = db.Conn()
	c.Assert(err, check.IsNil)
	s.logConn, err = db.LogConn()
	c.Assert(err, check.IsNil)
}
开发者ID:zhenruyan,项目名称:tsuru,代码行数:11,代码来源:deploy_test.go

示例9: SetUpSuite

func (s *EventSuite) SetUpSuite(c *check.C) {
	err := config.ReadConfigFile("testdata/config.yaml")
	c.Assert(err, check.IsNil)
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "tsuru_events_api_tests")
	config.Set("auth:hash-cost", 4)
	config.Set("repo-manager", "fake")
	s.conn, err = db.Conn()
	c.Assert(err, check.IsNil)
	s.logConn, err = db.LogConn()
	c.Assert(err, check.IsNil)
}
开发者ID:tsuru,项目名称:tsuru,代码行数:12,代码来源:event_test.go

示例10: Delete

// Delete deletes an app.
//
// Delete an app is a process composed of three steps:
//
//       1. Destroy the app unit
//       2. Unbind all service instances from the app
//       3. Remove the app from the database
func Delete(app *App) error {
	appName := app.Name
	wg := asyncDestroyAppProvisioner(app)
	wg.Add(1)
	defer wg.Done()
	go func() {
		defer ReleaseApplicationLock(appName)
		wg.Wait()
		logConn, err := db.LogConn()
		if err != nil {
			log.Errorf("Unable to delete app %s from db: %s", appName, err.Error())
		}
		defer logConn.Close()
		conn, err := db.Conn()
		if err != nil {
			log.Errorf("Unable to delete app %s from db: %s", appName, err.Error())
		}
		defer conn.Close()
		err = logConn.Logs(appName).DropCollection()
		if err != nil {
			log.Errorf("Ignored error dropping logs collection for app %s: %s", appName, err.Error())
		}
		err = conn.Apps().Remove(bson.M{"name": appName})
		if err != nil {
			log.Errorf("Error trying to destroy app %s from db: %s", appName, err.Error())
		}
		err = markDeploysAsRemoved(appName)
		if err != nil {
			log.Errorf("Error trying to mark old deploys as removed for app %s: %s", appName, err.Error())
		}
	}()
	err := repository.Manager().RemoveRepository(appName)
	if err != nil {
		log.Errorf("failed to remove app %q from repository manager: %s", appName, err)
	}
	token := app.Env["TSURU_APP_TOKEN"].Value
	err = AuthScheme.Logout(token)
	if err != nil {
		log.Errorf("Unable to remove app token in destroy: %s", err.Error())
	}
	owner, err := auth.GetUserByEmail(app.Owner)
	if err != nil {
		log.Errorf("Unable to get app owner in destroy: %s", err.Error())
	} else {
		err = auth.ReleaseApp(owner)
		if err != nil {
			log.Errorf("Unable to release app quota: %s", err.Error())
		}
	}
	return nil
}
开发者ID:rzs840707,项目名称:tsuru,代码行数:58,代码来源:app.go

示例11: SetUpSuite

func (s *DeploySuite) SetUpSuite(c *check.C) {
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "tsuru_deploy_api_tests")
	config.Set("aut:hash-cost", 4)
	config.Set("admin-team", "tsuruteam")
	config.Set("repo-manager", "fake")
	var err error
	s.conn, err = db.Conn()
	c.Assert(err, check.IsNil)
	s.logConn, err = db.LogConn()
	c.Assert(err, check.IsNil)
	s.provisioner = provisiontest.NewFakeProvisioner()
	app.Provisioner = s.provisioner
}
开发者ID:Zapelini,项目名称:tsuru,代码行数:14,代码来源:deploy_test.go

示例12: SetUpSuite

func (s *S) SetUpSuite(c *check.C) {
	err := config.ReadConfigFile("testdata/config.yaml")
	c.Assert(err, check.IsNil)
	s.conn, err = db.Conn()
	c.Assert(err, check.IsNil)
	s.logConn, err = db.LogConn()
	c.Assert(err, check.IsNil)
	s.provisioner = provisiontest.NewFakeProvisioner()
	Provisioner = s.provisioner
	AuthScheme = nativeScheme
	data, err := json.Marshal(AppLock{})
	c.Assert(err, check.IsNil)
	err = json.Unmarshal(data, &s.zeroLock)
	c.Assert(err, check.IsNil)
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:15,代码来源:suite_test.go

示例13: SetUpSuite

func (s *S) SetUpSuite(c *check.C) {
	err := config.ReadConfigFile("testdata/config.yaml")
	c.Assert(err, check.IsNil)
	config.Set("queue:mongo-url", "127.0.0.1:27017")
	config.Set("queue:mongo-database", "queue_app_pkg_tests")
	config.Set("queue:mongo-polling-interval", 0.01)
	config.Set("docker:registry", "registry.somewhere")
	s.conn, err = db.Conn()
	c.Assert(err, check.IsNil)
	s.logConn, err = db.LogConn()
	c.Assert(err, check.IsNil)
	s.provisioner = provisiontest.ProvisionerInstance
	provision.DefaultProvisioner = "fake"
	AuthScheme = nativeScheme
	data, err := json.Marshal(AppLock{})
	c.Assert(err, check.IsNil)
	err = json.Unmarshal(data, &s.zeroLock)
	c.Assert(err, check.IsNil)
	LogPubSubQueuePrefix = "pubsub:app-test:"
}
开发者ID:tsuru,项目名称:tsuru,代码行数:20,代码来源:suite_test.go

示例14: LogRemove

// LogRemove removes the app log.
func LogRemove(a *App) error {
	conn, err := db.LogConn()
	if err != nil {
		return err
	}
	defer conn.Close()
	if a != nil {
		return conn.Logs(a.Name).DropCollection()
	}
	colls, err := conn.LogsCollections()
	if err != nil {
		return err
	}
	for _, coll := range colls {
		err = coll.DropCollection()
		if err != nil {
			log.Errorf("Error trying to drop collection %s", coll.Name)
		}
	}
	return nil
}
开发者ID:4eek,项目名称:tsuru,代码行数:22,代码来源:log.go

示例15: runFlusher

func (d *appLogDispatcher) runFlusher() {
	defer close(d.errCh)
	t := time.NewTimer(bulkMaxWaitTime)
	pos := 0
	sz := 200
	bulkBuffer := make([]interface{}, sz)
	for {
		var flush bool
		select {
		case <-d.done:
			return
		case msg := <-d.toFlush:
			bulkBuffer[pos] = msg
			pos++
			flush = sz == pos
			if flush {
				t.Stop()
			} else {
				t.Reset(bulkMaxWaitTime)
			}
		case <-t.C:
			flush = pos > 0
		}
		if flush {
			conn, err := db.LogConn()
			if err != nil {
				d.errCh <- err
				return
			}
			coll := conn.Logs(d.appName)
			err = coll.Insert(bulkBuffer[:pos]...)
			coll.Close()
			if err != nil {
				d.errCh <- err
				return
			}
			pos = 0
		}
	}
}
开发者ID:zhenruyan,项目名称:tsuru,代码行数:40,代码来源:log.go


注:本文中的github.com/tsuru/tsuru/db.LogConn函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。