Skip to content

Commit

Permalink
[config] logging.useUTC -> logging.timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
jbudz committed Aug 1, 2018
1 parent a66cb68 commit 95b70a1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/server/config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export default async () => Joi.object({
then: Joi.default(!process.stdout.isTTY),
otherwise: Joi.default(true)
}),
useUTC: Joi.boolean().default(true),
timezone: Joi.string().allow(false).default('UTC')
}).default(),

ops: Joi.object({
Expand Down
11 changes: 11 additions & 0 deletions src/server/config/transform_deprecations.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import _, { partial } from 'lodash';
import { createTransform, Deprecations } from '../../deprecation';
import { unset, set } from '../utils';

const { rename, unused } = Deprecations;

Expand Down Expand Up @@ -55,6 +56,15 @@ const rewriteBasePath = (settings, log) => {
}
};

const loggingTimezone = (settings, log) => {
if (_.has(settings, 'logging.useUTC')) {
const timezone = settings.logging.useUTC ? 'UTC' : false;
set('logging.timezone', timezone);
unset(settings, 'logging.UTC');
log(`Config key "logging.useUTC" is deprecated. It has been replaced with "logging.timezone"`);
}
};

const deprecations = [
//server
rename('server.ssl.cert', 'server.ssl.certificate'),
Expand All @@ -68,6 +78,7 @@ const deprecations = [
serverSslEnabled,
savedObjectsIndexCheckTimeout,
rewriteBasePath,
loggingTimezone,
];

export const transformDeprecations = createTransform(deprecations);
2 changes: 1 addition & 1 deletion src/server/logging/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default function loggingConfiguration(config) {
config: {
json: config.get('logging.json'),
dest: config.get('logging.dest'),
useUTC: config.get('logging.useUTC'),
timezone: config.get('logging.timezone'),

// I'm adding the default here because if you add another filter
// using the commandline it will remove authorization. I want users
Expand Down
8 changes: 4 additions & 4 deletions src/server/logging/log_format.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import Stream from 'stream';
import moment from 'moment';
import moment from 'moment-timezone';
import { get, _ } from 'lodash';
import numeral from '@elastic/numeral';
import chalk from 'chalk';
Expand Down Expand Up @@ -66,10 +66,10 @@ export default class TransformObjStream extends Stream.Transform {
}

extractAndFormatTimestamp(data, format) {
const { useUTC } = this.config;
const { timezone } = this.config;
const date = moment(data['@timestamp']);
if (useUTC) {
date.utc();
if (timezone) {
date.tz(timezone);
}
return date.format(format);
}
Expand Down
12 changes: 5 additions & 7 deletions src/server/logging/log_format_json.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ describe('KbnLoggerJsonFormat', () => {
});
});

describe('useUTC', () => {
it('logs in UTC when useUTC is true', async () => {
describe('timezone', () => {
it('logs in UTC', async () => {
const format = new KbnLoggerJsonFormat({
useUTC: true
timezone: 'UTC'
});

const result = await createPromiseFromStreams([
Expand All @@ -211,10 +211,8 @@ describe('KbnLoggerJsonFormat', () => {
expect(timestamp).toBe(moment.utc(time).format());
});

it('logs in local timezone when useUTC is false', async () => {
const format = new KbnLoggerJsonFormat({
useUTC: false
});
it('logs in local timezone timezone is undefined', async () => {
const format = new KbnLoggerJsonFormat({});

const result = await createPromiseFromStreams([
createListStream([makeEvent('log')]),
Expand Down
10 changes: 4 additions & 6 deletions src/server/logging/log_format_string.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ const makeEvent = () => ({
});

describe('KbnLoggerStringFormat', () => {
it('logs in UTC when useUTC is true', async () => {
it('logs in UTC', async () => {
const format = new KbnLoggerStringFormat({
useUTC: true
timezone: 'UTC'
});

const result = await createPromiseFromStreams([
Expand All @@ -51,10 +51,8 @@ describe('KbnLoggerStringFormat', () => {
.toContain(moment.utc(time).format('HH:mm:ss.SSS'));
});

it('logs in local timezone when useUTC is false', async () => {
const format = new KbnLoggerStringFormat({
useUTC: false
});
it('logs in local timezone when timezone is undefined', async () => {
const format = new KbnLoggerStringFormat({});

const result = await createPromiseFromStreams([
createListStream([makeEvent()]),
Expand Down

0 comments on commit 95b70a1

Please sign in to comment.