本文整理汇总了Golang中github.com/buildkite/agent/logger.Debug函数的典型用法代码示例。如果您正苦于以下问题:Golang Debug函数的具体用法?Golang Debug怎么用?Golang Debug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Debug函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Stop
// Stops the agent from accepting new work and cancels any current work it's
// running
func (a *AgentWorker) Stop() {
// Only allow one stop to run at a time (because we're playing with channels)
a.stopMutex.Lock()
if a.stopping {
logger.Debug("Agent is already stopping...")
return
} else {
logger.Debug("Stopping the agent...")
}
// If ther'es a running job, kill it.
if a.jobRunner != nil {
a.jobRunner.Kill()
}
// If we have a ticker, stop it, and send a signal to the stop channel,
// which will cause the agent worker to stop looping immediatly.
if a.ticker != nil {
close(a.stop)
}
// Mark the agent as stopping
a.stopping = true
// Unlock the stop mutex
a.stopMutex.Unlock()
}
开发者ID:crumpleup,项目名称:agent,代码行数:30,代码来源:agent_worker.go
示例2: Worker
// The actual log streamer worker
func Worker(id int, ls *LogStreamer) {
logger.Debug("[LogStreamer/Worker#%d] Worker is starting...", id)
var chunk *LogStreamerChunk
for {
// Get the next chunk (pointer) from the queue. This will block
// until something is returned.
chunk = <-ls.queue
// If the next chunk is nil, then there is no more work to do
if chunk == nil {
break
}
// Upload the chunk
err := ls.Callback(chunk)
if err != nil {
atomic.AddInt32(&ls.ChunksFailedCount, 1)
logger.Error("Giving up on uploading chunk %d, this will result in only a partial build log on Buildkite", chunk.Order)
}
// Signal to the chunkWaitGroup that this one is done
ls.chunkWaitGroup.Done()
}
logger.Debug("[LogStreamer/Worker#%d] Worker has shutdown", id)
}
开发者ID:Shopify,项目名称:agent,代码行数:29,代码来源:log_streamer.go
示例3: Upload
func (u *S3Uploader) Upload(artifact *api.Artifact) error {
permission := "public-read"
if os.Getenv("BUILDKITE_S3_ACL") != "" {
permission = os.Getenv("BUILDKITE_S3_ACL")
} else if os.Getenv("AWS_S3_ACL") != "" {
permission = os.Getenv("AWS_S3_ACL")
}
// The dirtiest validation method ever...
if permission != "private" &&
permission != "public-read" &&
permission != "public-read-write" &&
permission != "authenticated-read" &&
permission != "bucket-owner-read" &&
permission != "bucket-owner-full-control" {
logger.Fatal("Invalid S3 ACL `%s`", permission)
}
Perms := s3.ACL(permission)
logger.Debug("Reading file \"%s\"", artifact.AbsolutePath)
data, err := ioutil.ReadFile(artifact.AbsolutePath)
if err != nil {
return errors.New("Failed to read file " + artifact.AbsolutePath + " (" + err.Error() + ")")
}
logger.Debug("Uploading \"%s\" to bucket with permission `%s`", u.artifactPath(artifact), permission)
err = u.Bucket.Put(u.artifactPath(artifact), data, u.mimeType(artifact), Perms, s3.Options{})
if err != nil {
return errors.New(fmt.Sprintf("Failed to PUT file \"%s\" (%s)", u.artifactPath(artifact), err.Error()))
}
return nil
}
开发者ID:nikyoudale,项目名称:agent,代码行数:34,代码来源:s3_uploader.go
示例4: Start
func (h *HeaderTimesStreamer) Start() error {
h.streaming = true
go func() {
logger.Debug("[HeaderTimesStreamer] Streamer has started...")
for true {
// Break out of streaming if it's finished. We also
// need to aquire a read lock on the flag because it
// can be modified by other routines.
h.streamingMutex.Lock()
if !h.streaming {
break
}
h.streamingMutex.Unlock()
// Upload any pending header times
h.Upload()
// Sleep for a second and try upload some more later
time.Sleep(1 * time.Second)
}
logger.Debug("[HeaderTimesStreamer] Streamer has finished...")
}()
return nil
}
开发者ID:Shopify,项目名称:agent,代码行数:28,代码来源:header_times_streamer.go
示例5: Upload
func (h *HeaderTimesStreamer) Upload() {
// Store the current cursor value
c := h.cursor
// Grab only the times that we haven't uploaded yet. We need to aquire
// a lock since other routines may be adding to it.
h.timesMutex.Lock()
length := len(h.times)
times := h.times[h.cursor:length]
h.timesMutex.Unlock()
// Construct the payload to send to the server
payload := map[string]string{}
for index, time := range times {
payload[strconv.Itoa(h.cursor+index)] = time
}
// Save the cursor we're up to
h.cursor = length
// How many times are we uploading this time
timesToUpload := len(times)
// Do we even have some times to upload
if timesToUpload > 0 {
// Call our callback with the times for upload
logger.Debug("[HeaderTimesStreamer] Uploading header times %d..%d", c, length-1)
h.UploadCallback(c, length, payload)
logger.Debug("[HeaderTimesStreamer] Finished uploading header times %d..%d", c, length-1)
// Decrement the wait group for every time we've uploaded.
h.uploadWaitGroup.Add(timesToUpload * -1)
}
}
开发者ID:Shopify,项目名称:agent,代码行数:34,代码来源:header_times_streamer.go
示例6: Do
// Do sends an API request and returns the API response. The API response is
// JSON decoded and stored in the value pointed to by v, or returned as an
// error if an API error has occurred. If v implements the io.Writer
// interface, the raw response body will be written to v, without attempting to
// first decode it.
func (c *Client) Do(req *http.Request, v interface{}) (*Response, error) {
var err error
if c.DebugHTTP {
// If the request is a multi-part form, then it's probably a
// file upload, in which case we don't want to spewing out the
// file contents into the debug log (especially if it's been
// gzipped)
var requestDump []byte
if strings.Contains(req.Header.Get("Content-Type"), "multipart/form-data") {
requestDump, err = httputil.DumpRequestOut(req, false)
} else {
requestDump, err = httputil.DumpRequestOut(req, true)
}
logger.Debug("ERR: %s\n%s", err, string(requestDump))
}
ts := time.Now()
logger.Debug("%s %s", req.Method, req.URL)
resp, err := c.client.Do(req)
if err != nil {
return nil, err
}
logger.Debug("↳ %s %s (%s %s)", req.Method, req.URL, resp.Status, time.Now().Sub(ts))
defer resp.Body.Close()
defer io.Copy(ioutil.Discard, resp.Body)
response := newResponse(resp)
if c.DebugHTTP {
responseDump, err := httputil.DumpResponse(resp, true)
logger.Debug("\nERR: %s\n%s", err, string(responseDump))
}
err = checkResponse(resp)
if err != nil {
// even though there was an error, we still return the response
// in case the caller wants to inspect it further
return response, err
}
if v != nil {
if w, ok := v.(io.Writer); ok {
io.Copy(w, resp.Body)
} else {
err = json.NewDecoder(resp.Body).Decode(v)
}
}
return response, err
}
开发者ID:Jasperswaagman,项目名称:agent,代码行数:61,代码来源:buildkite.go
示例7: Stop
func (h *HeaderTimesStreamer) Stop() {
logger.Debug("[HeaderTimesStreamer] Waiting for all the lines to be scanned")
h.scanWaitGroup.Wait()
logger.Debug("[HeaderTimesStreamer] Waiting for all the header times to be uploaded")
h.uploadWaitGroup.Wait()
// Since we're modifying the waitGroup and the streaming flag, we need
// to aquire a write lock.
h.streamingMutex.Lock()
h.streaming = false
h.streamingMutex.Unlock()
}
开发者ID:Shopify,项目名称:agent,代码行数:13,代码来源:header_times_streamer.go
示例8: Stop
// Waits for all the chunks to be uploaded, then shuts down all the workers
func (ls *LogStreamer) Stop() error {
logger.Debug("[LogStreamer] Waiting for all the chunks to be uploaded")
ls.chunkWaitGroup.Wait()
logger.Debug("[LogStreamer] Shutting down all workers")
for n := 0; n < ls.Concurrency; n++ {
ls.queue <- nil
}
return nil
}
开发者ID:Shopify,项目名称:agent,代码行数:14,代码来源:log_streamer.go
示例9: Run
// Runs the job
func (r *JobRunner) Run() error {
logger.Info("Starting job %s", r.Job.ID)
// Start the build in the Buildkite Agent API. This is the first thing
// we do so if it fails, we don't have to worry about cleaning things
// up like started log streamer workers, etc.
if err := r.startJob(time.Now()); err != nil {
return err
}
// Start the log streamer
if err := r.logStreamer.Start(); err != nil {
return err
}
// Start the process. This will block until it finishes.
if err := r.process.Start(); err != nil {
// Send the error as output
r.logStreamer.Process(fmt.Sprintf("%s", err))
} else {
// Add the final output to the streamer
r.logStreamer.Process(r.process.Output())
}
// Store the finished at time
finishedAt := time.Now()
// Wait until all the header times have finished uploading
logger.Debug("Waiting for header times to finish uploading")
r.headerTimesStreamer.Wait()
// Stop the log streamer. This will block until all the chunks have
// been uploaded
r.logStreamer.Stop()
// Warn about failed chunks
if r.logStreamer.ChunksFailedCount > 0 {
logger.Warn("%d chunks failed to upload for this job", r.logStreamer.ChunksFailedCount)
}
// Finish the build in the Buildkite Agent API
r.finishJob(finishedAt, r.process.ExitStatus, int(r.logStreamer.ChunksFailedCount))
// Wait for the routines that we spun up to finish
logger.Debug("Waiting for all other routines to finish")
r.wg.Wait()
logger.Info("Finished job %s", r.Job.ID)
return nil
}
开发者ID:Jasperswaagman,项目名称:agent,代码行数:52,代码来源:job_runner.go
示例10: onProcessStartCallback
func (r *JobRunner) onProcessStartCallback() {
// Start a routine that will grab the output every few seconds and send
// it back to Buildkite
go func() {
// Add to the wait group
r.wg.Add(1)
for r.process.Running {
// Send the output of the process to the log streamer
// for processing
r.logStreamer.Process(r.process.Output())
// Check the output in another second
time.Sleep(1 * time.Second)
}
// Mark this routine as done in the wait group
r.wg.Done()
logger.Debug("Routine that processes the log has finished")
}()
// Start a routine that will grab the output every few seconds and send it back to Buildkite
go func() {
// Add to the wait group
r.wg.Add(1)
for r.process.Running {
// Re-get the job and check it's status to see if it's been
// cancelled
jobState, _, err := r.APIClient.Jobs.GetState(r.Job.ID)
if err != nil {
// We don't really care if it fails, we'll just
// try again in a second anyway
logger.Warn("Problem with getting job state %s (%s)", r.Job.ID, err)
} else if jobState.State == "canceling" || jobState.State == "canceled" {
r.Kill()
}
// Check for cancellations every few seconds
time.Sleep(3 * time.Second)
}
// Mark this routine as done in the wait group
r.wg.Done()
logger.Debug("Routine that refreshes the job has finished")
}()
}
开发者ID:Jasperswaagman,项目名称:agent,代码行数:49,代码来源:job_runner.go
示例11: signal
func (p *Process) signal(sig os.Signal) error {
if p.command != nil && p.command.Process != nil {
logger.Debug("[Process] Sending signal: %s to PID: %d", sig.String(), p.Pid)
err := p.command.Process.Signal(syscall.SIGTERM)
if err != nil {
logger.Error("[Process] Failed to send signal: %s to PID: %d (%T: %v)", sig.String(), p.Pid, err, err)
return err
}
} else {
logger.Debug("[Process] No process to signal yet")
}
return nil
}
开发者ID:nikyoudale,项目名称:agent,代码行数:15,代码来源:process.go
示例12: collect
func (a *ArtifactUploader) collect() (artifacts []*api.Artifact, err error) {
globPaths := strings.Split(a.Paths, ";")
for _, globPath := range globPaths {
workingDirectory := a.WorkingDirectory(globPath)
globPath = strings.TrimSpace(globPath)
if globPath != "" {
logger.Debug("Searching for %s", a.NormalizedPath(globPath))
files, err := glob.Glob(workingDirectory, globPath)
if err != nil {
return nil, err
}
for _, file := range files {
// Generate an absolute path for the artifact
absolutePath, err := filepath.Abs(file)
if err != nil {
return nil, err
}
fileInfo, err := os.Stat(absolutePath)
if fileInfo.IsDir() {
logger.Debug("Skipping directory %s", file)
continue
}
// Create a relative path (from the workingDirectory) to the artifact, by removing the
// first part of the absolutePath that is the workingDirectory.
relativePath := strings.Replace(absolutePath, workingDirectory, "", 1)
// Ensure the relativePath doesn't have a file seperator "/" as the first character
relativePath = strings.TrimPrefix(relativePath, string(os.PathSeparator))
// Build an artifact object using the paths we have.
artifact, err := a.build(relativePath, absolutePath, globPath)
if err != nil {
return nil, err
}
artifacts = append(artifacts, artifact)
}
}
}
return artifacts, nil
}
开发者ID:crumpleup,项目名称:agent,代码行数:48,代码来源:artifact_uploader.go
示例13: Setup
func (u *S3Uploader) Setup(destination string, debugHTTP bool) error {
u.Destination = destination
u.DebugHTTP = debugHTTP
// Try to auth with S3
auth, err := awsS3Auth()
if err != nil {
return errors.New(fmt.Sprintf("Error creating AWS S3 authentication: %s", err.Error()))
}
// Try and get the region
region, err := awsS3Region()
if err != nil {
return err
}
logger.Debug("Authorizing S3 credentials and finding bucket `%s` in region `%s`...", u.BucketName(), region.Name)
// Find the bucket
s3 := s3.New(auth, region)
bucket := s3.Bucket(u.BucketName())
// If the list doesn't return an error, then we've got our bucket
_, err = bucket.List("", "", "", 0)
if err != nil {
return errors.New("Could not find bucket `" + u.BucketName() + "` in region `" + region.Name + "` (" + err.Error() + ")")
}
u.Bucket = bucket
return nil
}
开发者ID:nikyoudale,项目名称:agent,代码行数:32,代码来源:s3_uploader.go
示例14: Run
func Run(command string, arg ...string) (string, error) {
output, err := exec.Command(command, arg...).Output()
if err != nil {
logger.Debug("Could not run: %s %s (returned %s) (%T: %v)", command, arg, output, err, err)
return "", err
}
return strings.Trim(fmt.Sprintf("%s", output), "\n"), nil
}
开发者ID:crumpleup,项目名称:agent,代码行数:10,代码来源:run.go
示例15: onUploadHeaderTime
func (r *JobRunner) onUploadHeaderTime(cursor int, total int, times map[string]string) {
retry.Do(func(s *retry.Stats) error {
logger.Debug("Uploading header times %d..%d (%d)", cursor+1, total, len(times))
_, err := r.APIClient.HeaderTimes.Save(r.Job.ID, &api.HeaderTimes{Times: times})
if err != nil {
logger.Warn("%s (%s)", err, s)
}
return err
}, &retry.Config{Maximum: 10, Interval: 1 * time.Second})
}
开发者ID:Jasperswaagman,项目名称:agent,代码行数:12,代码来源:job_runner.go
示例16: Upload
func (u *GSUploader) Upload(artifact *api.Artifact) error {
permission := os.Getenv("BUILDKITE_GS_ACL")
// The dirtiest validation method ever...
if permission != "" &&
permission != "authenticatedRead" &&
permission != "private" &&
permission != "projectPrivate" &&
permission != "publicRead" &&
permission != "publicReadWrite" {
logger.Fatal("Invalid GS ACL `%s`", permission)
}
if permission == "" {
logger.Debug("Uploading \"%s\" to bucket \"%s\" with default permission",
u.artifactPath(artifact), u.BucketName())
} else {
logger.Debug("Uploading \"%s\" to bucket \"%s\" with permission \"%s\"",
u.artifactPath(artifact), u.BucketName(), permission)
}
object := &storage.Object{
Name: u.artifactPath(artifact),
ContentType: u.mimeType(artifact),
}
file, err := os.Open(artifact.AbsolutePath)
if err != nil {
return errors.New(fmt.Sprintf("Failed to open file \"%q\" (%v)", artifact.AbsolutePath, err))
}
call := u.Service.Objects.Insert(u.BucketName(), object)
if permission != "" {
call = call.PredefinedAcl(permission)
}
if res, err := call.Media(file).Do(); err == nil {
logger.Debug("Created object %v at location %v\n\n", res.Name, res.SelfLink)
} else {
return errors.New(fmt.Sprintf("Failed to PUT file \"%s\" (%v)", u.artifactPath(artifact), err))
}
return nil
}
开发者ID:grosskur,项目名称:agent,代码行数:40,代码来源:gs_uploader.go
示例17: Start
func (d S3Downloader) Start() error {
// Try to auth with S3
auth, err := awsS3Auth()
if err != nil {
return errors.New(fmt.Sprintf("Error creating AWS S3 authentication: %s", err.Error()))
}
// Try and get the region
region, err := awsS3Region()
if err != nil {
return err
}
// Split apart the bucket
bucketParts := strings.Split(strings.TrimLeft(d.Bucket, "s3://"), "/")
bucketName := bucketParts[0]
bucketPath := strings.Join(bucketParts[1:len(bucketParts)], "/")
logger.Debug("Authorizing S3 credentials and finding bucket `%s` in region `%s`...", bucketName, region.Name)
// Find the bucket
s3 := s3.New(auth, region)
bucket := s3.Bucket(bucketName)
// If the list doesn't return an error, then we've got our bucket
_, err = bucket.List("", "", "", 0)
if err != nil {
return errors.New("Could not find bucket `" + bucketName + "` in region `" + region.Name + "` (" + err.Error() + ")")
}
// Create the location of the file
var s3Location string
if bucketPath != "" {
s3Location = strings.TrimRight(bucketPath, "/") + "/" + strings.TrimLeft(d.Path, "/")
} else {
s3Location = d.Path
}
// Generate a Signed URL
signedURL := bucket.SignedURL(s3Location, time.Now().Add(time.Hour))
// We can now cheat and pass the URL onto our regular downloader
return Download{
URL: signedURL,
Path: d.Path,
Destination: d.Destination,
Retries: d.Retries,
DebugHTTP: d.DebugHTTP,
}.Start()
}
开发者ID:Jasperswaagman,项目名称:agent,代码行数:50,代码来源:s3_downloader.go
示例18: Scan
func (h *HeaderTimesStreamer) Scan(line string) {
// Keep track of how many line scans we need to do
h.scanWaitGroup.Add(1)
defer h.scanWaitGroup.Done()
if h.lineIsHeader(line) {
logger.Debug("[HeaderTimesStreamer] Found header %q", line)
// Aquire a lock on the times and then add the current time to
// our times slice.
h.timesMutex.Lock()
h.times = append(h.times, time.Now().UTC().Format(time.RFC3339Nano))
h.timesMutex.Unlock()
// Add the time to the wait group
h.uploadWaitGroup.Add(1)
}
}
开发者ID:Shopify,项目名称:agent,代码行数:18,代码来源:header_times_streamer.go
示例19: Heartbeat
// Performs a heatbeat
func (a *AgentWorker) Heartbeat() error {
var beat *api.Heartbeat
var err error
// Retry the heartbeat a few times
err = retry.Do(func(s *retry.Stats) error {
beat, _, err = a.APIClient.Heartbeats.Beat()
if err != nil {
logger.Warn("%s (%s)", err, s)
}
return err
}, &retry.Config{Maximum: 5, Interval: 1 * time.Second})
if err != nil {
return err
}
logger.Debug("Heartbeat sent at %s and received at %s", beat.SentAt, beat.ReceivedAt)
return nil
}
开发者ID:nikyoudale,项目名称:agent,代码行数:21,代码来源:agent_worker.go
示例20: ShowBanner
// Shows the welcome banner and the configuration options used when starting
// this agent.
func (r *AgentPool) ShowBanner() {
welcomeMessage :=
"\n" +
"%s _ _ _ _ _ _ _ _\n" +
" | | (_) | | | | (_) | | |\n" +
" | |__ _ _ _| | __| | | ___| |_ ___ __ _ __ _ ___ _ __ | |_\n" +
" | '_ \\| | | | | |/ _` | |/ / | __/ _ \\ / _` |/ _` |/ _ \\ '_ \\| __|\n" +
" | |_) | |_| | | | (_| | <| | || __/ | (_| | (_| | __/ | | | |_\n" +
" |_.__/ \\__,_|_|_|\\__,_|_|\\_\\_|\\__\\___| \\__,_|\\__, |\\___|_| |_|\\__|\n" +
" __/ |\n" +
" http://buildkite.com/agent |___/\n%s\n"
if logger.ColorsEnabled() {
fmt.Fprintf(logger.OutputPipe(), welcomeMessage, "\x1b[32m", "\x1b[0m")
} else {
fmt.Fprintf(logger.OutputPipe(), welcomeMessage, "", "")
}
logger.Notice("Starting buildkite-agent v%s with PID: %s", Version(), fmt.Sprintf("%d", os.Getpid()))
logger.Notice("The agent source code can be found here: https://github.com/buildkite/agent")
logger.Notice("For questions and support, email us at: [email protected]")
if r.ConfigFilePath != "" {
logger.Info("Configuration loaded from: %s", r.ConfigFilePath)
}
logger.Debug("Bootstrap command: %s", r.AgentConfiguration.BootstrapScript)
logger.Debug("Build path: %s", r.AgentConfiguration.BuildPath)
logger.Debug("Hooks directory: %s", r.AgentConfiguration.HooksPath)
logger.Debug("Plugins directory: %s", r.AgentConfiguration.PluginsPath)
if !r.AgentConfiguration.SSHFingerprintVerification {
logger.Debug("Automatic SSH fingerprint verification has been disabled")
}
if !r.AgentConfiguration.CommandEval {
logger.Debug("Evaluating console commands has been disabled")
}
if !r.AgentConfiguration.RunInPty {
logger.Debug("Running builds within a pseudoterminal (PTY) has been disabled")
}
}
开发者ID:nikyoudale,项目名称:agent,代码行数:45,代码来源:agent_pool.go
注:本文中的github.com/buildkite/agent/logger.Debug函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论