created: 20201120152706842
modified: 20260105121111637
tags: Widgets [[Debugging Widgets]]
title: LogWidget
type: text/vnd.tiddlywiki

! Introduction

<<.from-version "5.1.23">> The <<.wid log>> widget is a [[widget|Widgets]] that can be used to output debugging information to the [[JavaScript console|Web Developer Tools]] supported by most browsers.

When the widget is rendered or refreshed, the names and values of all [[attributes|Widget Attributes]] are logged to the JavaScript console.

```
<$log name=value />
```

<<.note """ For debugging inside of actions see [[ActionLogWidget]]""">>

! Content and Attributes

The <<.wid log>> widget is invisible. Any content within it is ignored.


|!Attribute |!Description |
|<<.attr $$filter>>|(Optional) All variables whose name matches the [[Filter Expression]] will be logged |
|<<.attr $$message>> |(Optional) A message to display as the title of the information logged. Useful when several <<.wid log>> widgets are used in sequence |
|<<.attr $$all>> |(Optional) Set to <<.value yes>> to log all variables |

<<.note """ If `<$log />` is called without any attributes, all defined variables will be logged as if `$$all=yes` were set.""">>

<<.note """When logging [[Variable Attribute Values]], the body text of macros and procedures will be output as their value. Functions are evaluated and their first result is logged.""">>

! Examples

!! Basic Example

Log the value of variable <<.var name>>, the first result of the filter expression `[tag[Learning]]` and the value of field <<.field created>> of the current tiddler:

```
<$log name=<<name>> filter={{{ [tag[Learning]] }}} created={{!!created}} />
```

!! Example using <<.attr $$filter>> and <<.attr $$message>> 

Log all core variables (which start with <<.var tv->>) with a table title:

```
<$log $$message="Core Variables" $$filter="[prefix[tv-]]" />
```

!! Widget Debugging

Change a misbehaving <<.wlink TranscludeWidget>> widget to a <<.wid log>> widget to verify that <<.var name>> and <<.var mode>> match their expected values:

<<.tip """If a widget is not behaving as expected it is often useful to temporarily change it to a <<.wid log>> widget so that the passed attributes can be verified.""">>

```
<$log $variable=<<name>> $mode=<<mode>> />
```

This application is the primary reason that the attributes of the <<.wid log>> widget are prefixed with two dollar signs instead of one. Otherwise, the attributes of the original widget could be interpreted as attributes to <<.wid log>> and lead to unintended consequences.

!! Example with Function

Log the <<.var tiddlerList>> function definition and its first evaluation result (see browser console after clicking "Try it"):

<<.example n:"2" eg:"""\function tiddlerList() [tag[Learning]]

<$log $$filter="[title[tiddlerList]]" value=<<tiddlerList>> />""" >>

<<.note """The values output with the <<.attr $$filter>> or <<.attr $$all>> attributes will only contain the definition of functions instead of their values, as the evaluation of many functions can lead to significant performance penalties.""">>