Skip to content

Commit 0fb5442

Browse files
authored
When expanding log record, preserve newlines (#282)
1 parent 17cc0c0 commit 0fb5442

File tree

7 files changed

+32
-19
lines changed

7 files changed

+32
-19
lines changed

dev/config/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ monolog:
5454
error:
5555
type: stream
5656
path: "%kernel.logs_dir%/error.log"
57+
include_stacktraces: true
5758
level: error
5859
channels: [ "!event", "!deprecation" ]
5960
deprecation:

frontend/src/components/LogRecord.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script setup lang="ts">
22
import JsonData from '@/components/json/JsonData.vue';
3+
import {nl2br, escapeHtml} from '@/services/Strings.ts';
34
import type LogRecord from '@/models/LogRecord';
45
import {isEmptyJson, prettyFormatJson} from '@/services/JsonFormatter';
56
import {ref} from 'vue';
@@ -23,7 +24,10 @@ function click(value: string) {
2324
<span class="pe-2 text-secondary">{{ logRecord.datetime }}</span>
2425
<span class="text-primary pe-2" v-if="logRecord.channel.length > 0">{{ logRecord.channel }}</span>
2526
<span :class="['pe-2', logRecord.level_class ]">{{ logRecord.level_name }}</span>
26-
<span>{{ logRecord.text }}</span>
27+
28+
<!-- log message -->
29+
<span v-if="!expanded" v-text="logRecord.text.substring(0, 500)"></span>
30+
<span v-if="expanded" v-html="nl2br(escapeHtml(logRecord.text))"></span>
2731
</div>
2832
<div class="border-top pt-2 ps-2 mb-2 position-relative" v-bind:class="{'d-block': expanded, 'd-none': !expanded}" v-if="expanded">
2933
<button class="btn btn-outline-secondary slv-btn-raw" @click="styled = !styled">{{ styled ? 'raw' : 'styled' }}</button>

frontend/src/components/json/JsonScalarValue.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<script setup lang="ts">
22
import Numbers from '@/services/Numbers.ts';
3-
import Strings from '@/services/Strings.ts';
3+
import {trim} from '@/services/Strings.ts';
44
55
const props = defineProps<{ path: string, data: unknown }>();
66
const emit = defineEmits(['click']);
77
88
function click(value: unknown) {
9-
emit('click', `${Strings.trim(props.path, '.')}="${value}"`);
9+
emit('click', `${trim(props.path, '.')}="${value}"`);
1010
}
1111
</script>
1212

frontend/src/services/Strings.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
export default class Strings {
1+
export function trim(str: string, toRemove: string): string {
2+
while (str.startsWith(toRemove)) {
3+
str = str.substring(toRemove.length);
4+
}
5+
while (str.endsWith(toRemove)) {
6+
str = str.substring(0, str.length - toRemove.length);
7+
}
8+
9+
return str;
10+
}
211

3-
public static trim(str: string, toRemove: string): string {
4-
while (str.startsWith(toRemove)) {
5-
str = str.substring(toRemove.length);
6-
}
7-
while (str.endsWith(toRemove)) {
8-
str = str.substring(0, str.length - toRemove.length);
9-
}
12+
export function nl2br(str: string): string {
13+
return str.replace(/\n/g, '<br/>');
14+
}
1015

11-
return str;
12-
}
16+
export function escapeHtml(str: string): string {
17+
return str
18+
.replace(/&/g, '&amp;')
19+
.replace(/</g, '&lt;')
20+
.replace(/>/g, '&gt;')
1321
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"src/main.ts": {
3-
"file": "assets/main-CF_yt7iQ.js",
3+
"file": "assets/main-C_BrajeJ.js",
44
"name": "main",
55
"src": "src/main.ts",
66
"isEntry": true
77
},
88
"style.css": {
9-
"file": "assets/style-CcMiSAP_.css",
9+
"file": "assets/style-J8MU6gDa.css",
1010
"src": "style.css"
1111
}
1212
}

src/Resources/public/assets/main-CF_yt7iQ.js renamed to src/Resources/public/assets/main-C_BrajeJ.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Resources/public/assets/style-CcMiSAP_.css renamed to src/Resources/public/assets/style-J8MU6gDa.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)