docs(guide): document script logging

This commit is contained in:
Elian Doran 2025-10-01 20:22:50 +03:00
parent 7cfebbabeb
commit 95b1c82ccb
No known key found for this signature in database
8 changed files with 362 additions and 281 deletions

File diff suppressed because one or more lines are too long

View File

@ -6,22 +6,19 @@ class="image">
<img style="aspect-ratio:1144/660;" src="Sharing_image.png" width="1144" <img style="aspect-ratio:1144/660;" src="Sharing_image.png" width="1144"
height="660"> height="660">
</figure> </figure>
<h2>Features, interaction and limitations</h2> <h2>Features, interaction and limitations</h2>
<ul> <ul>
<li data-list-item-id="eb3d8067f5cb94bac4a4a84183ef4ed02">Searching by note title.</li> <li>Searching by note title.</li>
<li data-list-item-id="ed2b6bee8436ae78524bb348bab92b590">Automatic dark/light mode based on the user's browser settings.</li> <li>Automatic dark/light mode based on the user's browser settings.</li>
<li <li>Mobile-friendly layout, with sidebar.</li>
data-list-item-id="e3d6e72b17bee26edd1cdf32f6622d1a8">Mobile-friendly layout, with sidebar.</li> <li>Collapsible tree with the same note icons as the application.</li>
<li data-list-item-id="e82d45b6ad8b782bf44e765283f7648af">Collapsible tree with the same note icons as the application.</li> <li>Customizable logo.</li>
<li <li>Toggle button for dark/light mode, which also stores the user preferences.</li>
data-list-item-id="e9672befb64e973ce887f2a993f426f22">Customizable logo.</li> <li>Quick navigation buttons (previous and next note).</li>
<li data-list-item-id="e4aa50a784c9b83cdbe894eac6c4512e9">Toggle button for dark/light mode, which also stores the user preferences.</li> <li>Displaying the date of the last update of the note.</li>
<li
data-list-item-id="e0ba76ae1a1b97e38ca239ccc919ad562">Quick navigation buttons (previous and next note).</li>
<li data-list-item-id="e2a6c8a3de7eedaf5b344f136e298fd49">Displaying the date of the last update of the note.</li>
</ul> </ul>
<h3>By note type</h3> <h3>By note type</h3>
<figure class="table">
<table class="ck-table-resized"> <table class="ck-table-resized">
<colgroup> <colgroup>
<col style="width:19.92%;"> <col style="width:19.92%;">
@ -45,8 +42,8 @@ class="image">
<li data-list-item-id="e9707fdfa2c92d66690cf932f7e647253">Syntax highlight of code blocks, provided a language is selected (does <li data-list-item-id="e9707fdfa2c92d66690cf932f7e647253">Syntax highlight of code blocks, provided a language is selected (does
not work if “Auto-detected” is enabled).</li> not work if “Auto-detected” is enabled).</li>
<li data-list-item-id="e84420a10c6d64bd107edb6e867c91d4b">Rendering for math equations.</li> <li data-list-item-id="e84420a10c6d64bd107edb6e867c91d4b">Rendering for math equations.</li>
<li data-list-item-id="e10834dcd0619d77ae2e94d3695bedf58"><a href="#root/pOsGYCXsbNQG/KSZ04uQ2D1St/iPIMuisry3hd/_help_nBAXQFj20hS1">Including notes</a> (only <li data-list-item-id="e10834dcd0619d77ae2e94d3695bedf58"><a href="#root/_help_nBAXQFj20hS1">Including notes</a> (only if the included
if the included notes are also shared).</li> notes are also shared).</li>
</ul> </ul>
</td> </td>
<td> <td>
@ -169,15 +166,13 @@ class="image">
</tr> </tr>
</tbody> </tbody>
</table> </table>
</figure>
<p>While the sharing feature is powerful, it has some limitations:</p> <p>While the sharing feature is powerful, it has some limitations:</p>
<ul> <ul>
<li data-list-item-id="e4d030291f0f3baf41b533c9aab0958fa"><strong>Code Notes</strong>: No syntax highlighting.</li> <li><strong>Code Notes</strong>: No syntax highlighting.</li>
<li class="ck-list-marker-bold" <li><strong>Static Note Tree</strong>
data-list-item-id="ec84705de13a1a2ce9f21bc5fd8b3ad64"><strong>Static Note Tree</strong>
</li> </li>
<li data-list-item-id="e5391374edc6fa023765af8802dae2d75"><strong>Protected Notes</strong>: Cannot be shared.</li> <li><strong>Protected Notes</strong>: Cannot be shared.</li>
<li data-list-item-id="e6556bb11a4c4bf2f4d44519a8c055634"><strong>Include Notes</strong>: Not supported.</li> <li><strong>Include Notes</strong>: Not supported.</li>
</ul> </ul>
<p>Some of these limitations may be addressed in future updates.</p> <p>Some of these limitations may be addressed in future updates.</p>
<h2>Prerequisites</h2> <h2>Prerequisites</h2>
@ -186,7 +181,7 @@ class="image">
This is necessary because the notes will be hosted from the server.</p> This is necessary because the notes will be hosted from the server.</p>
<h2>Sharing a note</h2> <h2>Sharing a note</h2>
<ol> <ol>
<li data-list-item-id="eb0acda67602064cf3393dd478527d708"> <li>
<p><strong>Enable Sharing</strong>: To share a note, toggle the <code>Shared</code> switch <p><strong>Enable Sharing</strong>: To share a note, toggle the <code>Shared</code> switch
within the note's interface. Once sharing is enabled, an URL will appear, within the note's interface. Once sharing is enabled, an URL will appear,
which you can click to access the shared note.</p> which you can click to access the shared note.</p>
@ -194,9 +189,11 @@ class="image">
<img src="Sharing_share-single-note.png" alt="Share Note"> <img src="Sharing_share-single-note.png" alt="Share Note">
</p> </p>
</li> </li>
<li data-list-item-id="e295548918d29695504a2356e807593e5"><strong>Access the Shared Note</strong>: The link provided will open the <li>
<p><strong>Access the Shared Note</strong>: The link provided will open the
note in your browser. If your server is not configured with a public IP, note in your browser. If your server is not configured with a public IP,
the URL will refer to <code>localhost (127.0.0.1)</code>.</li> the URL will refer to <code>localhost (127.0.0.1)</code>.</p>
</li>
</ol> </ol>
<h2>Sharing a note subtree</h2> <h2>Sharing a note subtree</h2>
<p>When you share a note, you actually share the entire subtree of notes <p>When you share a note, you actually share the entire subtree of notes
@ -222,13 +219,12 @@ class="image">
<p>The default design should be a good starting point, but you can customize <p>The default design should be a good starting point, but you can customize
it using your own CSS:</p> it using your own CSS:</p>
<ul> <ul>
<li data-list-item-id="e86cb1bab4a5f642720bad026d50f7742"><strong>Custom CSS</strong>: Link a CSS&nbsp;<a class="reference-link" <li><strong>Custom CSS</strong>: Link a CSS&nbsp;<a class="reference-link"
href="#root/_help_6f9hih2hXXZk">Code</a>&nbsp;note to the shared page by href="#root/_help_6f9hih2hXXZk">Code</a>&nbsp;note to the shared page by
adding a <code>~shareCss</code> relation to the note. If you want this style adding a <code>~shareCss</code> relation to the note. If you want this style
to apply to the entire subtree, make the label inheritable. You can hide to apply to the entire subtree, make the label inheritable. You can hide
the CSS code note from the tree navigation by adding the <code>#shareHiddenFromTree</code> label.</li> the CSS code note from the tree navigation by adding the <code>#shareHiddenFromTree</code> label.</li>
<li <li><strong>Omitting Default CSS</strong>: For extensive styling changes,
data-list-item-id="ec911775f2f39d62f7a6a2ab762e3f773"><strong>Omitting Default CSS</strong>: For extensive styling changes,
use the <code>#shareOmitDefaultCss</code> label to avoid conflicts with Trilium's use the <code>#shareOmitDefaultCss</code> label to avoid conflicts with Trilium's
<a <a
href="#root/_help_Wy267RK4M69c">default stylesheet</a>.</li> href="#root/_help_Wy267RK4M69c">default stylesheet</a>.</li>
@ -251,8 +247,8 @@ for (const attr of parentNote.attributes) {
This will change the URL to <code>http://domain.tld/share/highlighting</code>.</p> This will change the URL to <code>http://domain.tld/share/highlighting</code>.</p>
<p><strong>Important</strong>:</p> <p><strong>Important</strong>:</p>
<ol> <ol>
<li data-list-item-id="e15a33a78ef6f36ad0aa99341387051b0">Ensure that aliases are unique.</li> <li>Ensure that aliases are unique.</li>
<li data-list-item-id="ed1ec56ed4f152f9adceacf6053ecaac2">Using slashes (<code>/</code>) within aliases to create subpaths is not <li>Using slashes (<code>/</code>) within aliases to create subpaths is not
supported.</li> supported.</li>
</ol> </ol>
<h3>Setting a custom favicon</h3> <h3>Setting a custom favicon</h3>
@ -275,7 +271,6 @@ for (const attr of parentNote.attributes) {
When viewed, the list of shared roots will be displayed at the bottom of When viewed, the list of shared roots will be displayed at the bottom of
the note.</p> the note.</p>
<h2>Attribute reference</h2> <h2>Attribute reference</h2>
<figure class="table">
<table> <table>
<thead> <thead>
<tr> <tr>
@ -351,7 +346,7 @@ for (const attr of parentNote.attributes) {
</tr> </tr>
</tbody> </tbody>
</table> </table>
</figure>
<h2>Credits</h2> <h2>Credits</h2>
<p>Since v0.95.0, a new theme was introduced (and enabled by default) which <p>Since v0.95.0, a new theme was introduced (and enabled by default) which
greatly improves the visual aspect of the Share feature, as well as its greatly improves the visual aspect of the Share feature, as well as its

View File

@ -7,9 +7,9 @@
<img src="Include Note_image.png">button. There is also a keyboard shortcut defined for it but it is not <img src="Include Note_image.png">button. There is also a keyboard shortcut defined for it but it is not
allocated by default.</p> allocated by default.</p>
<h2>Included notes in the share functionality</h2> <h2>Included notes in the share functionality</h2>
<p>If a <a href="#root/pOsGYCXsbNQG/tC7s2alapj8V/_help_R9pX4DGra2Vt">shared note</a> contains <p>If a <a href="#root/_help_R9pX4DGra2Vt">shared note</a> contains one or
one or more included notes, they will be displayed in the content of the more included notes, they will be displayed in the content of the note
note as if they were part of the note itself.</p> as if they were part of the note itself.</p>
<p>For this to work, the included notes must also be shared, otherwise they <p>For this to work, the included notes must also be shared, otherwise they
will not be shown. However, the included notes can still be hidden from will not be shown. However, the included notes can still be hidden from
the note tree via <code>#shareHiddenFromTree</code>.</p> the note tree via <code>#shareHiddenFromTree</code>.</p>

View File

@ -0,0 +1,24 @@
<p>Both front-end and back-end notes can log messages for debugging.</p>
<h2>UI logging via <code>api.log</code></h2>
<figure class="image image_resized image-style-align-center" style="width:57.74%;">
<img style="aspect-ratio:749/545;" src="Logging_image.png" width="749"
height="545">
</figure>
<p>The API log feature integrates with the script editor and it displays
all the messages logged via <code>api.log</code>. This works for both back-end
and front-end scripts.</p>
<p>The API log panel will appear after executing a script that uses <code>api.log</code> and
it can be dismissed temporarily by pressing the close button in the top-right
of the panel.</p>
<p>Apart from strings, an object can be passed as well in which case it will
be pretty-formatted if possible (e.g. recursive objects are not supported).</p>
<h2>Console logging</h2>
<p>For logs that are not directly visible to the user, the standard <code>console.log</code> can
be used as well.</p>
<ul>
<li data-list-item-id="ec01fd8ccf51930dda1c2f707e78c0842">For front-end scripts, the log will be shown in the Developer Tools (also
known as Inspect).</li>
<li data-list-item-id="e62355c5371735daf1c436b4d65ba3549">For back-end scripts, the log will be shown in the server output while
running but <strong>will not</strong> be visible in the&nbsp;<a class="reference-link"
href="#root/pOsGYCXsbNQG/BgmBlOIl72jZ/qzNzp9LYQyPT/_help_bnyigUA2UK7s">Backend (server) logs</a>.</li>
</ul>

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

View File

@ -10367,122 +10367,129 @@
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "6f9hih2hXXZk", "value": "nBAXQFj20hS1",
"isInheritable": false, "isInheritable": false,
"position": 20 "position": 20
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "m523cpzocqaD", "value": "6f9hih2hXXZk",
"isInheritable": false, "isInheritable": false,
"position": 30 "position": 30
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "iRwzGnHPzonm", "value": "m523cpzocqaD",
"isInheritable": false, "isInheritable": false,
"position": 40 "position": 40
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "bdUJEHsAPYQR", "value": "iRwzGnHPzonm",
"isInheritable": false, "isInheritable": false,
"position": 50 "position": 50
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "HcABDtFCkbFN", "value": "bdUJEHsAPYQR",
"isInheritable": false, "isInheritable": false,
"position": 60 "position": 60
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "GTwFsgaA0lCt", "value": "HcABDtFCkbFN",
"isInheritable": false, "isInheritable": false,
"position": 70 "position": 70
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "s1aBHPd79XYj", "value": "GTwFsgaA0lCt",
"isInheritable": false, "isInheritable": false,
"position": 80 "position": 80
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "grjYqerjn243", "value": "s1aBHPd79XYj",
"isInheritable": false, "isInheritable": false,
"position": 90 "position": 90
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "1vHRoWCEjj0L", "value": "grjYqerjn243",
"isInheritable": false, "isInheritable": false,
"position": 100 "position": 100
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "gBbsAeiuUxI5", "value": "1vHRoWCEjj0L",
"isInheritable": false, "isInheritable": false,
"position": 110 "position": 110
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "81SGnPGMk7Xc", "value": "gBbsAeiuUxI5",
"isInheritable": false, "isInheritable": false,
"position": 120 "position": 120
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "W8vYD3Q1zjCR", "value": "81SGnPGMk7Xc",
"isInheritable": false, "isInheritable": false,
"position": 130 "position": 130
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "WOcw2SLH6tbX", "value": "W8vYD3Q1zjCR",
"isInheritable": false, "isInheritable": false,
"position": 140 "position": 140
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "x3i7MxGccDuM", "value": "WOcw2SLH6tbX",
"isInheritable": false, "isInheritable": false,
"position": 150 "position": 150
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "bwZpz2ajCEwO", "value": "x3i7MxGccDuM",
"isInheritable": false, "isInheritable": false,
"position": 160 "position": 160
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "Wy267RK4M69c", "value": "bwZpz2ajCEwO",
"isInheritable": false, "isInheritable": false,
"position": 170 "position": 170
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "Qjt68inQ2bRj", "value": "Wy267RK4M69c",
"isInheritable": false, "isInheritable": false,
"position": 180 "position": 180
}, },
{
"type": "relation",
"name": "internalLink",
"value": "Qjt68inQ2bRj",
"isInheritable": false,
"position": 190
},
{ {
"type": "label", "type": "label",
"name": "shareAlias", "name": "shareAlias",
@ -10496,13 +10503,6 @@
"value": "bx bx-share-alt", "value": "bx bx-share-alt",
"isInheritable": false, "isInheritable": false,
"position": 30 "position": 30
},
{
"type": "relation",
"name": "internalLink",
"value": "nBAXQFj20hS1",
"isInheritable": false,
"position": 190
} }
], ],
"format": "markdown", "format": "markdown",
@ -13209,6 +13209,49 @@
"attachments": [] "attachments": []
} }
] ]
},
{
"isClone": false,
"noteId": "vElnKeDNPSVl",
"notePath": [
"pOsGYCXsbNQG",
"CdNpE2pqjmI6",
"vElnKeDNPSVl"
],
"title": "Logging",
"notePosition": 100,
"prefix": null,
"isExpanded": false,
"type": "text",
"mime": "text/html",
"attributes": [
{
"type": "relation",
"name": "internalLink",
"value": "bnyigUA2UK7s",
"isInheritable": false,
"position": 10
},
{
"type": "label",
"name": "iconClass",
"value": "bx bx-terminal",
"isInheritable": false,
"position": 20
}
],
"format": "markdown",
"dataFileName": "Logging.md",
"attachments": [
{
"attachmentId": "OFVZwVeITJOR",
"title": "image.png",
"role": "image",
"mime": "image/png",
"position": 10,
"dataFileName": "Logging_image.png"
}
]
} }
] ]
} }

View File

@ -0,0 +1,19 @@
# Logging
Both front-end and back-end notes can log messages for debugging.
## UI logging via `api.log`
<figure class="image image_resized image-style-align-center" style="width:57.74%;"><img style="aspect-ratio:749/545;" src="Logging_image.png" width="749" height="545"></figure>
The API log feature integrates with the script editor and it displays all the messages logged via `api.log`. This works for both back-end and front-end scripts.
The API log panel will appear after executing a script that uses `api.log` and it can be dismissed temporarily by pressing the close button in the top-right of the panel.
Apart from strings, an object can be passed as well in which case it will be pretty-formatted if possible (e.g. recursive objects are not supported).
## Console logging
For logs that are not directly visible to the user, the standard `console.log` can be used as well.
* For front-end scripts, the log will be shown in the Developer Tools (also known as Inspect).
* For back-end scripts, the log will be shown in the server output while running but **will not** be visible in the <a class="reference-link" href="../Troubleshooting/Error%20logs/Backend%20(server)%20logs.md">Backend (server) logs</a>.

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB