Skip to content

Commit 7f9ffc6

Browse files
authored
Add support for nginx and apache logs (#31)
1 parent d0a6cb6 commit 7f9ffc6

28 files changed

+743
-45
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ read logs from any directory.
1919

2020
### Features
2121

22-
- 📂 **View all the Monolog logs** in your `%kernel.logs_dir%` directory,
22+
- 📂 **View all the Monolog, Apache2 or Nginx logs** in specified directories,
2323
- 🔍 **Search** the logs,
2424
- 🎚 **Filter** by log level (error, info, debug, etc.), by channel, date range or log content,
2525
- 🌑 **Dark mode**,
@@ -74,15 +74,15 @@ php bin/console assets:install
7474

7575
Once the installation is complete, you will be able to access **Log Viewer** directly in your browser.
7676

77-
By default, the application is available at: `{APP_URL}/log-viewer`.
78-
79-
(for example: `https://my-app.test/log-viewer`)
77+
By default, it is available at: `/log-viewer` on your domain.
8078

8179
## Configuration
8280
- [Adding more monolog directories](docs/adding-more-monolog-directories.md)
8381
- [Modifying monolog configuration](docs/modifying-monolog-configuration.md)
8482
- [Disabling the default monolog configuration](docs/disabling-default-monolog-configuration.md)
8583
- [Adding additional log files](docs/adding-additional-log-files.md)
84+
- [Adding apache logs](docs/configuring-apache-logs.md)
85+
- [Adding nginx logs](docs/configuring-nginx-logs.md)
8686
- [Configuring the back home url](docs/configuring-the-back-home-route.md)
87-
- [Advanced search queries](docs/search-queries.md)
87+
- [Advanced search queries](docs/advanced-search-queries.md)
8888
- [Full configuration reference](docs/configuration-reference.md)

dev/compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ version: '3'
22

33
services:
44
nginx:
5+
container_name: log-viewer-nginx
56
image: nginx:stable-alpine
67
ports:
78
- ${NGINX_PORT:-8888}:80
89
volumes:
910
- ../.:/app:rw
1011
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
12+
- log-viewer-log:/var/log/nginx:rw
1113

1214
php-fpm:
1315
container_name: log-viewer-php

dev/config/config.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,19 @@ fd_log_viewer:
5252
monolog:
5353
downloadable: true
5454
deletable: true
55+
nginx-access:
56+
type: nginx-access
57+
name: Nginx access
58+
finder:
59+
in: "/var/log/nginx"
60+
name: "nginx.access.log"
61+
downloadable: true
62+
deletable: true
63+
nginx-error:
64+
type: nginx-error
65+
name: Nginx error
66+
finder:
67+
in: "/var/log/nginx"
68+
name: "nginx.error.log"
69+
downloadable: true
70+
deletable: true

dev/docker/nodejs/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22
set -e
33

4-
npm install --no-save
4+
npm install --no-save --no-update-notifier --no-fund --no-audit
55
node node_modules/vite/bin/vite.js build -w --mode development

docs/configuration-reference.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,13 @@ This entry allows you to add more log file directories to the Log Viewer. Each e
5252

5353
### log_files.type
5454

55-
**type**: `string` (`enum: monolog`)
55+
**type**: `string` (`enum: monolog|http-access|apache-error|nginx-error`)
5656

57-
This is the type of log file that will be read. Currently only `monolog` is supported.
57+
This is the type of log file that will be read.
58+
- `monolog` is the default type and will read the default monolog log files.
59+
- `http-access` will read the access log files of Apache and Nginx.
60+
- `apache-error` will read the error log files of Apache.
61+
- `nginx-error` will read the error log files of Nginx.
5862
<br><br>
5963

6064
### log_files.name
@@ -142,7 +146,7 @@ Should the log folders and files be deletable.
142146

143147
**type**: `string|null`.
144148

145-
As log files can contain multiple lines per log entry, this pattern is used to find the start of a log entry. Any lines not matching
149+
As certain log files can contain multiple lines per log entry, this pattern is used to find the start of a log entry. Any lines not matching
146150
the pattern will be appended to the line before.
147151
The default monolog regex pattern is `/^\[\d{4}-\d{2}-\d{2}[^]]*]\s+\S+\.\S+:/` and matches:
148152

docs/configuring-apache-logs.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Configuring Apache2 logs
2+
3+
To add apache2 logs to the Log Viewer, add the following to your `config/packages/fd_log_viewer.yaml` file:
4+
5+
```yaml
6+
fd_log_viewer:
7+
log_files:
8+
apache-access:
9+
type: http-access
10+
name: Apache2 access
11+
finder:
12+
in: "/var/log/apache2"
13+
name: "access.log"
14+
apache-error:
15+
type: apache-error
16+
name: Apache2 error
17+
finder:
18+
in: "/var/log/apache2"
19+
name: "error.log"
20+
```
21+
22+
## Access logs
23+
24+
The `log_message_pattern`-regex that is used for the **access logs** is:
25+
26+
```regex
27+
/(?P<ip>\S+) (?P<identity>\S+) (?P<remote_user>\S+) \[(?P<date>[^\]]+)\] "(?P<method>\S+) (?P<path>\S+) (?P<http_version>\S+)" (?P<status_code>\S+) (?P<content_length>\S+) "(?P<referrer>[^"]*)" "(?P<user_agent>[^"]*)"/
28+
```
29+
30+
The fields `date`, `method` and `path` are mandatory. The other fields are optional.
31+
32+
## Error logs
33+
34+
The `log_message_pattern`-regex that is used for the **error logs** is:
35+
36+
```regex
37+
/^\[(?<date>.*?)\] \[(?:(?<module>.*?):)?(?<severity>.*?)\] \[pid\s(?<pid>\d*)\](?: (?<error_status>[^\]]*?))?(?: \[client (?<ip>.*):(?<port>\d+)\]) (?<message>.*?)(?:, referer: (?<referer>\S*?))?$/
38+
```
39+
40+
The fields `date`, `severity`, and `message` are mandatory. The other fields are optional.

docs/configuring-nginx-logs.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Configuring Nginx logs
2+
3+
To add nginx logs to the Log Viewer, add the following to your `config/packages/fd_log_viewer.yaml` file:
4+
5+
```yaml
6+
fd_log_viewer:
7+
log_files:
8+
nginx-access:
9+
type: http-access
10+
name: Nginx access
11+
finder:
12+
in: "/var/log/nginx"
13+
name: "nginx.access.log"
14+
nginx-error:
15+
type: nginx-error
16+
name: Nginx error
17+
finder:
18+
in: "/var/log/nginx"
19+
name: "nginx.error.log"
20+
```
21+
22+
## Access logs
23+
24+
The `log_message_pattern`-regex that is used for the **access logs** is:
25+
26+
```regex
27+
/(?P<ip>\S+) (?P<identity>\S+) (?P<remote_user>\S+) \[(?P<date>[^\]]+)\] "(?P<method>\S+) (?P<path>\S+) (?P<http_version>\S+)" (?P<status_code>\S+) (?P<content_length>\S+) "(?P<referrer>[^"]*)" "(?P<user_agent>[^"]*)"/
28+
```
29+
30+
The fields `date`, `method` and `path` are mandatory. The other fields are optional.
31+
32+
## Error logs
33+
34+
The `log_message_pattern`-regex that is used for the **error logs** is:
35+
36+
```regex
37+
/^(?P<date>[\d+/ :]+) \[(?P<severity>.+)] .*?: (?P<message>.+?)(?:, client: (?P<ip>.+?))?(?:, server: (?P<server>.*?))?(?:, request: "?(?P<request>.+?)"?)?(?:, upstream: "?(?P<upstream>.+?)"?)?(?:, host: "?(?P<host>.+?)"?)?$/
38+
```
39+
40+
The fields `date`, `severity`, and `message` are mandatory. The other fields are optional.

frontend/src/components/FileTree.vue

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
import LogFolder from '@/components/LogFolder.vue';
33
import bus from '@/services/EventBus';
44
import {useFolderStore} from '@/stores/folders';
5-
import {ref} from 'vue'
65
7-
const selectedFolder = ref(0);
8-
const folderStore = useFolderStore();
6+
const folderStore = useFolderStore();
97
108
bus.on('file-deleted', () => folderStore.update());
119
bus.on('folder-deleted', () => folderStore.update());
@@ -15,9 +13,7 @@ bus.on('folder-deleted', () => folderStore.update());
1513
<!-- FileTree -->
1614
<div class="p-1 pe-2 overflow-auto">
1715
<div class="slv-control-layout m-0">
18-
<div>
19-
<!-- Host: Local-->
20-
</div>
16+
<div><!-- Host: Local --></div>
2117
<div></div>
2218
<div>
2319
<select class="form-control p-0 border-0" v-model="folderStore.direction" v-on:change="folderStore.update">
@@ -28,11 +24,7 @@ bus.on('folder-deleted', () => folderStore.update());
2824
</div>
2925

3026
<div class="slv-loadable" v-bind:class="{ 'slv-loading': folderStore.loading }">
31-
<log-folder :folder="folder"
32-
:expanded="index === selectedFolder"
33-
:key="index"
34-
v-for="(folder, index) in folderStore.folders"
35-
@expand="selectedFolder = index"/>
27+
<log-folder :folder="folder" :expand="true" :key="index" v-for="(folder, index) in folderStore.folders"/>
3628
</div>
3729
</div>
3830
</template>

frontend/src/components/LogFolder.vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
<script setup lang="ts">
2-
import LogFile from '@/components/LogFile.vue';
32
import ButtonGroup from '@/components/ButtonGroup.vue';
3+
import LogFile from '@/components/LogFile.vue';
44
import type LogFolder from '@/models/LogFolder';
55
import bus from '@/services/EventBus';
66
import axios from 'axios';
7-
import {ref} from 'vue';
7+
import {onMounted, ref} from 'vue';
88
import {useRouter} from 'vue-router';
99
1010
const toggleRef = ref();
1111
const baseUri = axios.defaults.baseURL;
1212
const router = useRouter();
13+
const expanded = ref(false);
1314
14-
defineProps<{
15-
expanded: boolean,
15+
const props = defineProps<{
16+
expand: boolean,
1617
folder: LogFolder
1718
}>()
1819
@@ -24,14 +25,16 @@ const deleteFile = (identifier: string) => {
2425
});
2526
}
2627
28+
onMounted(() => expanded.value = props.expand);
29+
2730
</script>
2831

2932
<template>
3033
<!-- LogFolder -->
3134
<div class="folder-group mt-1" :aria-expanded="expanded">
3235
<button-group ref="toggleRef" alignment="right" :split="folder.can_download || folder.can_delete" :hide-on-selected="true">
3336
<template v-slot:btn_left>
34-
<button type="button" class="btn btn-outline-primary text-start w-100" @click="$emit('expand')">
37+
<button type="button" class="btn btn-outline-primary text-start w-100" @click="expanded = !expanded">
3538
<i class="slv-indicator bi bi-chevron-right me-2"></i>
3639
<span class="text-nowrap">{{ folder.path }}</span>
3740
</button>

frontend/src/components/LogRecord.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ defineProps<{
1414
<div class="slv-list-link" :class="{ 'text-nowrap': !expanded, 'overflow-hidden': !expanded }" @click="expanded = !expanded">
1515
<i class="slv-indicator bi bi-chevron-right me-1"></i>
1616
<span class="pe-2 text-secondary">{{ logRecord.datetime }}</span>
17-
<span class="text-primary pe-2">{{ logRecord.channel }}</span>
17+
<span class="text-primary pe-2" v-if="logRecord.channel.length > 0">{{ logRecord.channel }}</span>
1818
<span :class="['pe-2', logRecord.level_class ]">{{ logRecord.level_name }}</span>
1919
<span>{{ logRecord.text }}</span>
2020
</div>

0 commit comments

Comments
 (0)