Sidechair

log.error()

Browse the reference

Writes an error to the Pine Logs panel and lets the script keep running, unlike runtime.error.

Try it in the editor

log.error(message) adds a line at the error level. log.error(formatString, arg0, arg1, ...) fills {0}, {1} and so on in the format string with the arguments. The script is not stopped.

Use it to report a failed check while still returning a usable result, for example logging a bad input and falling back to a default. When the script cannot continue, call runtime.error instead.

Syntax

Pine Script
log.error(message: series string) -> void
log.error(formatString: series string, arg0, arg1, ...: series int/float/bool/string/array<int/float/bool/string>) -> void

Arguments

NameTypeDefaultDescription
messageseries stringrequiredThe text written to the log. It is one string, so build it with str.tostring or str.format.
formatStringseries stringrequiredText containing placeholders {0}, {1} and so on, filled with the arguments that follow.
arg0series int/float/bool/string/array<int/float/bool/string>requiredThe value for {0} in the format string.
arg1series int/float/bool/string/array<int/float/bool/string>requiredThe value for {1} in the format string.
...series int/float/bool/string/array<int/float/bool/string>requiredMore values for {2}, {3} and so on. Numbers, bools, strings and arrays of them are accepted.

Returns

Nothing.

Remarks

  • The log line carries the bar it was written on, so you can find the first bar where a condition failed.

Example

Pine ScriptLog a bad length and fall backOpen in editor
//@version=6
indicator("Length check")
len = input.int(20, "Length")
safe = len < 2 ? 2 : len
if barstate.isfirst and len < 2
    log.error("Length {0} is too small, using 2", len)
plot(ta.sma(close, safe), "SMA", color.blue)

See also

Runs on Sidechair