logpolicy

package
v1.40.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: BSD-3-Clause Imports: 44 Imported by: 24

Documentation

Overview

Package logpolicy manages the creation or reuse of logtail loggers, caching collection instance state on disk for use on future runs of programs on the same machine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogHost deprecated added in v1.20.0

func LogHost() string

LogHost returns the hostname only (without port) of the configured logtail server, or the default.

Deprecated: Use LogURL instead.

func LogURL added in v1.32.0

func LogURL() string

LogURL is the base URL for the configured logtail server, or the default. It is guaranteed to not terminate with any forward slashes.

func LogsDir added in v1.38.0

func LogsDir(logf logger.Logf) string

LogsDir returns the directory to use for log configuration and buffer storage.

func MakeDialFunc added in v1.40.0

func MakeDialFunc(netMon *netmon.Monitor) func(ctx context.Context, netw, addr string) (net.Conn, error)

MakeDialFunc creates a net.Dialer.DialContext function specialized for use by logtail. It does the following:

  • If DNS lookup fails, consults the bootstrap DNS list of Tailscale hostnames.
  • If TLS connection fails, try again using LetsEncrypt's built-in root certificate, for the benefit of older OS platforms which might not include it.

The netMon parameter is optional; if non-nil it's used to do faster interface lookups.

func NewLogtailTransport added in v1.20.0

func NewLogtailTransport(host string, netMon *netmon.Monitor) http.RoundTripper

NewLogtailTransport returns an HTTP Transport particularly suited to uploading logs to the given host name. See DialContext for details on how it works. The netMon parameter is optional; if non-nil it's used to do faster interface lookups.

Types

type Config

type Config struct {
	Collection string
	PrivateID  logid.PrivateID
	PublicID   logid.PublicID
}

Config represents an instance of logs in a collection.

func ConfigFromBytes

func ConfigFromBytes(jsonEnc []byte) (*Config, error)

ConfigFromBytes parses a Config from its JSON encoding.

func ConfigFromFile added in v1.28.0

func ConfigFromFile(statefile string) (*Config, error)

ConfigFromFile reads a Config from a JSON file.

func NewConfig added in v1.28.0

func NewConfig(collection string) *Config

NewConfig creates a Config with collection and a newly generated PrivateID.

func (*Config) Save added in v1.28.0

func (c *Config) Save(stateFile string) error

Save writes the JSON representation of c to stateFile.

func (*Config) ToBytes

func (c *Config) ToBytes() []byte

ToBytes returns the JSON representation of c.

func (*Config) Validate added in v1.28.0

func (c *Config) Validate(collection string) error

Validate verifies that the Config matches the collection, and that the PrivateID and PublicID pair are sensible.

type Policy

type Policy struct {
	// Logtail is the logger.
	Logtail *logtail.Logger
	// PublicID is the logger's instance identifier.
	PublicID logid.PublicID
}

Policy is a logger and its public ID.

func New

func New(collection string, netMon *netmon.Monitor) *Policy

New returns a new log policy (a logger and its instance ID) for a given collection name. The netMon parameter is optional; if non-nil it's used to do faster interface lookups.

func NewWithConfigPath added in v1.32.0

func NewWithConfigPath(collection, dir, cmdName string, netMon *netmon.Monitor) *Policy

NewWithConfigPath is identical to New, but uses the specified directory and command name. If either is empty, it derives them automatically.

func (*Policy) Close

func (p *Policy) Close()

Close immediately shuts down the logger.

func (*Policy) SetVerbosityLevel added in v1.4.0

func (p *Policy) SetVerbosityLevel(level int)

SetVerbosityLevel controls the verbosity level that should be written to stderr. 0 is the default (not verbose). Levels 1 or higher are increasingly verbose.

It should not be changed concurrently with log writes.

func (*Policy) Shutdown

func (p *Policy) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the logger, finishing any current log upload if it can be done before ctx is canceled.

Jump to

Keyboard shortcuts

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