Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: common/cloudlogging/entry.go

Issue 2937693003: Make luci-go compile again after deps.lock roll. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « common/cloudlogging/client_test.go ('k') | common/cloudlogging/severity.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package cloudlogging
6
7 import (
8 "time"
9
10 cloudlog "google.golang.org/api/logging/v1beta3"
11 )
12
13 // Entry is a single log entry. It can be a text message, or a JSONish struct.
14 type Entry struct {
15 // This log's Insert ID, used to uniquely identify this log entry.
16 InsertID string
17 // Timestamp is an optional timestamp.
18 Timestamp time.Time
19 // Severity is the severity of the log entry.
20 Severity Severity
21 // Labels is an optional set of key/value labels for this log entry.
22 Labels Labels
23 // TextPayload is the log entry payload, represented as a text string.
24 TextPayload string
25 // StructPayload is the log entry payload, represented as a JSONish stru cture.
26 StructPayload interface{}
27 }
28
29 func (e *Entry) cloudLogEntry(opts *ClientOptions) (*cloudlog.LogEntry, error) {
30 entry := cloudlog.LogEntry{
31 InsertId: e.InsertID,
32 Metadata: &cloudlog.LogEntryMetadata{
33 Labels: e.Labels,
34 ProjectId: opts.ProjectID,
35 Region: opts.Region,
36 ServiceName: opts.ServiceName,
37 Timestamp: formatTimestamp(e.Timestamp),
38 UserId: opts.UserID,
39 Zone: opts.Zone,
40 },
41
42 TextPayload: e.TextPayload,
43 StructPayload: e.StructPayload,
44 }
45
46 // Cloud logging defaults to DEFAULT; therefore, if the entry specifies
47 // Default value, there's no need to explicitly include it in the log me ssage.
48 if e.Severity != Default {
49 if err := e.Severity.Validate(); err != nil {
50 return nil, err
51 }
52 entry.Metadata.Severity = e.Severity.String()
53 }
54
55 if !e.Timestamp.IsZero() {
56 entry.Metadata.Timestamp = formatTimestamp(e.Timestamp)
57 }
58 return &entry, nil
59 }
60
61 // formatTimestamp formats a time.Time such that it is compatible with Cloud
62 // Logging timestamp.
63 func formatTimestamp(t time.Time) string {
64 return t.UTC().Format(time.RFC3339Nano)
65 }
OLDNEW
« no previous file with comments | « common/cloudlogging/client_test.go ('k') | common/cloudlogging/severity.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698