Skip to content

Commit 52c4939

Browse files
committed
Improve rendering of log excerpts
Log excerpts are inconsistently written using quotation or code blocks. When the site is built, the generated markup is different, the former generates a BLOCKQUOTE tag, and the later a PRE tag. Styling of these elements is very different, as code blocks do not wrap lines and quotations wrap lines but also collapse spaces. While it is possible to skip new-line collapsing with some end-of-line spaces, this is error-prone and sometimes missing. As a result, a lot of extracts are not rendered correctly. In order to improve this, introduce a new liquid block `log` that we can use in the markdown documents around log excerpts: ``` {% log %} A very long line that can be larger than the screen of the user. A second very long line that can also be larger that the screen of the user. {% endlog %} ``` This new block transform each new-line character to an explicit BR tag, and wraps the result in a BLOCKQUOTE tag with custom CSS styling. This styling makes it easier to read long/wrapped lines by indenting continuation lines: ``` |<------------ screen width------------->| | A very long line that can be larger | | than the screen of the user. | | A second very long line that can also | | be larger that the screen of the | | user. | ``` Signed-off-by: Romain Tartière <romain@blogreen.org>
1 parent 0b95e36 commit 52c4939

44 files changed

Lines changed: 362 additions & 247 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

_includes/head.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
{% include globals.html %}
1414
{% include skins.html %}
1515

16+
<link rel="stylesheet" href="{{ '/assets/css/log.css' | relative_url}}">
1617
<link rel="preload" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5/css/all.min.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
1718
<noscript><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5/css/all.min.css"></noscript>
1819

_plugins/log.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require "cgi"
2+
3+
# Liquid block to render log excerpts
4+
#
5+
# {% log %}
6+
# New lines are preserved.
7+
# Long lines will be wrapped when displayed on screen.
8+
# {% endlog %}
9+
#
10+
# Will be rendered in the browser to:
11+
#
12+
# |<--------- screen size --------->|
13+
# | New lines are preserved. |
14+
# | Long lines will be wrapped when |
15+
# | displayed on screen. |
16+
class LogBlock < Liquid::Block
17+
def render(context)
18+
output = '<blockquote class="log">'
19+
output << CGI.escapeHTML(super.strip).gsub("\n", "<br/>")
20+
output << "</blockquote>"
21+
output
22+
end
23+
end
24+
25+
Liquid::Template.register_tag("log", LogBlock)

assets/css/log.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
search: false
3+
toc: false
4+
---
5+
6+
@import "minimal-mistakes/variables";
7+
8+
blockquote.log {
9+
text-indent: 2em hanging each-line;
10+
font-family: $monospace;
11+
white-space: pre-wrap;
12+
}

doc/_admin-guide/020_The_concepts_of_syslog-ng/007_The_structure_of_a_log_message/002_EWMM_messages.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ on the receiver side.
2121

2222
The following is a sample log message in EWMM format.
2323

24-
><13>1 2018-05-13T13:27:50.993+00:00 my-host @syslog-ng - - -
25-
>{"MESSAGE":"<34>Oct 11 22:14:15 mymachine su: 'su root' failed for username on
26-
>/dev/pts/8","HOST_FROM":"my-host","HOST":"my-host","FILE_NAME":"/tmp/in","._TAGS":".source.s_file"}
24+
{% log %}
25+
<13>1 2018-05-13T13:27:50.993+00:00 my-host @syslog-ng - - - {"MESSAGE":"<34>Oct 11 22:14:15 mymachine su: 'su root' failed for username on /dev/pts/8","HOST_FROM":"my-host","HOST":"my-host","FILE_NAME":"/tmp/in","._TAGS":".source.s_file"}
26+
{% endlog %}
2727

2828
The message has the following parts:
2929

doc/_admin-guide/040_Quick-start_guide/003_Managing_and_checking_syslog-ng_OSE_service_on_Linux.md

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -71,29 +71,33 @@ To check the status of {{ site.product.short_name }} service
7171

7272
- **active (running)** - {{ site.product.short_name }} service is up and running
7373

74-
Example: {{ site.product.short_name }} service active
75-
76-
> syslog-ng.service - System Logger Daemon
77-
> Loaded: loaded (/lib/systemd/system/syslog-ng.service; enabled; vendor preset: enabled)
78-
> Active: active (running) since Tue 2019-06-25 08:58:09 CEST; 5s ago
79-
> Main PID: 6575 (syslog-ng)
80-
> Tasks: 3
81-
> Memory: 13.3M
82-
> CPU: 268ms
83-
> CGroup: /system.slice/syslog-ng.service
84-
> 6575 /opt/syslog-ng/libexec/syslog-ng -F --no-caps --enable-core
74+
Example: {{ site.product.short_name }} service active
75+
76+
{% log %}
77+
syslog-ng.service - System Logger Daemon
78+
Loaded: loaded (/lib/systemd/system/syslog-ng.service; enabled; vendor preset: enabled)
79+
Active: active (running) since Tue 2019-06-25 08:58:09 CEST; 5s ago
80+
Main PID: 6575 (syslog-ng)
81+
Tasks: 3
82+
Memory: 13.3M
83+
CPU: 268ms
84+
CGroup: /system.slice/syslog-ng.service
85+
6575 /opt/syslog-ng/libexec/syslog-ng -F --no-caps --enable-core
86+
{% endlog %}
8587

8688
- **inactive (dead)** - syslog-ng service is stopped
8789

8890
Example: {{ site.product.short_name }} status inactive
8991

90-
> syslog-ng.service - System Logger Daemon
91-
> Loaded: loaded (/lib/systemd/system/syslog-ng.service; enabled; vendor preset: enabled)
92-
> Active: inactive (dead) since Tue 2019-06-25 09:14:16 CEST; 2min 18s ago
93-
> Process: 6575 ExecStart=/opt/syslog-ng/sbin/syslog-ng -F --no-caps --enable-core $SYSLOGNG_OPTIONS(code=exited, status=0/SUCCESS)
94-
> Main PID: 6575 (code=exited, status=0/SUCCESS)
95-
> Status: "Shutting down... Tue Jun 25 09:14:16 2019"
96-
> Jun 25 09:14:31 as-syslog-srv systemd: Stopped System Logger Daemon.
92+
{% log %}
93+
syslog-ng.service - System Logger Daemon
94+
Loaded: loaded (/lib/systemd/system/syslog-ng.service; enabled; vendor preset: enabled)
95+
Active: inactive (dead) since Tue 2019-06-25 09:14:16 CEST; 2min 18s ago
96+
Process: 6575 ExecStart=/opt/syslog-ng/sbin/syslog-ng -F --no-caps --enable-core $SYSLOGNG_OPTIONS(code=exited, status=0/SUCCESS)
97+
Main PID: 6575 (code=exited, status=0/SUCCESS)
98+
Status: "Shutting down... Tue Jun 25 09:14:16 2019"
99+
Jun 25 09:14:31 as-syslog-srv systemd: Stopped System Logger Daemon.
100+
{% endlog %}
97101

98102
### Checking the process of {{ site.product.short_name }}
99103

@@ -105,19 +109,20 @@ ps u `pidof syslog-ng`
105109

106110
Expected output example:
107111

108-
> USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
109-
>
110-
> syslogng 6709 0.0 0.6 308680 13432 ? Ss 09:17 0:00
111-
> /opt/syslog-ng/libexec/syslog-ng -F --no-caps --enable-core
112+
{% log %}
113+
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
114+
syslogng 6709 0.0 0.6 308680 13432 ? Ss 09:17 0:00 /opt/syslog-ng/libexec/syslog-ng -F --no-caps --enable-core
115+
{% endlog %}
112116

113117
```bash
114118
ps axu | grep syslog-ng | grep -v grep
115119
```
116120

117121
Expected output example:
118122

119-
> syslogng 6709 0.0 0.6 308680 13432 ? Ss 09:17 0:00
120-
> /opt/syslog-ng/libexec/syslog-ng -F --no-caps --enable-core
123+
{% log %}
124+
syslogng 6709 0.0 0.6 308680 13432 ? Ss 09:17 0:00 /opt/syslog-ng/libexec/syslog-ng -F --no-caps --enable-core
125+
{% endlog %}
121126

122127
### Checking the internal logs of {{ site.product.short_name }}**
123128

@@ -154,10 +159,11 @@ If the numbers are changing, {{ site.product.short_name }} is processing the mes
154159

155160
Example: output example
156161

157-
> Every 2.0s: /opt/syslog-ng/sbin/syslog-ng-ctl stats | grep
158-
> ^center Tue Jun 25 10:33:25 2019
159-
> center;;queued;a;processed;112
160-
> center;;received;a;processed;28
162+
{% log %}
163+
Every 2.0s: /opt/syslog-ng/sbin/syslog-ng-ctl stats | grep ^center Tue Jun 25 10:33:25 2019
164+
center;;queued;a;processed;112
165+
center;;received;a;processed;28
166+
{% endlog %}
161167

162168
### Source statistics
163169

@@ -173,11 +179,12 @@ If the numbers are changing, {{ site.product.short_name }} is receiving messages
173179

174180
Example: output example
175181

176-
> Every 2.0s: /opt/syslog-ng/sbin/syslog-ng-ctl stats | grep
177-
> ^source Tue Jun 25 10:40:50 2019
178-
> source;s_null;;a;processed;0
179-
> source;s_net;;a;processed;0
180-
> source;s_local;;a;processed;90
182+
{% log %}
183+
Every 2.0s: /opt/syslog-ng/sbin/syslog-ng-ctl stats | grep ^source Tue Jun 25 10:40:50 2019
184+
source;s_null;;a;processed;0
185+
source;s_net;;a;processed;0
186+
source;s_local;;a;processed;90
187+
{% endlog %}
181188

182189
### Destination statistics
183190

@@ -193,12 +200,13 @@ If the numbers are changing, {{ site.product.short_name }} is receiving messages
193200

194201
Example: output example
195202

196-
> Every 2.0s: /opt/syslog-ng/sbin/syslog-ng-ctl stats | grep
197-
> ^destination Tue Jun 25 10:41:02 2019
198-
> destination;d_logserver2;;a;processed;90
199-
> destination;d_messages;;a;processed;180
200-
> destination;d_logserver;;a;processed;90
201-
> destination;d_null;;a;processed;0
203+
{% log %}
204+
Every 2.0s: /opt/syslog-ng/sbin/syslog-ng-ctl stats | grep ^destination Tue Jun 25 10:41:02 2019
205+
destination;d_logserver2;;a;processed;90
206+
destination;d_messages;;a;processed;180
207+
destination;d_logserver;;a;processed;90
208+
destination;d_null;;a;processed;0
209+
{% endlog %}
202210

203211
**NOTE:** If you find error messages in the internal logs, messages are not
204212
processed by {{ site.product.short_name }} or you encounter any issue, you have the

doc/_admin-guide/060_Sources/070_Network/001_Proxy_protocol_support/000_Proxy_protocol_working_mechanism.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@ macros to every message the comes through the connection later on:
2121

2222
- PROXY_DSTPORT (the destination port of the proxy)
2323

24-
>**NOTE:** Consider the following about macros and headers:
25-
>
24+
>**NOTE:** Consider the following about macros and headers:
25+
>
2626
>- When the proxy protocol header is PROXY UNKNOWN, no additional macros are added.
27-
>
27+
>
2828
>- When {{ site.product.short_name }} cannot parse a proxy protocol header, the connection is closed:
29-
>
30-
> [2020-11-20T17:33:22.189458] PROXY protocol header received; line='PROXYdsfj'
31-
> [2020-11-20T17:33:22.189475] Error parsing PROXY protocol header;
32-
> [2020-11-20T17:33:22.189517] Syslog connection closed; fd='13',
33-
> client='AF_INET(127.0.0.1:51665)', local='AF_INET(0.0.0.0:6666)'
34-
> [2020-11-20T17:33:22.189546] Freeing PROXY protocol source driver; driver='0x7fffcba5bcf0'
29+
>
30+
> {% log %}
31+
> [2020-11-20T17:33:22.189458] PROXY protocol header received; line='PROXYdsfj'
32+
> [2020-11-20T17:33:22.189475] Error parsing PROXY protocol header;
33+
> [2020-11-20T17:33:22.189517] Syslog connection closed; fd='13', client='AF_INET(127.0.0.1:51665)', local='AF_INET(0.0.0.0:6666)'
34+
> [2020-11-20T17:33:22.189546] Freeing PROXY protocol source driver; driver='0x7fffcba5bcf0'
3535
> [2020-11-20T17:33:22.189600] Closing log transport fd; fd='13'
36+
> {% endlog %}
3637
{: .notice--info}
3738

3839
**NOTE:** Since the driver only implements version 1 of the protocol, it

doc/_admin-guide/060_Sources/070_Network/001_Proxy_protocol_support/001_Proxy_protocol_configuration.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,8 @@ the output.
7676
With the PROXY TCP4 192.168.1.1 10.10.0.1 1111 2222 input header, the
7777
output looks like this:
7878

79-
> {"SOURCE":"s_tcp_pp","PROXIED_SRCPORT":"1111","PROXIED_SRCIP":"192.168.1.1",
80-
>"PROXIED_IP_VERSION":"4","PROXIED_DSTPORT":"2222","PROXIED_DSTIP":"10.10.0.1",
81-
>"PROGRAM":"TestMsg","MESSAGE":"","LEGACY_MSGHDR":"TestMsg",
82-
>"HOST_FROM":"localhost","HOST":"localhost"}
79+
{% log %}
80+
{"SOURCE":"s_tcp_pp","PROXIED_SRCPORT":"1111","PROXIED_SRCIP":"192.168.1.1", "PROXIED_IP_VERSION":"4","PROXIED_DSTPORT":"2222","PROXIED_DSTIP":"10.10.0.1", "PROGRAM":"TestMsg","MESSAGE":"","LEGACY_MSGHDR":"TestMsg", "HOST_FROM":"localhost","HOST":"localhost"}
81+
{% endlog %}
8382

8483
Note that the macros that {{ site.product.short_name }} adds to the message appear in the output.

doc/_admin-guide/060_Sources/102_osquery/README.md

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The osquery() source of {{ site.product.short_name }} allows you read the result
1414
periodical osquery queries (from the
1515
/var/log/osquery/osqueryd.results.log file) and automatically parse the
1616
messages (if you want to use {{ site.product.short_name }} to send log messages to
17-
osquery, read this blogpost).
17+
osquery, read this blogpost).
1818

1919
For example, you can:
2020

@@ -100,16 +100,9 @@ the outgoing message will be a well-formed JSON message.
100100

101101
#### Input message
102102

103-
>{"name":"pack_osquery-monitoring_osquery_info","hostIdentifier":"testhost",
104-
>"calendarTime":"Fri Jul 21 10:04:41 2017 >UTC","unixTime":"1500631481",
105-
>"decorations":{"host_uuid":"4C4C4544-004D-3610-8043-C2C04F4D3332",
106-
>"username":"myuser"},>"columns":{"build_distro":"xenial",
107-
>"build_platform":"ubuntu",>"config_hash":"43cd1c6a7d0c283e21e026a53e619b2e582e94ee",
108-
>"config_valid":"1","counter":"4","extensions":"active",
109-
>"instance_id":"d0c3eb0d-f8e0-4bea-868b-18a2c61b438d","pid":"19764",
110-
>"resident_size":"26416000",>"start_time":"1500629552","system_time":"223",
111-
>"user_time":"476","uuid":"4C4C4544-004D-3610-8043-C2C04F4D3332",
112-
>"version":"2.5.0","watcher":"19762"},"action":"added"}
103+
{% log %}
104+
{"name":"pack_osquery-monitoring_osquery_info","hostIdentifier":"testhost", "calendarTime":"Fri Jul 21 10:04:41 2017 >UTC","unixTime":"1500631481", "decorations":{"host_uuid":"4C4C4544-004D-3610-8043-C2C04F4D3332", "username":"myuser"},>"columns":{"build_distro":"xenial", "build_platform":"ubuntu",>"config_hash":"43cd1c6a7d0c283e21e026a53e619b2e582e94ee", "config_valid":"1","counter":"4","extensions":"active", "instance_id":"d0c3eb0d-f8e0-4bea-868b-18a2c61b438d","pid":"19764", "resident_size":"26416000",>"start_time":"1500629552","system_time":"223", "user_time":"476","uuid":"4C4C4544-004D-3610-8043-C2C04F4D3332", "version":"2.5.0","watcher":"19762"},"action":"added"}
105+
{% endlog %}
113106

114107
#### {{ site.product.short_name }} configuration
115108

@@ -138,16 +131,8 @@ log {
138131

139132
#### Outgoing message
140133

141-
>Outgoing message; message='{"_osquery":{"unixTime":"1500631481",
142-
>"name":"pack_osquery-monitoring_osquery_info","hostIdentifier":"testhost",
143-
>"decorations":{"username":"myuser","host_uuid":"4C4C4544-004D-3610-8043-C2C04F4D3332"},
144-
>"columns":{"watcher":"19762","version":"2.5.0","uuid":"4C4C4544-004D-3610-8043-C2C04F4D3332",
145-
>"user_time":"476","system_time":"223","start_time":"1500629552",
146-
>"resident_size":"26416000","pid":"19764","instance_id":"d0c3eb0d-f8e0-4bea-868b-18a2c61b438d",
147-
>"extensions":"active","counter":"4","config_valid":"1",
148-
>"config_hash":"43cd1c6a7d0c283e21e026a53e619b2e582e94ee","build_platform":"ubuntu",
149-
>"build_distro":"xenial"},"calendarTime":"Fri Jul 21 10:04:41 2017 UTC","action":"added"}}\x0a'
134+
> Outgoing message; message='{"_osquery":{"unixTime":"1500631481", "name":"pack_osquery-monitoring_osquery_info","hostIdentifier":"testhost", "decorations":{"username":"myuser","host_uuid":"4C4C4544-004D-3610-8043-C2C04F4D3332"}, "columns":{"watcher":"19762","version":"2.5.0","uuid":"4C4C4544-004D-3610-8043-C2C04F4D3332", "user_time":"476","system_time":"223","start_time":"1500629552", "resident_size":"26416000","pid":"19764","instance_id":"d0c3eb0d-f8e0-4bea-868b-18a2c61b438d", "extensions":"active","counter":"4","config_valid":"1", "config_hash":"43cd1c6a7d0c283e21e026a53e619b2e582e94ee","build_platform":"ubuntu", "build_distro":"xenial"},"calendarTime":"Fri Jul 21 10:04:41 2017 UTC","action":"added"}}\x0a'
150135
151136
To configure a destination to send the log messages to Elasticsearch,
152-
see elasticsearch-http: Sending messages to Elasticsearch HTTP Bulk API.
137+
see elasticsearch-http: Sending messages to Elasticsearch HTTP Bulk API.
153138
For other destinations, see destination: Forward, send, and store log messages.

doc/_admin-guide/060_Sources/140_Python/001_Python_logmessage_API.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ set in the message, and uses the IP address of the {{ site.product.short_name }}
6464
the hostname (to use the hostname instead of the IP address, set the
6565
use-dns() or use-fqdn() options in the Python source).
6666

67-
>msg_ietf = LogMessage.parse('<165>1 2003-10-11T22:14:15.003Z mymachine.example.com
68-
>evntslog - ID47 [exampleSDID@32473 iut="3" eventSource="Application" eventID="1011"]
69-
>An application event log entry', self.parse_options)
70-
>msg_bsd = LogMessage.parse('<34>Oct 11 22:14:15 mymachine su: \'su root\' failed for
71-
>lonvick on /dev/pts/8', self.parse_options)
67+
```python
68+
msg_ietf = LogMessage.parse('<165>1 2003-10-11T22:14:15.003Z mymachine.example.com \
69+
evntslog - ID47 [exampleSDID@32473 iut="3" eventSource="Application" eventID="1011"] \
70+
An application event log entry', self.parse_options)
71+
msg_bsd = LogMessage.parse('<34>Oct 11 22:14:15 mymachine su: \'su root\' failed for \
72+
lonvick on /dev/pts/8', self.parse_options)
73+
```
7274

7375
## set_pri() method
7476

doc/_admin-guide/060_Sources/155_stdin/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ used to collect a test message:
3535
$ echo "this is a test message" | ./syslog-ng -Fe --no-caps
3636
```
3737

38-
> [2017-11-14T13:47:16.757938] syslog-ng starting up; version='3.12.1'
39-
> [2017-11-14T13:47:16.758195] syslog-ng shutting down; version='3.12.1'
40-
> Nov 14 13:47:16 testserver this is a test message
38+
{% log %}
39+
[2017-11-14T13:47:16.757938] syslog-ng starting up; version='3.12.1'
40+
[2017-11-14T13:47:16.758195] syslog-ng shutting down; version='3.12.1'
41+
Nov 14 13:47:16 testserver this is a test message
42+
{% endlog %}

0 commit comments

Comments
 (0)