feat: migrate old logging to new
parent
b4fef1ab39
commit
e02f20d993
|
@ -227,6 +227,7 @@ THE SOFTWARE.
|
||||||
import ExternalLink from 'do-vue/src/templates/external_link';
|
import ExternalLink from 'do-vue/src/templates/external_link';
|
||||||
import delegatedFromDefaults from '../../util/delegated_from_defaults';
|
import delegatedFromDefaults from '../../util/delegated_from_defaults';
|
||||||
import computedFromDefaults from '../../util/computed_from_defaults';
|
import computedFromDefaults from '../../util/computed_from_defaults';
|
||||||
|
import { serverDomainDefault } from '../../util/defaults';
|
||||||
import PrettyCheck from '../inputs/checkbox';
|
import PrettyCheck from '../inputs/checkbox';
|
||||||
import PrettyRadio from '../inputs/radio';
|
import PrettyRadio from '../inputs/radio';
|
||||||
|
|
||||||
|
@ -269,7 +270,7 @@ THE SOFTWARE.
|
||||||
},
|
},
|
||||||
letsEncryptEmail: {
|
letsEncryptEmail: {
|
||||||
default: '',
|
default: '',
|
||||||
computed: 'info@example.com', // No default value, but a default computed
|
computed: `info@${serverDomainDefault}`, // No default value, but a default computed
|
||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
sslCertificate: {
|
sslCertificate: {
|
||||||
|
|
|
@ -44,7 +44,7 @@ THE SOFTWARE.
|
||||||
v-model="accessLogPath"
|
v-model="accessLogPath"
|
||||||
class="input"
|
class="input"
|
||||||
type="text"
|
type="text"
|
||||||
:placeholder="`/var/log/nginx/${$parent.$props.data.server.domain.computed}.access.log`"
|
:placeholder="$props.data.accessLogPath.default"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -86,7 +86,7 @@ THE SOFTWARE.
|
||||||
v-model="errorLogPath"
|
v-model="errorLogPath"
|
||||||
class="input"
|
class="input"
|
||||||
type="text"
|
type="text"
|
||||||
:placeholder="`/var/log/nginx/${$parent.$props.data.server.domain.computed}.error.log`"
|
:placeholder="$props.data.errorLogPath.default"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -119,7 +119,7 @@ THE SOFTWARE.
|
||||||
<script>
|
<script>
|
||||||
import delegatedFromDefaults from '../../util/delegated_from_defaults';
|
import delegatedFromDefaults from '../../util/delegated_from_defaults';
|
||||||
import computedFromDefaults from '../../util/computed_from_defaults';
|
import computedFromDefaults from '../../util/computed_from_defaults';
|
||||||
import { accessLogParamsDefault, errorLogLevelDefault, errorLogLevelOptions } from '../../util/logging';
|
import { accessLogPathDefault, accessLogParamsDefault, errorLogPathDefault, errorLogLevelDefault, errorLogLevelOptions } from '../../util/logging';
|
||||||
import PrettyCheck from '../inputs/checkbox';
|
import PrettyCheck from '../inputs/checkbox';
|
||||||
import PrettyRadio from '../inputs/radio';
|
import PrettyRadio from '../inputs/radio';
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ THE SOFTWARE.
|
||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
accessLogPath: {
|
accessLogPath: {
|
||||||
default: '',
|
default: accessLogPathDefault,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
accessLogParameters: {
|
accessLogParameters: {
|
||||||
|
@ -141,7 +141,7 @@ THE SOFTWARE.
|
||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
errorLogPath: {
|
errorLogPath: {
|
||||||
default: '',
|
default: errorLogPathDefault,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
errorLogLevel: {
|
errorLogLevel: {
|
||||||
|
@ -164,18 +164,5 @@ THE SOFTWARE.
|
||||||
data: Object, // Data delegated back to us from parent
|
data: Object, // Data delegated back to us from parent
|
||||||
},
|
},
|
||||||
computed: computedFromDefaults(defaults, 'logging'), // Getters & setters for the delegated data
|
computed: computedFromDefaults(defaults, 'logging'), // Getters & setters for the delegated data
|
||||||
watch: {
|
|
||||||
'$parent.$props.data.server.domain': {
|
|
||||||
handler(data) {
|
|
||||||
if (!this.$props.data.accessLogPath.value.trim()) {
|
|
||||||
this.$props.data.accessLogPath.computed = `/var/log/nginx/${data.computed}.access.log`;
|
|
||||||
}
|
|
||||||
if (!this.$props.data.errorLogPath.value.trim()) {
|
|
||||||
this.$props.data.errorLogPath.computed = `/var/log/nginx/${data.computed}.error.log`;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
deep: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -147,16 +147,17 @@ THE SOFTWARE.
|
||||||
<script>
|
<script>
|
||||||
import delegatedFromDefaults from '../../util/delegated_from_defaults';
|
import delegatedFromDefaults from '../../util/delegated_from_defaults';
|
||||||
import computedFromDefaults from '../../util/computed_from_defaults';
|
import computedFromDefaults from '../../util/computed_from_defaults';
|
||||||
|
import { serverDomainDefault } from '../../util/defaults';
|
||||||
import PrettyCheck from '../inputs/checkbox';
|
import PrettyCheck from '../inputs/checkbox';
|
||||||
|
|
||||||
const defaults = {
|
const defaults = {
|
||||||
domain: {
|
domain: {
|
||||||
default: 'example.com',
|
default: serverDomainDefault,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
path: {
|
path: {
|
||||||
default: '',
|
default: '',
|
||||||
computed: '/var/www/example.com', // No default value, but a default computed
|
computed: `/var/www/${serverDomainDefault}`, // No default value, but a default computed
|
||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
documentRoot: {
|
documentRoot: {
|
||||||
|
|
|
@ -166,7 +166,7 @@ THE SOFTWARE.
|
||||||
<script>
|
<script>
|
||||||
import delegatedFromDefaults from '../../util/delegated_from_defaults';
|
import delegatedFromDefaults from '../../util/delegated_from_defaults';
|
||||||
import computedFromDefaults from '../../util/computed_from_defaults';
|
import computedFromDefaults from '../../util/computed_from_defaults';
|
||||||
import { errorLogLevelDefault, errorLogLevelOptions } from '../../util/logging';
|
import { errorLogPathDefault, errorLogLevelDefault, errorLogLevelOptions } from '../../util/logging';
|
||||||
import PrettyCheck from '../inputs/checkbox';
|
import PrettyCheck from '../inputs/checkbox';
|
||||||
import PrettyRadio from '../inputs/radio';
|
import PrettyRadio from '../inputs/radio';
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ THE SOFTWARE.
|
||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
errorLogPath: {
|
errorLogPath: {
|
||||||
default: '/var/log/nginx/error.log',
|
default: errorLogPathDefault,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
errorLogLevel: {
|
errorLogLevel: {
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
Copyright 2022 DigitalOcean
|
||||||
|
|
||||||
|
This code is licensed under the MIT License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
https://github.com/digitalocean/nginxconfig.io/blob/master/LICENSE or https://mit-license.org/
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions :
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const serverDomainDefault = 'example.com';
|
|
@ -43,7 +43,9 @@ export const getDomainErrorLog = (domain) => {
|
||||||
return `${path} ${domain.logging.errorLogLevel.computed}`;
|
return `${path} ${domain.logging.errorLogLevel.computed}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const accessLogPathDefault = '/var/log/nginx/access.log';
|
||||||
export const accessLogParamsDefault = 'buffer=512k flush=1m';
|
export const accessLogParamsDefault = 'buffer=512k flush=1m';
|
||||||
|
|
||||||
|
export const errorLogPathDefault = '/var/log/nginx/error.log';
|
||||||
export const errorLogLevelDefault = 'warn';
|
export const errorLogLevelDefault = 'warn';
|
||||||
export const errorLogLevelOptions = Object.freeze(['debug', 'info', 'notice', 'warn', 'error', 'crit', 'alert', 'emerg']);
|
export const errorLogLevelOptions = Object.freeze(['debug', 'info', 'notice', 'warn', 'error', 'crit', 'alert', 'emerg']);
|
||||||
|
|
|
@ -26,6 +26,72 @@ THE SOFTWARE.
|
||||||
|
|
||||||
import isObject from './is_object';
|
import isObject from './is_object';
|
||||||
import deepMerge from './deep_merge';
|
import deepMerge from './deep_merge';
|
||||||
|
import { accessLogPathDefault, accessLogParamsDefault, errorLogPathDefault, errorLogLevelDefault } from './logging';
|
||||||
|
import { serverDomainDefault } from './defaults';
|
||||||
|
|
||||||
|
// Migrate old logging settings to new ones
|
||||||
|
const migrateLogging = data => {
|
||||||
|
if (Object.keys(data).length === 0) {
|
||||||
|
// Not having anything to migrate, so skip this logic
|
||||||
|
}
|
||||||
|
|
||||||
|
const globalLogging = 'logging' in data.global && isObject(data.global.logging) ? data.global.logging : {};
|
||||||
|
|
||||||
|
// global access_log
|
||||||
|
const [globalAccessLogPath, ...globalAccessLogParameters] = (globalLogging.accessLog || accessLogPathDefault).split(' ');
|
||||||
|
const globalAccessLogEnabled =
|
||||||
|
!('accessLog' in globalLogging) || // accessLog was enabled by default and might not appear at all
|
||||||
|
(globalAccessLogPath !== '' && globalAccessLogPath !== 'off'); // *or* someone turned it off explicitly
|
||||||
|
|
||||||
|
// global error_log
|
||||||
|
const [globalErrorLogPath, ...globalErrorLogLevel] = (globalLogging.errorLog || `${errorLogPathDefault} ${errorLogLevelDefault}`).split(' ');
|
||||||
|
const globalErrorLogEnabled =
|
||||||
|
!('errorLog' in globalLogging) || // errorLog was enabled by default and might not appear at all
|
||||||
|
globalErrorLogPath !== '/dev/null'; // *or* someone turned it off explicitly
|
||||||
|
|
||||||
|
// set global access_log / error_log files for every domain UNLESS it was explicitly
|
||||||
|
// enabled for the domain
|
||||||
|
for (const key in data.domains) {
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(data.domains, key)) continue;
|
||||||
|
|
||||||
|
const perDomainServer = 'server' in data.domains[key] && isObject(data.domains[key].server) ? data.domains[key].server : {
|
||||||
|
domain: serverDomainDefault,
|
||||||
|
};
|
||||||
|
const perDomainLogging = 'logging' in data.domains[key] && isObject(data.domains[key].logging) ? data.domains[key].logging : {};
|
||||||
|
|
||||||
|
// access_log
|
||||||
|
let accessLogEnabled = globalAccessLogEnabled,
|
||||||
|
accessLogPath = globalAccessLogPath;
|
||||||
|
const accessLogParameters = globalAccessLogParameters.join(' ') || accessLogParamsDefault;
|
||||||
|
|
||||||
|
const perDomainAccessLogEnabled = !!perDomainLogging.accessLog;
|
||||||
|
if (perDomainAccessLogEnabled) {
|
||||||
|
accessLogEnabled = true;
|
||||||
|
accessLogPath = `/var/log/nginx/${perDomainServer.domain}.access.log`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// error_log
|
||||||
|
let errorLogEnabled = globalErrorLogEnabled,
|
||||||
|
errorLogPath = globalErrorLogPath;
|
||||||
|
const errorLogLevel = globalErrorLogLevel.join(' ') || errorLogLevelDefault;
|
||||||
|
|
||||||
|
const perDomainErrorLogEnabled = !!perDomainLogging.errorLog;
|
||||||
|
if (perDomainErrorLogEnabled) {
|
||||||
|
errorLogEnabled = true;
|
||||||
|
errorLogPath = `/var/log/nginx/${perDomainServer.domain}.error.log`;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.domains[key].logging = {
|
||||||
|
...perDomainLogging,
|
||||||
|
accessLogEnabled,
|
||||||
|
accessLogPath,
|
||||||
|
accessLogParameters,
|
||||||
|
errorLogEnabled,
|
||||||
|
errorLogPath,
|
||||||
|
errorLogLevel,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Handle converting the old query format to our new query params
|
// Handle converting the old query format to our new query params
|
||||||
export default data => {
|
export default data => {
|
||||||
|
@ -68,4 +134,6 @@ export default data => {
|
||||||
deepMerge(data.domains[key], mappedData);
|
deepMerge(data.domains[key], mappedData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
migrateLogging(data);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue