log

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 12 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Critical added in v1.0.5

func Critical(ctx context.Context, err error)

Critical ... Criticalログの定形を出力する

func Criticalc

func Criticalc(ctx context.Context, code int, format string, args ...any) error

Criticalc ... Criticalログを出力してコード付きのエラーを生成する

func Criticale

func Criticale(ctx context.Context, format string, args ...any) error

Criticale ... Criticalログを出力してエラーを生成する

func Criticalf

func Criticalf(ctx context.Context, format string, args ...any)

Criticalf ... Criticalログを出力する

func Debug added in v1.0.5

func Debug(ctx context.Context, err error)

Debug ... Debugログの定形を出力する

func Debugc

func Debugc(ctx context.Context, code int, format string, args ...any) error

Debugc ... Debugログを出力してコード付きのエラーを生成する

func Debuge

func Debuge(ctx context.Context, format string, args ...any) error

Debuge ... Debugログを出力してエラーを生成する

func Debugf

func Debugf(ctx context.Context, format string, args ...any)

Debugf ... Debugログを出力する

func Error added in v1.0.5

func Error(ctx context.Context, err error)

Error ... Errorログの定形を出力する

func Errorc

func Errorc(ctx context.Context, code int, format string, args ...any) error

Errorc ... Errorログを出力してコード付きのエラーを生成する

func Errore

func Errore(ctx context.Context, format string, args ...any) error

Errore ... Errorログを出力してエラーを生成する

func Errorf

func Errorf(ctx context.Context, format string, args ...any)

Errorf ... Errorログを出力する

func Info added in v1.0.5

func Info(ctx context.Context, err error)

Info ... Infoログの定形を出力する

func Infoc

func Infoc(ctx context.Context, code int, format string, args ...any) error

Infoc ... Infoログを出力してコード付きのエラーを生成する

func Infoe

func Infoe(ctx context.Context, format string, args ...any) error

Infoe ... Infoログを出力してエラーを生成する

func Infof

func Infof(ctx context.Context, format string, args ...any)

Infof ... Infoログを出力する

func Panic

func Panic(ctx context.Context, rcvr any) string

Panic ... Panicをハンドリングする

func SetLogger

func SetLogger(ctx context.Context, logger *Logger) context.Context

SetLogger ... HTTPHeaderの値を設定

func SetResponseStatus

func SetResponseStatus(ctx context.Context, status int)

SetResponseStatus ... レスポンスのステータスコードを設定する

func Warning added in v1.0.5

func Warning(ctx context.Context, err error)

Warning ... Warningログの定形を出力する

func Warningc

func Warningc(ctx context.Context, code int, format string, args ...any) error

Warningc ... Warningログを出力してコード付きのエラーを生成する

func Warninge

func Warninge(ctx context.Context, format string, args ...any) error

Warninge ... Warningログを出力してエラーを生成する

func Warningf

func Warningf(ctx context.Context, format string, args ...any)

Warningf ... Warningログを出力する

Types

type Duration

type Duration time.Duration

Duration ... ProtocolBufferのフォーマット

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

MarshalJSON ... JSONに変換

type Entry

type Entry struct {
	Severity    string            `json:"severity"`
	HTTPRequest *EntryHTTPRequest `json:"httpRequest,omitempty"`
	Time        Time              `json:"time"`
	Trace       string            `json:"logging.googleapis.com/trace"`
	TraceID     string            `json:"traceId"`
	Childs      []*EntryChild     `json:"childs"`
	Message     string            `json:"message,omitempty"`
}

Entry ... 構造ログ定義 https://cloud.google.com/logging/docs/agent/configuration#special-fields

type EntryChild

type EntryChild struct {
	Severity string `json:"severity"`
	Message  string `json:"message"`
	Time     Time   `json:"time"`
}

EntryChild ... 子ログの構造ログ定義

type EntryHTTPRequest

type EntryHTTPRequest struct {
	RequestMethod                  string   `json:"requestMethod"`
	RequestURL                     string   `json:"requestUrl"`
	RequestSize                    int64    `json:"requestSize,string,omitempty"`
	Status                         int      `json:"status"`
	ResponseSize                   int64    `json:"responseSize,string,omitempty"`
	UserAgent                      string   `json:"userAgent,omitempty"`
	Referer                        string   `json:"referer,omitempty"`
	Latency                        Duration `json:"latency,omitempty"`
	CacheLookup                    *bool    `json:"cacheLookup,omitempty"`
	CacheHit                       *bool    `json:"cacheHit,omitempty"`
	CacheValidatedWithOriginServer *bool    `json:"cacheValidatedWithOriginServer,omitempty"`
	CacheFillBytes                 *int64   `json:"cacheFillBytes,string,omitempty"`
	Protocol                       string   `json:"protocol"`
}

EntryHTTPRequest ... HTTPリクエストの構造ログ定義 https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#httprequest

type EntrySourceLocation

type EntrySourceLocation struct {
	File     string `json:"file,omitempty"`
	Line     int64  `json:"line,string,omitempty"`
	Function string `json:"function,omitempty"`
}

EntrySourceLocation ... SourceLocationの構造ログ定義 https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logentrysourcelocation

type Logger

type Logger struct {
	Writer            Writer
	MinOutSeverity    Severity
	MaxOuttedSeverity Severity
	TraceID           string
	ResponseStatus    int
	ApplicationLogs   []*EntryChild
}

Logger ... ロガー

func GetLogger

func GetLogger(ctx context.Context) *Logger

GetLogger ... HTTPHeaderの値を取得

func NewLogger

func NewLogger(writer Writer, minSeverity Severity, traceID string) *Logger

NewLogger ... Loggerを作成する

func (*Logger) AddApplicationLog

func (l *Logger) AddApplicationLog(severity Severity, file string, line int64, function string, msg string, at time.Time)

AddApplicationLog ... アプリケーションログ履歴を記録する

func (*Logger) IsLogging

func (l *Logger) IsLogging(severity Severity) bool

IsLogging ... レベル毎のログ出力許可

func (*Logger) SetOuttedSeverity

func (l *Logger) SetOuttedSeverity(severity Severity)

SetOuttedSeverity ... 出力された最大のレベルを設定

func (*Logger) WriteJob added in v1.3.0

func (l *Logger) WriteJob(ctx context.Context)

WriteJob ... ジョブログを出力する

func (*Logger) WriteRequest

func (l *Logger) WriteRequest(r *http.Request, at time.Time, dr time.Duration)

WriteRequest ... リクエストログを出力する

type Middleware

type Middleware struct {
	Writer         Writer
	MinOutSeverity Severity
}

Middleware ... ロガー

func NewMiddleware

func NewMiddleware(writer Writer, minOutSeverity string) *Middleware

func (*Middleware) Handle

func (m *Middleware) Handle(next http.Handler) http.Handler

Handle ... ロガーを初期化する

func (*Middleware) SetLogger added in v1.3.0

func (m *Middleware) SetLogger(ctx context.Context) context.Context

func (*Middleware) WriteJob added in v1.3.0

func (m *Middleware) WriteJob(ctx context.Context)

type Severity

type Severity int

Severity ... ログレベル spec: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity

const (
	// SeverityDefault ... ログレベル: Default
	SeverityDefault Severity = 0
	// SeverityDebug ... ログレベル: Debug
	SeverityDebug Severity = 100
	// SeverityInfo ... ログレベル: Info
	SeverityInfo Severity = 200
	// SeverityWarning ... ログレベル: Warning
	SeverityWarning Severity = 400
	// SeverityError ... ログレベル: Error
	SeverityError Severity = 500
	// SeverityCritical ... ログレベル: Critical
	SeverityCritical Severity = 600
)

func NewSeverity

func NewSeverity(s string) Severity

NewSeverity ... Severityを作成する

func (Severity) String

func (c Severity) String() string

type Time

type Time time.Time

Time ... ProtocolBufferのフォーマット

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON ... JSONに変換

type Writer

type Writer interface {
	Request(
		severity Severity,
		traceID string,
		applicationLogs []*EntryChild,
		r *http.Request,
		status int,
		at time.Time,
		dr time.Duration,
	)

	Job(
		severity Severity,
		traceID string,
		applicationLogs []*EntryChild,
	)

	Application(
		severity Severity,
		traceID string,
		msg string,
		file string,
		line int64,
		function string,
		at time.Time,
	)
}

Writer ... ログの出力

func NewWriterStackdriver

func NewWriterStackdriver(projectID string) Writer

func NewWriterStdout

func NewWriterStdout() Writer

Jump to

Keyboard shortcuts

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