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


Golang runtime.CreateLogger函数代码示例

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


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

示例1: Execute

func (cmd) Execute(args map[string]interface{}) bool {
	log, err := runtime.CreateLogger(args["--log-level"].(string))
	if err != nil {
		fmt.Fprintf(os.Stderr, "Invalid log-level, error: %s", err)
		return false
	}

	// Create shell server
	shellServer := interactive.NewShellServer(
		newExecShell, log.WithField("component", "shell-server"),
	)

	// Setup server
	server := graceful.Server{
		Timeout: 35 * time.Second,
		Server: &http.Server{
			Addr:    fmt.Sprintf("127.0.0.1:%s", args["--port"].(string)),
			Handler: shellServer,
		},
		NoSignalHandling: false, // abort on sigint and sigterm
	}

	server.ListenAndServe()
	shellServer.Abort()
	shellServer.WaitAndClose()

	return true
}
开发者ID:taskcluster,项目名称:taskcluster-worker,代码行数:28,代码来源:cmd.go

示例2: TestRetrievePollTaskUrlsErrorCaught

func TestRetrievePollTaskUrlsErrorCaught(t *testing.T) {
	logger, _ := runtime.CreateLogger("")
	mockedQueue := &client.MockQueue{}
	service := queueService{
		client:           mockedQueue,
		provisionerID:    ProvisionerID,
		workerType:       WorkerType,
		log:              logger.WithField("component", "Queue Service"),
		expirationOffset: 300,
	}

	mockedQueue.On(
		"PollTaskUrls",
		ProvisionerID,
		WorkerType,
	// Error value does not matter, just as long as we create an error to return
	).Return(&queue.PollTaskUrlsResponse{}, errors.New("bad error"))

	err := service.refreshMessageQueueURLs()
	if err == nil {
		t.Fatal("Error should have been returned when polling failed")
	}

	assert.Equal(t, "Error retrieving message queue urls.", err.Error())
}
开发者ID:taskcluster,项目名称:taskcluster-worker,代码行数:25,代码来源:queueservice_test.go

示例3: newTestEnvironment

// NewTestEnvironment creates a new Environment suitable for use in tests.
//
// This function should only be used in testing
func newTestEnvironment() *runtime.Environment {
	storage, err := runtime.NewTemporaryStorage(os.TempDir())
	nilOrPanic(err, "Failed to create temporary storage at: ", os.TempDir())

	folder, err := storage.NewFolder()
	nilOrPanic(err, "Failed to create temporary storage folder")

	// Set finalizer so that we always get the temporary folder removed.
	// This is should really only be used in tests, otherwise it would better to
	// call Remove() manually.
	rt.SetFinalizer(folder, func(f runtime.TemporaryFolder) {
		f.Remove()
	})

	logger, err := runtime.CreateLogger(os.Getenv("LOGGING_LEVEL"))
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error creating logger. %s", err)
		os.Exit(1)
	}

	return &runtime.Environment{
		GarbageCollector: &gc.GarbageCollector{},
		TemporaryStorage: folder,
		Log:              logger,
	}
}
开发者ID:taskcluster,项目名称:taskcluster-worker,代码行数:29,代码来源:testutils.go

示例4: TestGuestToolsFailed

func TestGuestToolsFailed(t *testing.T) {
	// Create temporary storage
	storage, err := runtime.NewTemporaryStorage(os.TempDir())
	if err != nil {
		panic("Failed to create TemporaryStorage")
	}
	environment := &runtime.Environment{
		TemporaryStorage: storage,
	}

	// Setup a new MetaService
	logTask := bytes.NewBuffer(nil)
	result := false
	resolved := false
	m := sync.Mutex{}
	s := metaservice.New([]string{"sh", "-c", "echo \"$TEST_TEXT\" && false"}, map[string]string{
		"TEST_TEXT": "Hello world",
	}, logTask, func(r bool) {
		m.Lock()
		defer m.Unlock()
		if resolved {
			panic("It shouldn't be possible to resolve twice")
		}
		resolved = true
		result = r
	}, environment)

	// Create http server for testing
	ts := httptest.NewServer(s)
	defer ts.Close()
	u, err := url.Parse(ts.URL)
	if err != nil {
		panic("Expected a url we can parse")
	}

	// Create a logger
	logger, _ := runtime.CreateLogger("info")
	log := logger.WithField("component", "guest-tools-tests")

	// Create an run guest-tools
	g := new(u.Host, log)
	g.Run()

	// Check the state
	if !resolved {
		t.Error("Expected the metadata to have resolved the task")
	}
	if result != false {
		t.Error("Expected the metadata to get failed result")
	}
	if !strings.Contains(logTask.String(), "Hello world") {
		t.Error("Got unexpected taskLog: '", logTask.String(), "'")
	}
}
开发者ID:taskcluster,项目名称:taskcluster-worker,代码行数:54,代码来源:guesttools_test.go

示例5: TestClaimTaskError

func TestClaimTaskError(t *testing.T) {
	// When a task cannot be claimed because of a 401 authorization error, the message
	// should not be deleted from the queue.

	// Delete should be called if the claim errored because of authorization or ISE
	// issues
	deleteCalled := false
	var handler = func(w http.ResponseWriter, r *http.Request) {
		if r.URL.Path == "/delete" {
			deleteCalled = true
		}
		return
	}
	s := httptest.NewServer(http.HandlerFunc(handler))
	defer s.Close()

	mockedQueue := &client.MockQueue{}
	mockedQueue.On(
		"ClaimTask",
		"abc",
		"0",
		&queue.TaskClaimRequest{
			WorkerGroup: WorkerType,
			WorkerID:    WorkerID,
		},
	).Return(&queue.TaskClaimResponse{},
		httpbackoff.BadHttpResponseCode{
			HttpResponseCode: 401,
		},
	)
	task := &taskMessage{
		TaskID:          "abc",
		RunID:           0,
		signedDeleteURL: fmt.Sprintf("%s/delete", s.URL),
	}

	logger, _ := runtime.CreateLogger(os.Getenv("LOGGING_LEVEL"))
	service := queueService{
		client:        mockedQueue,
		log:           logger.WithField("component", "Queue Service"),
		workerID:      WorkerID,
		workerGroup:   WorkerType,
		provisionerID: ProvisionerID,
	}

	_, err := service.claimTask(task)

	assert.NotNil(t, err, "Task should not have been claimed")
	// Delete should not have been called because it was an authorization issue
	assert.False(t, deleteCalled, "Message should not have been deleted from the queue.")
}
开发者ID:taskcluster,项目名称:taskcluster-worker,代码行数:51,代码来源:queueservice_test.go

示例6: TestRetrieveTasksFromQueueDequeueChecked

func TestRetrieveTasksFromQueueDequeueChecked(t *testing.T) {
	// When the dequeue count is above the reshold of 15, the message should be deleted
	// regardless if it's been claimed yet or not.
	message := `<?xml version="1.0" encoding="utf-8"?>
	<QueueMessagesList>
	  <QueueMessage>
		<MessageId>5974b586-0df3-4e2d-ad0c-18e3892bfca3</MessageId>
		<InsertionTime>Fri, 09 Oct 2009 21:04:30 GMT</InsertionTime>
		<ExpirationTime>Fri, 16 Oct 2009 21:04:30 GMT</ExpirationTime>
		<PopReceipt>YzQ4Yzg1MDItYTc0Ny00OWNjLTkxYTUtZGM0MDFiZDAwYzEw</PopReceipt>
		<TimeNextVisible>Fri, 09 Oct 2009 23:29:20 GMT</TimeNextVisible>
		<DequeueCount>16</DequeueCount>
		<MessageText>eyJ0YXNrSWQiOiAiYWJjIiwgInJ1bklkIjogMX0=</MessageText>
	  </QueueMessage>
	</QueueMessagesList>`

	// Delete URL should be called when dequeue count above threshold (15)
	deleteCalled := false

	var handler = func(w http.ResponseWriter, r *http.Request) {
		if r.URL.Path == "/delete/5974b586-0df3-4e2d-ad0c-18e3892bfca3/YzQ4Yzg1MDItYTc0Ny00OWNjLTkxYTUtZGM0MDFiZDAwYzEw" {
			deleteCalled = true
			message = ""
			return
		}
		w.Header().Set("Content-Type", "application/xml")
		w.Write([]byte(message))
	}

	s := httptest.NewServer(http.HandlerFunc(handler))
	defer s.Close()
	logger, _ := runtime.CreateLogger(os.Getenv("LOGGING_LEVEL"))
	service := queueService{
		log:              logger.WithField("component", "Queue Service"),
		expirationOffset: 300,
		expires:          tcclient.Time(time.Now().Add(time.Minute * 10)),
		queues: []messageQueue{
			{
				SignedDeleteURL: fmt.Sprintf("%s/delete/{{messageId}}/{{popReceipt}}", s.URL),
				SignedPollURL:   fmt.Sprintf("%s/tasks/1234?messages=true", s.URL),
			},
		},
	}

	tasks := service.retrieveTasksFromQueue(2)

	assert.Equal(t, 1, len(tasks))
	assert.True(t, deleteCalled, "Delete should have been called when dequeue count above threshold")

}
开发者ID:taskcluster,项目名称:taskcluster-worker,代码行数:50,代码来源:queueservice_test.go

示例7: TestErrorCaughtDeleteFromAzureQueueL

func TestErrorCaughtDeleteFromAzureQueueL(t *testing.T) {
	var handler = func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusForbidden)
	}

	s := httptest.NewServer(http.HandlerFunc(handler))
	defer s.Close()
	logger, _ := runtime.CreateLogger(os.Getenv("LOGGING_LEVEL"))
	service := queueService{
		log: logger.WithField("component", "Queue Service"),
	}
	err := service.deleteFromAzure(fmt.Sprintf("%s/delete/{{messageId}}/{{popReceipt}}", s.URL))
	assert.NotNil(t, err)
	assert.Contains(t, err.Error(), "(Permanent) HTTP response code 403")
}
开发者ID:taskcluster,项目名称:taskcluster-worker,代码行数:15,代码来源:queueservice_test.go

示例8: TestSuccessfullyDeleteFromAzureQueue

func TestSuccessfullyDeleteFromAzureQueue(t *testing.T) {
	// The method for deleting from the azure queue just makes sure that when
	// calling a given URL that a 200 status response is received.
	var handler = func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("ok"))
	}

	s := httptest.NewServer(http.HandlerFunc(handler))
	defer s.Close()
	logger, _ := runtime.CreateLogger(os.Getenv("LOGGING_LEVEL"))
	service := queueService{
		log: logger.WithField("component", "Queue Service"),
	}
	err := service.deleteFromAzure(fmt.Sprintf("%s/delete/{{messageId}}/{{popReceipt}}", s.URL))
	assert.Nil(t, err)
}
开发者ID:taskcluster,项目名称:taskcluster-worker,代码行数:16,代码来源:queueservice_test.go

示例9: TestShouldNotRefreshMessageQueueURLs

func TestShouldNotRefreshMessageQueueURLs(t *testing.T) {
	logger, _ := runtime.CreateLogger(os.Getenv("LOGGING_LEVEL"))
	service := queueService{
		expirationOffset: 300,
		expires:          tcclient.Time(time.Now().Add(time.Minute * 10)),
		queues:           []messageQueue{messageQueue{}, messageQueue{}},
		log:              logger.WithField("component", "Queue Service"),
	}

	// Because the expiration is not close, and the service already has queues,
	// there should be no reason to refresh.  Because the service was not created
	// with a taskcluster queue client, if it attempts to refresh, there will be
	// a panic
	err := service.refreshMessageQueueURLs()
	assert.Nil(t, err, "No error should be returned because the urls should not have been refreshed")
}
开发者ID:taskcluster,项目名称:taskcluster-worker,代码行数:16,代码来源:queueservice_test.go

示例10: TestPollTaskURLNonEmptyMessageList

func TestPollTaskURLNonEmptyMessageList(t *testing.T) {
	// Messages below are arbitrary messages to ensure that they can be
	// decoded.
	messages := `<?xml version="1.0" encoding="utf-8"?>
	<QueueMessagesList>
	  <QueueMessage>
		<MessageId>5974b586-0df3-4e2d-ad0c-18e3892bfca3</MessageId>
		<InsertionTime>Fri, 09 Oct 2009 21:04:30 GMT</InsertionTime>
		<ExpirationTime>Fri, 16 Oct 2009 21:04:30 GMT</ExpirationTime>
		<PopReceipt>YzQ4Yzg1MDItYTc0Ny00OWNjLTkxYTUtZGM0MDFiZDAwYzEw</PopReceipt>
		<TimeNextVisible>Fri, 09 Oct 2009 23:29:20 GMT</TimeNextVisible>
		<DequeueCount>1</DequeueCount>
		<MessageText>eyJ0YXNrSWQiOiAiYWJjIiwgInJ1bklkIjogMH0=</MessageText>
	  </QueueMessage>
	  <QueueMessage>
		<MessageId>5974b586-0df3-4e2d-ad0c-18e3892bfca2</MessageId>
		<InsertionTime>Fri, 09 Oct 2009 21:04:30 GMT</InsertionTime>
		<ExpirationTime>Fri, 16 Oct 2009 21:04:30 GMT</ExpirationTime>
		<PopReceipt>YzQ4Yzg1MDItYTc0Ny00OWNjLTkxYTUtZGM0MDFiZDAwYzEw</PopReceipt>
		<TimeNextVisible>Fri, 09 Oct 2009 23:29:20 GMT</TimeNextVisible>
		<DequeueCount>1</DequeueCount>
		<MessageText>eyJ0YXNrSWQiOiAiZGVmIiwgInJ1bklkIjogMX0=</MessageText>
	  </QueueMessage>
	</QueueMessagesList>`
	var handler = func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/xml")
		w.Write([]byte(messages))
	}

	s := httptest.NewServer(http.HandlerFunc(handler))
	defer s.Close()
	logger, _ := runtime.CreateLogger(os.Getenv("LOGGING_LEVEL"))
	service := queueService{
		log: logger.WithField("component", "Queue Service"),
		queues: []messageQueue{{
			SignedDeleteURL: fmt.Sprintf("%s/delete/{{messageId}}/{{popReceipt}}", s.URL),
			SignedPollURL:   fmt.Sprintf("%s/tasks", s.URL),
		}},
	}

	tasks, err := service.pollTaskURL(&service.queues[0], 3)
	assert.Nil(t, err, "Error should not have been returned when empty message list provided.")
	assert.Equal(t, 2, len(tasks))
	// quick sanity check to make sure the messages are different
	assert.NotEqual(t, tasks[0].TaskID, tasks[1].TaskID)
	assert.NotEqual(t, tasks[0].signedDeleteURL, tasks[1].signedDeleteURL)
}
开发者ID:taskcluster,项目名称:taskcluster-worker,代码行数:47,代码来源:queueservice_test.go

示例11: TestPollTaskURLInvalidMessageTextEncoding

func TestPollTaskURLInvalidMessageTextEncoding(t *testing.T) {
	// MessageText is not a valid base64 encoded string
	messages := `<?xml version="1.0" encoding="utf-8"?>
	<QueueMessagesList>
	  <QueueMessage>
		<MessageId>5974b586-0df3-4e2d-ad0c-18e3892bfca3</MessageId>
		<InsertionTime>Fri, 09 Oct 2009 21:04:30 GMT</InsertionTime>
		<ExpirationTime>Fri, 16 Oct 2009 21:04:30 GMT</ExpirationTime>
		<PopReceipt>YzQ4Yzg1MDItYTc0Ny00OWNjLTkxYTUtZGM0MDFiZDAwYzEw</PopReceipt>
		<TimeNextVisible>Fri, 09 Oct 2009 23:29:20 GMT</TimeNextVisible>
		<DequeueCount>1</DequeueCount>
		<MessageText>invalid MessageText, not base64 encoded!</MessageText>
	  </QueueMessage>
	</QueueMessagesList>`

	// When there is an error decoding, message should be deleted from Azure
	deleteCalled := false

	var handler = func(w http.ResponseWriter, r *http.Request) {
		if r.URL.Path == "/delete/5974b586-0df3-4e2d-ad0c-18e3892bfca3/YzQ4Yzg1MDItYTc0Ny00OWNjLTkxYTUtZGM0MDFiZDAwYzEw" {
			deleteCalled = true
			return
		}

		w.Header().Set("Content-Type", "application/xml")
		w.Write([]byte(messages))
	}

	s := httptest.NewServer(http.HandlerFunc(handler))
	defer s.Close()
	logger, _ := runtime.CreateLogger(os.Getenv("LOGGING_LEVEL"))
	service := queueService{
		log: logger.WithField("component", "Queue Service"),
		queues: []messageQueue{{
			SignedDeleteURL: fmt.Sprintf("%s/delete/{{messageId}}/{{popReceipt}}", s.URL),
			SignedPollURL:   fmt.Sprintf("%s/tasks", s.URL),
		}},
	}

	tasks, err := service.pollTaskURL(&service.queues[0], 3)
	assert.Nil(t, err, "Error should not have been raised when unmarshalling invalid MessageText")
	assert.Equal(t, 0, len(tasks))
	assert.True(t, deleteCalled, "Delete URL not called after attempting to decode messageText")
}
开发者ID:taskcluster,项目名称:taskcluster-worker,代码行数:44,代码来源:queueservice_test.go

示例12: TestRetrievePollTaskUrls

func TestRetrievePollTaskUrls(t *testing.T) {
	logger, _ := runtime.CreateLogger("")
	mockedQueue := &client.MockQueue{}
	service := queueService{
		client:           mockedQueue,
		provisionerID:    ProvisionerID,
		workerType:       WorkerType,
		log:              logger.WithField("component", "Queue Service"),
		expirationOffset: 300,
	}
	mockedQueue.On(
		"PollTaskUrls",
		ProvisionerID,
		WorkerType,
	).Return(&queue.PollTaskUrlsResponse{
		Expires: tcclient.Time(time.Now().Add(time.Minute * 10)),
		Queues: []struct {
			SignedDeleteURL string `json:"signedDeleteUrl"`
			SignedPollURL   string `json:"signedPollUrl"`
		}{{
			// Urls are arbitrary and unique so they can be checked later on.
			// Polling should return at least 2 queues in production because of
			// high/low priority queues
			SignedDeleteURL: "abc",
			SignedPollURL:   "123",
		}, {
			SignedDeleteURL: "def",
			SignedPollURL:   "456",
		}},
	}, nil)
	service.refreshMessageQueueURLs()
	assert.Equal(t,
		len(service.queues),
		2,
		fmt.Sprintf("Queue Service should contain two sets of url pairs but got %d", len(service.queues)),
	)

	assert.Equal(t, "abc", service.queues[0].SignedDeleteURL)
	assert.Equal(t, "123", service.queues[0].SignedPollURL)
	assert.Equal(t, "def", service.queues[1].SignedDeleteURL)
	assert.Equal(t, "456", service.queues[1].SignedPollURL)
}
开发者ID:taskcluster,项目名称:taskcluster-worker,代码行数:42,代码来源:queueservice_test.go

示例13: TestBuildImage

func TestBuildImage(t *testing.T) {
	// Setup logging
	logger, _ := runtime.CreateLogger("info")
	log := logger.WithField("component", "qemu-build")

	inputImageFile, err := filepath.Abs("../../engines/qemu/test-image/tinycore-setup.tar.zst")
	if err != nil {
		panic(err)
	}
	outputFile := filepath.Join(os.TempDir(), slugid.Nice())
	defer os.Remove(outputFile)
	novnc := true
	cdrom := ""

	// Create ISO file to play with
	datadir := filepath.Join(os.TempDir(), slugid.Nice())
	defer os.RemoveAll(datadir)
	err = os.Mkdir(datadir, 0700)
	if err != nil {
		panic(err)
	}
	err = ioutil.WriteFile(filepath.Join(datadir, "setup.sh"),
		[]byte("#!/bin/sh\necho 'started';\nsudo poweroff;\n"), 0755)
	if err != nil {
		panic(err)
	}
	isofile := filepath.Join(os.TempDir(), slugid.Nice())
	defer os.Remove(isofile)
	err = exec.Command("genisoimage", "-vJrV", "DATA_VOLUME", "-input-charset", "utf-8", "-o", isofile, datadir).Run()
	if err != nil {
		panic(err)
	}

	err = buildImage(
		log, inputImageFile, outputFile,
		true, novnc, isofile, cdrom, 1,
	)
	if err != nil {
		panic(err)
	}
}
开发者ID:taskcluster,项目名称:taskcluster-worker,代码行数:41,代码来源:buildimage_test.go

示例14: TestPollTaskUrlInvalidXMLResponse

func TestPollTaskUrlInvalidXMLResponse(t *testing.T) {
	var handler = func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/xml")
		io.WriteString(w, "Invalid XML")
	}

	s := httptest.NewServer(http.HandlerFunc(handler))
	defer s.Close()
	logger, _ := runtime.CreateLogger(os.Getenv("LOGGING_LEVEL"))
	service := queueService{
		log: logger.WithField("component", "Queue Service"),
		queues: []messageQueue{{
			SignedDeleteURL: fmt.Sprintf("%s/delete/{{messageId}}/{{popReceipt}}", s.URL),
			SignedPollURL:   fmt.Sprintf("%s/tasks", s.URL),
		}},
	}

	_, err := service.pollTaskURL(&service.queues[0], 3)
	assert.NotNil(t, err, "Error should have been returned when invalid xml was parsed")
	assert.Contains(t, err.Error(), "Not able to xml decode the response from the Azure queue")
}
开发者ID:taskcluster,项目名称:taskcluster-worker,代码行数:21,代码来源:queueservice_test.go

示例15: TestPollTaskURLEmptyMessageList

func TestPollTaskURLEmptyMessageList(t *testing.T) {
	var handler = func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/xml")
		io.WriteString(w, "<QueueMessagesList></QueueMessagesList>")
	}

	s := httptest.NewServer(http.HandlerFunc(handler))
	defer s.Close()
	logger, _ := runtime.CreateLogger(os.Getenv("LOGGING_LEVEL"))
	service := queueService{
		log: logger.WithField("component", "Queue Service"),
		queues: []messageQueue{{
			SignedDeleteURL: fmt.Sprintf("%s/delete/{{messageId}}/{{popReceipt}}", s.URL),
			SignedPollURL:   fmt.Sprintf("%s/tasks", s.URL),
		}},
	}

	tasks, err := service.pollTaskURL(&service.queues[0], 3)
	assert.Nil(t, err, "Error should not have been returned when empty message list provided.")
	assert.Equal(t, 0, len(tasks))
}
开发者ID:taskcluster,项目名称:taskcluster-worker,代码行数:21,代码来源:queueservice_test.go


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