gcplogurl

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2020 License: BSD-3-Clause Imports: 13 Imported by: 1

README

gcplogurl PkgGoDev

Build link URL to Google Cloud Platform Cloud Logging Logs Explorer.

see example.

Documentation

Overview

Example
package main

import (
	"fmt"
	"time"

	"github.com/vvakame/gcplogurl"
)

func main() {
	exp := &gcplogurl.Explorer{
		ProjectID:    "test-project",
		StorageScope: gcplogurl.StorageScopeProject,
		Query:        `trace="projects/test-project/traces/2f029f622a49837d621cbe6dc5e5d146"`,
		TimeRange: &gcplogurl.SpecificTimeWithRange{
			At:    time.Date(2020, 11, 14, 4, 20, 0, 0, time.FixedZone("Asia/Tokyo", 9*60*60)),
			Range: 2 * time.Hour,
		},
	}
	logURL := exp.String()

	fmt.Println(logURL)

}
Output:

https://console.cloud.google.com/logs/query;query=trace%3D%22projects%2Ftest-project%2Ftraces%2F2f029f622a49837d621cbe6dc5e5d146%22;storageScope=project;timeRange=2020-11-13T19:20:00Z%2F2020-11-13T19:20:00Z--PT2H?project=test-project

Index

Examples

Constants

View Source
const StorageScopeProject = storageScopeProject(0)

StorageScopeProject use scope by project.

Variables

This section is empty.

Functions

func TraceLogURL

func TraceLogURL(ctx context.Context) (string, error)

TraceLogURL construct Cloud Logging URL about this trace (request).

Example
package main

import (
	"context"
	"fmt"
	"os"

	"go.opencensus.io/trace"

	"github.com/vvakame/gcplogurl"
)

func main() {
	_ = os.Setenv("GCP_PROJECT", "test-project")
	ctx := context.Background()
	ctx, span := trace.StartSpan(ctx, "test-span")
	defer span.End()

	logURL, err := gcplogurl.TraceLogURL(ctx)
	if err != nil {
		panic(err)
	}

	fmt.Println(logURL)
}
Output:

Types

type Explorer

type Explorer struct {
	BaseURL   *url.URL
	ProjectID string
	// Query expression for logs.
	// https://cloud.google.com/logging/docs/view/logging-query-language
	Query Query
	// StorageScope for refine scope.
	StorageScope StorageScope
	// TimeRange for filter logs.
	TimeRange TimeRange
	// SummaryFields for manage summary fields.
	SummaryFields *SummaryFields
}

Explorer is a map of GCP Cloud Logging Log Explorer.

func (*Explorer) String

func (ex *Explorer) String() string

String returns represent of Explorer URL.

type Query added in v0.2.0

type Query string

type RecentRange

type RecentRange struct {
	Last time.Duration
}

RecentRange provides "** seconds/minutes/hours/days ago".

type SpecificTimeBetween

type SpecificTimeBetween struct {
	From time.Time
	To   time.Time
}

SpecificTimeBetween pvovides custom range.

type SpecificTimeWithRange

type SpecificTimeWithRange struct {
	At    time.Time
	Range time.Duration
}

SpecificTimeWithRange provides jump tp time.

type StorageScope

type StorageScope interface {
	// contains filtered or unexported methods
}

StorageScope means scope about logs.

type StorageScopeStorage

type StorageScopeStorage struct {
	Src []string
}

StorageScopeStorage use scope by storage.

type SummaryFields

type SummaryFields struct {
	Fields       []string
	Truncate     bool
	MaxLen       int
	TruncateFrom TruncateFrom
}

SummaryFields provides configurations for log's summary fields.

type TimeRange

type TimeRange interface {
	// contains filtered or unexported methods
}

TimeRange means when to display the logs.

type TruncateFrom

type TruncateFrom string

TruncateFrom provides option for truncate field name.

const (
	// TruncateFromBeginning about field name.
	TruncateFromBeginning TruncateFrom = "beginning"
	// TruncateFromEnd about field name.
	TruncateFromEnd TruncateFrom = "end"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL