Skip to content

Commit a9b2b2b

Browse files
committed
Enhance log component documentation
1 parent 08cfbcb commit a9b2b2b

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed
Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,61 @@
11
INSERT INTO component(name, icon, description) VALUES
2-
('log', 'logs', 'A Component to log a message to the Servers STDOUT or Log file on page load');
2+
('log', 'logs', 'A component that writes messages to the server logs.
3+
When a page runs, it prints your message to the terminal/console (standard error).
4+
Use it to track what happens and troubleshoot issues.
5+
6+
### Where do the messages appear?
7+
8+
- Running from a terminal (Linux, macOS, or Windows PowerShell/Command Prompt): they show up in the window.
9+
- Docker: run `docker logs <container_name>`.
10+
- Linux service (systemd): run `journalctl -u sqlpage`.
11+
- Output is written to [standard error (stderr)](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)).
12+
');
313

414
INSERT INTO parameter(component, name, description, type, top_level, optional) SELECT 'log', * FROM (VALUES
515
-- top level
6-
('message', 'The message that needs to be logged', 'TEXT', TRUE, FALSE),
7-
('priority', 'The priority which the message should be logged with. Possible values are [''trace'', ''debug'', ''info'', ''warn'', ''error''] and are not case sensitive. If this value is missing or not matching any possible values, the default priority will be ''info''.', 'TEXT', TRUE, TRUE)
16+
('message', 'The text to write to the server logs. It is printed when the page runs.', 'TEXT', TRUE, FALSE),
17+
('level', 'How important the message is. One of ''trace'', ''debug'', ''info'' (default), ''warn'', ''error''. Not case-sensitive. Controls the level shown in the logs.', 'TEXT', TRUE, TRUE)
818
) x;
919

1020
INSERT INTO example(component, description) VALUES
1121
('log', '
12-
### Hello World
22+
### Record a simple message
1323
14-
Log a simple ''Hello, World!'' message on page load.
24+
This writes "Hello, World!" to the server logs.
1525
1626
```sql
17-
SELECT ''log'' as component,
18-
''Hello, World!'' as message
27+
SELECT ''log'' as component, ''Hello, World!'' as message;
1928
```
2029
21-
Output example:
30+
Example output:
2231
23-
```
24-
[2025-09-12T08:33:48.228Z INFO sqlpage::log from file "index.sql" in statement 3] Hello, World!
32+
```text
33+
[2025-09-13T22:30:14.722Z INFO sqlpage::log from "x.sql" statement 1] Hello, World!
2534
```
2635
27-
### Priority
36+
### Set the importance (level)
2837
29-
Change the priority to error.
38+
Choose how important the message is.
3039
3140
```sql
32-
SELECT ''log'' as component,
33-
''This is a error message'' as message,
34-
''error'' as priority
41+
SELECT ''log'' as component, ''error'' as level, ''This is an error message'' as message;
3542
```
3643
37-
Output example:
44+
Example output:
3845
39-
```
40-
[2025-09-12T08:33:48.228Z ERROR sqlpage::log from file "index.sql" in header] This is a error message
46+
```text
47+
[2025-09-13T22:30:14.722Z ERROR sqlpage::log from "x.sql" statement 2] This is an error message
4148
```
4249
43-
### Retrieve user data
50+
### Log dynamic information
4451
45-
```sql
46-
set username = ''user'' -- (retrieve username from somewhere)
52+
Include variables like a username.
4753
48-
select ''log'' as component,
49-
''403 - failed for '' || coalesce($username, ''None'') as output,
50-
''error'' as priority;
51-
```
52-
53-
Output example:
54+
```sql
55+
set username = ''user''
5456
55-
```
56-
[2025-09-12T08:33:48.228Z ERROR sqlpage::log from file "403.sql" in statement 7] 403 - failed for user
57+
select ''log'' as component,
58+
''403 - failed for '' || coalesce($username, ''None'') as message,
59+
''error'' as level;
5760
```
5861
')

0 commit comments

Comments
 (0)