cloudlogger

package
v0.0.0-...-c4d653c Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package cloudlogger provides functionality to log text or json data to Google Cloud logging backend.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogProfilerReport

func LogProfilerReport(g StructuredLogger, opts *LoggerOpts) error

LogProfilerReport logs the output of logShellCommand and logUSEReport functions to a logger of type *logging.Logger. It takes as input the logger itself, and a pointer to a LoggerOpts struct that contains the shell command to execute, the number of time to execute that shell command, the interval between shell command executions, the time limit for shell command execution, the number of time to run the profiler tool, the interval between the number of times to run the profiler, and a profiler option struct that specify the component to generate USEReport for as well as any options associated to that component.

func LogText

func LogText(g TextLogger, infoToLog string) error

LogText writes the string infoToLog to a logging backend by calling the `Printf` method defined by the TextLogger interface. To log some text to Google Cloud Logging backend , pass in an instance of type *log.Logger.

Types

type LoggerOpts

type LoggerOpts struct {
	// Specifies the project ID to write logs to.
	ProjID string `json:"ProjID"`
	// Specifies the commands to run mapped with their options.
	ShCmds []ShellCmdOpts `json:"ShCmds"`
	// Specifies the number of times to run the profiler.
	ProfilerCount int `json: "ProfilerCount"`
	// Specifies the interval the profiler will run.
	ProfilerInterval time.Duration `json: "ProfilerInterval"`
	// Components on which to run profiler. It may contain CPU(s), Memory, etc.
	Components []profiler.Component
	// ProfilerCmds field specifies additional options needed to run the profiler
	ProfilerCmds []profiler.Command
}

LoggerOpts contains the options supported when logging the Profiler Report to Google Cloud Logging backend.

func (*LoggerOpts) Validate

func (l *LoggerOpts) Validate() error

Validate ensures that options are correctly set. If they aren't, the method returns a list of error messages encountered. To log the output of a shell command, the user must specify both the command, command count and interval configurations which specify the command, how often to log its output and the interval in seconds. By default, the commands will timeout after 300 seconds unless the user specified a different value using the commandTimeout configuration. Similarly, to run the profiler, the user must specify a ProfilerCount configuration if a ProfilerInterval configuration was specified.

type ShellCmdOpts

type ShellCmdOpts struct {
	// Specifies raw commands for which to log output.
	Command string `json:"Command"`
	// Specifies the number of times to run an arbitrary shell command.
	CmdCount int `json:"CmdCount"`
	// Specifies the interval separating the number of times the user runs
	// an arbitrary shell command.
	CmdInterval time.Duration `json:"CmdInterval"`
	// Specifies the amount of time it will take for the a raw shell command to
	// timeout.
	CmdTimeOut time.Duration `json: "CmdTimeOut"`
}

ShellCmdOpts contains the options that each arbitrary shell command should be mapped to.

type StructuredLogger

type StructuredLogger interface {
	Log(l logging.Entry)
	Flush() error
}

StructuredLogger defines the method required to log anything that can be marshaled to JSON to Google Cloud logging backend and the method that blocks buffered log entries until previous log entries are sent to Google Cloud logging backend.

type TextLogger

type TextLogger interface {
	Printf(text string, a ...interface{})
}

TextLogger defines the method required to log a text string to Google Cloud logging backend.

Jump to

Keyboard shortcuts

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