admin/options: "Don't log address"
Massimo Melina committed
Apr 10, 2023 at 20:13 UTC
58ad85b51c71e52f4129770e071a59f60cab1018
4 files changed
+12
-4
admin/src/OptionsPage.ts
+8
-3
@@ -125,9 +125,14 @@ export default function OptionsPage() {
125
{ k: 'favicon', comp: FileField, placeholder: "None", fileMask: '*.png|*.ico|*.jpg|*.jpeg|*.gif|*.svg',
126
helperText: "The icon associated to your website" },
127
{ k: 'log', label: logLabels.log, md: 3, helperText: "Requests are logged here" },
128
- { k: 'error_log', label: logLabels.error_log, md: 3, placeholder: "errors go to main log", helperText: "If you want errors in a different log" },
129
- { k: 'log_rotation', comp: SelectField, options: [{ value:'', label:"disabled" }, 'daily', 'weekly', 'monthly' ],
130
- helperText: "To avoid an endlessly-growing single log file"
128
+ { k: 'error_log', label: logLabels.error_log, md: 3, placeholder: "errors go to main log",
129
+ helperText: "If you want errors in a different log"
130
+ },
131
+ { k: 'log_rotation', comp: SelectField, md: 3, options: [{ value:'', label:"disabled" }, 'daily', 'weekly', 'monthly' ],
132
+ helperText: "To keep log-files smaller"
133
+ },
134
+ { k: 'dont_log_net', comp: NetmaskField, label: "Don't log address", md: 3, placeholder: "no exception",
135
+ helperText: h(WildcardsSupported)
136
},
137
{ k: 'proxies', comp: NumberField, min: 0, max: 9, sm: 6, label: "How many HTTP proxies between this server and users?",
138
error: proxyWarning(values, status),
config.md
+1
@@ -7,6 +7,7 @@ This file contains details the configuration files.
7
- `log_rotation` frequency of log rotation. Accepted values are `daily`, `weekly`, `monthly`, or empty string to disable. Default is `weekly`.
8
- `error_log` path of the log file for errors. Default is `error.log`.
9
- `errors_in_main_log` if you want to use a single file for both kind of entries. Default is false.
10
+- `dont_log_net` don't include in log entries if IP matches this network mask. Default is `127.0.0.1|::1`.
11
- `accounts` list of accounts. For details see the dedicated following section.
12
- `mime` command what mime-type to be returned with some files.
13
E.g.: `"*.jpg": image/jpeg`
src/log.ts
+3
@@ -11,6 +11,7 @@ import events from './events'
11
import _ from 'lodash'
12
import { prepareFolder } from './util-files'
13
import { getCurrentUsername } from './perm'
14
+import { makeNetMatcher } from './misc'
15
16
class Logger {
17
stream?: Writable
@@ -60,6 +61,7 @@ errorLogFile.sub(path => {
61
})
62
63
const logRotation = defineConfig('log_rotation', 'weekly')
64
+const dontLogNet = defineConfig('dont_log_net', '127.0.0.1|::1', makeNetMatcher)
65
66
export function log(): Koa.Middleware {
67
const debounce = _.debounce(cb => cb(), 1000)
@@ -68,6 +70,7 @@ export function log(): Koa.Middleware {
70
await next()
71
console.debug(ctx.status, ctx.method, ctx.path)
72
Promise.race([ once(ctx.res, 'finish'), once(ctx.res, 'close') ]).then(() => {
73
+ if (dontLogNet.compiled()(ctx.ip)) return
74
const isError = ctx.status >= 400
75
const logger = isError && accessErrorLog || accessLogger
76
const rotate = logRotation.get()?.[0]
todo.md
-1
@@ -1,5 +1,4 @@
1
# To do
2
-- log filter option (skip localhost by default)
2
- blacklist of plugins (as a temporary measure until GitHub's intervention)
3
- admin: warn in case of items with same name
4
- frontend search supporting masks