chore: per-domain logging

pull/399/head
Kobi Meirson 2022-10-17 15:03:24 +03:00
parent f44832ed7a
commit 8e2d5436f7
No known key found for this signature in database
GPG Key ID: 5D66F732B037CDE1
5 changed files with 70 additions and 15 deletions

View File

@ -107,8 +107,19 @@ export default (domains, global) => {
} }
config.http.push(['# Logging', '']); config.http.push(['# Logging', '']);
config.http.push(['access_log', (global.logging.accessLog.computed.trim() + (global.logging.cloudflare.computed ? ' cloudflare' : '')) || 'off']); if (global.logging.accessLog.computed) {
config.http.push(['error_log', global.logging.errorLog.computed.trim() || '/dev/null']); config.http.push(['access_log', global.logging.accessLogPath.computed.trim() +
(global.logging.cloudflare.computed ? ' cloudflare' : '') +
(global.logging.accessLogArguments.computed ? ` ${global.logging.accessLogArguments.computed.trim()}` : '')
]);
} else {
config.http.push(['access_log', 'off']);
}
if (global.logging.errorLog.computed) {
config.http.push(['error_log', global.logging.errorLogPath.computed.trim()]);
} else {
config.http.push(['error_log', '/dev/null']);
}
if (global.security.limitReq.computed) { if (global.security.limitReq.computed) {
config.http.push(['# Limits', '']); config.http.push(['# Limits', '']);

View File

@ -226,7 +226,10 @@ export default (domain, domains, global, ipPortPairs) => {
if (domain.logging.accessLog.computed) if (domain.logging.accessLog.computed)
serverConfig.push(['access_log', serverConfig.push(['access_log',
getAccessLogDomainPath(domain, global) + (global.logging.cloudflare.computed ? ' cloudflare' : '')]); getAccessLogDomainPath(domain, global) +
(global.logging.cloudflare.computed ? ' cloudflare' : '') +
(global.logging.accessLogArguments.computed ? ` ${global.logging.accessLogArguments.computed.trim()}`: '')
]);
if (domain.logging.errorLog.computed) if (domain.logging.errorLog.computed)
serverConfig.push(['error_log', getErrorLogDomainPath(domain, global)]); serverConfig.push(['error_log', getErrorLogDomainPath(domain, global)]);
@ -369,9 +372,6 @@ export default (domain, domains, global, ipPortPairs) => {
// HTTPS // HTTPS
cdnConfig.push(...sslConfig(domain, global)); cdnConfig.push(...sslConfig(domain, global));
cdnConfig.push(['# disable access_log', '']);
cdnConfig.push(['access_log', 'off']);
// Gzip // Gzip
if (global.performance.gzipCompression.computed) { if (global.performance.gzipCompression.computed) {
cdnConfig.push(['# gzip', '']); cdnConfig.push(['# gzip', '']);

View File

@ -69,11 +69,11 @@ THE SOFTWARE.
const defaults = { const defaults = {
accessLog: { accessLog: {
default: false, default: true,
enabled: true, enabled: true,
}, },
errorLog: { errorLog: {
default: false, default: true,
enabled: true, enabled: true,
}, },
}; };

View File

@ -33,11 +33,36 @@ THE SOFTWARE.
<div class="field-body"> <div class="field-body">
<div class="field"> <div class="field">
<div :class="`control${accessLogChanged ? ' is-changed' : ''}`"> <div :class="`control${accessLogChanged ? ' is-changed' : ''}`">
<div class="checkbox">
<PrettyCheck v-model="accessLog" class="p-default p-curve p-fill p-icon">
{{ $t('common.enable') }}
</PrettyCheck>
</div>
</div>
<div v-if="$props.data.accessLog.computed" class="control field is-horizontal is-expanded">
<input <input
v-model="accessLog" v-model="accessLogPath"
class="input" class="input"
type="text" type="text"
:placeholder="$props.data.accessLog.default" :placeholder="$props.data.accessLogPath.default"
/>
</div>
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label">
<label class="label">access_log arguments</label>
</div>
<div class="field-body">
<div class="field">
<div :class="`control${accessLogArgumentsChanged ? ' is-changed' : ''}`">
<input
v-model="accessLogArguments"
class="input"
type="text"
:placeholder="$props.data.accessLogArguments.default"
/> />
</div> </div>
</div> </div>
@ -51,11 +76,18 @@ THE SOFTWARE.
<div class="field-body"> <div class="field-body">
<div class="field"> <div class="field">
<div :class="`control${errorLogChanged ? ' is-changed' : ''}`"> <div :class="`control${errorLogChanged ? ' is-changed' : ''}`">
<div class="checkbox">
<PrettyCheck v-model="errorLog" class="p-default p-curve p-fill p-icon">
{{ $t('common.enable') }}
</PrettyCheck>
</div>
</div>
<div v-if="$props.data.errorLog.computed" class="control field is-horizontal is-expanded">
<input <input
v-model="errorLog" v-model="errorLogPath"
class="input" class="input"
type="text" type="text"
:placeholder="$props.data.errorLog.default" :placeholder="$props.data.errorLogPath.default"
/> />
</div> </div>
</div> </div>
@ -161,10 +193,22 @@ THE SOFTWARE.
const defaults = { const defaults = {
accessLog: { accessLog: {
default: false,
enabled: true,
},
accessLogPath: {
default: '/var/log/nginx/access.log', default: '/var/log/nginx/access.log',
enabled: true, enabled: true,
}, },
accessLogArguments: {
default: 'buffer=512k flush=1m',
enabled: true,
},
errorLog: { errorLog: {
default: false,
enabled: true,
},
errorLogPath: {
default: '/var/log/nginx/error.log warn', default: '/var/log/nginx/error.log warn',
enabled: true, enabled: true,
}, },
@ -263,7 +307,7 @@ THE SOFTWARE.
} }
}, },
deep: true, deep: true,
}, }
}, },
}; };
</script> </script>

View File

@ -25,9 +25,9 @@ THE SOFTWARE.
*/ */
export const getAccessLogDomainPath = (domain, global) => { export const getAccessLogDomainPath = (domain, global) => {
return global.logging.accessLog.computed.replace(/([^/]+)\.log$/, `${domain.server.domain.computed}.$1.log`); return global.logging.accessLogPath.computed.replace(/([^/]+)\.log$/, `${domain.server.domain.computed}.$1.log`);
}; };
export const getErrorLogDomainPath = (domain, global) => { export const getErrorLogDomainPath = (domain, global) => {
return global.logging.errorLog.computed.replace(/([^/]+)\.log (.+)$/, `${domain.server.domain.computed}.$1.log $2`); return global.logging.errorLogPath.computed.replace(/([^/]+)\.log (.+)$/, `${domain.server.domain.computed}.$1.log $2`);
}; };