slog

Types from the Go package slog (a library PocketBase builds on), as JavaScript sees them: they turn up as values of PocketBase's types and of hook events.

slog.Attr

An Attr is a key-value pair.

Member Type
key string
value Value
equal() (b: Attr): boolean Equal reports whether a and b have equal keys and values.
string() (): string

slog.Handler

A Handler handles log records produced by a Logger.

A typical handler may print log records to standard error, or write them to a file or database, or perhaps augment them with additional attributes and pass them on to another handler.

Any of the Handler's methods may be called concurrently with itself or with other methods. It is the responsibility of the Handler to manage this concurrency.

Users of the slog package should not invoke Handler methods directly. They should use the methods of Logger instead.

Before implementing your own handler, consult https://go.dev/s/slog-handler-guide.

Member Type
enabled() (_arg0: context.Context, _arg1: Level): boolean Enabled reports whether the handler handles records at the given level. The handler ignores records whose level is lower. It is called early, before any arguments are processed, to save effort if the log event should be discarded. If called from a Logger method, the first argument is the context passed to that method, or context.Background() if nil was passed or the method does not take a context. The context is passed so Enabled can use its values to make a decision.
handle() (_arg0: context.Context, _arg1: Record): void Handle handles the Record. It will only be called when Enabled returns true. The Context argument is as for Enabled. It is present solely to provide Handlers access to the context's values. Canceling the context should not affect record processing. (Among other things, log messages may be necessary to debug a cancellation-related problem.)
withAttrs() (attrs: Array<Attr>): Handler WithAttrs returns a new Handler whose attributes consist of both the receiver's attributes and the arguments. The Handler owns the slice: it may retain, modify or discard it.
withGroup() (name: string): Handler WithGroup returns a new Handler with the given group appended to the receiver's existing groups. The keys of all subsequent attributes, whether added by With or in a Record, should be qualified by the sequence of group names.

slog.Level

A Level is the importance or severity of a log event. The higher the level, the more important or severe the event.

Has everything Number has.

Member Type
string() (): string String returns a name for the level. If the level has a name, then that name in uppercase is returned. If the level is between named values, then an integer is appended to the uppercased name. Examples:
marshalJSON() (): string|Array<number> MarshalJSON implements [encoding/json.Marshaler] by quoting the output of Level.string.
unmarshalJSON() (data: string|Array<number>): void UnmarshalJSON implements [encoding/json.Unmarshaler] It accepts any string produced by Level.marshalJSON, ignoring case. It also accepts numeric offsets that would result in a different string on output. For example, "Error-8" would marshal as "INFO".
appendText() (b: string|Array<number>): string|Array<number> AppendText implements encoding.textAppender by calling Level.string.
marshalText() (): string|Array<number> MarshalText implements encoding.textMarshaler by calling Level.appendText.
unmarshalText() (data: string|Array<number>): void UnmarshalText implements encoding.textUnmarshaler. It accepts any string produced by Level.marshalText, ignoring case. It also accepts numeric offsets that would result in a different string on output. For example, "Error-8" would marshal as "INFO".
level() (): Level Level returns the receiver. It implements Leveler.

slog.Logger

A Logger records structured information about each call to its Log, Debug, Info, Warn, and Error methods. For each call, it creates a Record and passes it to a Handler.

To create a new Logger, call New or a Logger method that begins "With".

Member Type
handler() (): Handler Handler returns l's Handler.
with() (...args: any[]): (Logger) With returns a Logger that includes the given attributes in each output operation. Arguments are converted to attributes as if by Logger.log.
withGroup() (name: string): (Logger) WithGroup returns a Logger that starts a group, if name is non-empty. The keys of all attributes added to the Logger will be qualified by the given name. (How that qualification happens depends on the Handler.withGroup method of the Logger's Handler.)
enabled() (ctx: context.Context, level: Level): boolean Enabled reports whether l emits log records at the given context and level.
log() (ctx: context.Context, level: Level, msg: string, ...args: any[]): void Log emits a log record with the current time and the given level and message. The Record's Attrs consist of the Logger's attributes followed by the Attrs specified by args.
logAttrs() (ctx: context.Context, level: Level, msg: string, ...attrs: Attr[]): void LogAttrs is a more efficient version of Logger.log that accepts only Attrs.
debug() (msg: string, ...args: any[]): void Debug logs at LevelDebug. It uses context.background internally; to specify the context, use Logger.debugContext.
debugContext() (ctx: context.Context, msg: string, ...args: any[]): void DebugContext logs at LevelDebug with the given context.
info() (msg: string, ...args: any[]): void Info logs at LevelInfo. It uses context.background internally; to specify the context, use Logger.infoContext.
infoContext() (ctx: context.Context, msg: string, ...args: any[]): void InfoContext logs at LevelInfo with the given context.
warn() (msg: string, ...args: any[]): void Warn logs at LevelWarn. It uses context.background internally; to specify the context, use Logger.warnContext.
warnContext() (ctx: context.Context, msg: string, ...args: any[]): void WarnContext logs at LevelWarn with the given context.
error() (msg: string, ...args: any[]): void Error logs at LevelError. It uses context.background internally; to specify the context, use Logger.errorContext.
errorContext() (ctx: context.Context, msg: string, ...args: any[]): void ErrorContext logs at LevelError with the given context.

slog.Record

A Record holds information about a log event. Copies of a Record share state. Do not modify a Record after handing out a copy to it. Call NewRecord to create a new Record. Use Record.clone to create a copy with no shared state.

Member Type
time time.Time The time at which the output method (Log, Info, etc.) was called.
message string The log message.
level Level The level of the event.
pc number The program counter at the time the record was constructed, as determined by runtime.Callers. If zero, no program counter is available.
clone() (): Record Clone returns a copy of the record with no shared state. The original record and the clone can both be modified without interfering with each other.
numAttrs() (): number NumAttrs returns the number of attributes in the Record.
attrs() (f: (_arg0: Attr) => boolean): void Attrs calls f on each Attr in the Record. Iteration stops if f returns false.
addAttrs() (...attrs: Attr[]): void AddAttrs appends the given Attrs to the Record's list of Attrs. It omits empty groups.
add() (...args: any[]): void Add converts the args to Attrs as described in Logger.log, then appends the Attrs to the Record's list of Attrs. It omits empty groups.
source() (): (Source) Source returns a new Source for the log event using r's PC. If the PC field is zero, meaning the Record was created without the necessary information or the location is unavailable, then nil is returned.

slog.Value

A Value can represent any Go value, but unlike type any, it can represent most small values without an allocation. The zero Value corresponds to nil.

Member Type
kind() (): Kind Kind returns v's Kind.
any() (): any Any returns v's value as an any.
string() (): string String returns Value's value as a string, formatted like fmt.sprint. Unlike the methods Int64, Float64, and so on, which panic if v is of the wrong kind, String never panics.
int64() (): number Int64 returns v's value as an int64. It panics if v is not a signed integer.
uint64() (): number Uint64 returns v's value as a uint64. It panics if v is not an unsigned integer.
bool() (): boolean Bool returns v's value as a bool. It panics if v is not a bool.
duration() (): time.Duration Duration returns v's value as a time.duration. It panics if v is not a time.Duration.
float64() (): number Float64 returns v's value as a float64. It panics if v is not a float64.
time() (): time.Time Time returns v's value as a time.time. It panics if v is not a time.Time.
logValuer() (): LogValuer LogValuer returns v's value as a LogValuer. It panics if v is not a LogValuer.
group() (): Array<Attr> Group returns v's value as a []Attr. It panics if v's Kind is not KindGroup.
equal() (w: Value): boolean Equal reports whether v and w represent the same Go value.
resolve() (): Value Resolve repeatedly calls LogValue on v while it implements LogValuer, and returns the result. If v resolves to a group, the group's attributes' values are not recursively resolved. If the number of LogValue calls exceeds a threshold, a Value containing an error is returned. Resolve's return value is guaranteed not to be of Kind KindLogValuer.

slog.Source

Source describes the location of a line of source code.

Member Type
function string Function is the package path-qualified function name containing the source line. If non-empty, this string uniquely identifies a single function in the program. This may be the empty string if not known.
file string File and Line are the file name and line number (1-based) of the source line. These may be the empty string and zero, respectively, if not known.
line number

slog.Kind

Kind is the kind of a Value.

Has everything Number has.

Member Type
string() (): string

slog.LogValuer

A LogValuer is any Go value that can convert itself into a Value for logging.

This mechanism may be used to defer expensive operations until they are needed, or to expand a single value into a sequence of components.

Member Type
logValue() (): Value