Skip to content

Log API ​

Provides formatted writing, tail reading, and clearing for log files in the foobar2000 profile directory.

log ​

log.clear ​

Empty webview_ui.log.

This method takes no parameters.

Returns

success is true on success. On failure the response is { success: false, error, code }; see Error codes for code.

js
const result = await fb2k.invoke('log.clear');

log.read ​

Read the last lines of webview_ui.log. A file that does not exist yet reads as empty.

ParameterTypeRequiredDescription
linesintegerNoHow many lines to return from the end of the file. At least 0. Default: 100.

Returns

FieldTypeDescription
contentstringThe returned lines joined with \n.
linesstring[]The returned lines. Absent when the file does not exist.
lineCountintegerNumber of lines returned.
totalLinesintegerNumber of lines in the whole file. Absent when the file does not exist.

success is true on success. On failure the response is { success: false, error, code }; see Error codes for code.

js
const res = await fb2k.invoke('log.read', { lines: 50 });
if (res.success === false) throw new Error(res.error);
const { content } = res;

log.write ​

Write a line to a log file in the foobar2000 profile directory: webview_ui.log, or the file named by file.

ParameterTypeRequiredDescription
messageanyNoWhat to write. A string is written as it is; any other JSON value as its JSON text. Takes precedence over args.
argsany[]NoValues to write, separated by spaces: strings as they are, other values as their JSON text. Used only when message is absent.
levelstringNoLevel written in brackets before the message, upper-cased. Default: "info".
appendbooleanNoAppend to the file; false replaces its content with this line. Default: true.
timestampbooleanNoPrefix the line with the local time, as [YYYY-MM-DD HH:MM:SS.mmm]. Default: true.
filestringNoName of another file in the profile directory. It must be a plain file name ending in .log or .txt and not a Windows device name such as CON; any other value is ignored and the line goes to webview_ui.log.

Returns

FieldTypeDescription
pathstringFull path of the file that was written.

success is true on success. On failure the response is { success: false, error, code }; see Error codes for code.

Provide one of message or args; a call with neither fails with INVALID_PARAMS (message is required).

js
await fb2k.invoke('log.write', { message: 'panel initialized' });

Owner-family behavior and limits ​

  • console.log, console.warn, console.error, and log.write require one of message or args. log.write.file, when accepted, is only a leaf .log or .txt filename under the profile directory; paths, traversal and Windows reserved device names are rejected by the runtime.

Contract supplements ​

The sections below close public-contract findings from the strict parameter audit without replacing existing explanations.

Contract supplement: log.write ​

ParameterTypeRequiredDefaultDescription
messagestringNoomittedLog text. Non-string values are serialized.
argsarrayNo[]Argument list joined with spaces when message is omitted.
filestringNoomittedLeaf .log or .txt filename under the profile directory.
levelstringNoinfoLevel tag written in upper case before the message.
appendbooleanNotrueAppends when true; truncates the file first when false.
timestampbooleanNotruePrefixes each line with a timestamp.

Return fields ​

FieldTypeOptional
errorstringYes
successbooleanNo
pathjsonNo

Semantics: omitted optional parameters use handler defaults. One of message or args must be present.

js
await fb2k.invoke('log.write', { message: 'startup complete', level: 'warn' });