Log correct Kibana URL when TLS is enabled and log it only once. (#20721)

This commit is contained in:
Aleh Zasypkin 2018-07-19 01:27:32 +02:00 committed by GitHub
parent 0f5322e3a5
commit 2a645d2252
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 54 additions and 55 deletions

View file

@ -13,44 +13,15 @@ Object {
],
"type": "log",
},
Object {
"@timestamp": "## @timestamp ##",
"message": "starting server :tada:",
"pid": "## PID ##",
"tags": Array [
"info",
"server",
],
"type": "log",
},
Object {
"@timestamp": "## @timestamp ##",
"message": "registering route handler for [/core]",
"pid": "## PID ##",
"tags": Array [
"info",
"http",
],
"type": "log",
},
Object {
"@timestamp": "## @timestamp ##",
"message": "starting http server [localhost:8274]",
"pid": "## PID ##",
"tags": Array [
"info",
"http",
"server",
],
"type": "log",
},
Object {
"@timestamp": "## @timestamp ##",
"message": "Server running at http://localhost:8274",
"pid": "## PID ##",
"tags": Array [
"listening",
"info",
"http",
"server",
"listening",
],
"type": "log",
},

View file

@ -18,14 +18,14 @@ Object {
exports[`register route handler 1`] = `
Object {
"debug": Array [],
"error": Array [],
"fatal": Array [],
"info": Array [
"debug": Array [
Array [
"registering route handler for [/foo]",
],
],
"error": Array [],
"fatal": Array [],
"info": Array [],
"log": Array [],
"trace": Array [],
"warn": Array [],

View file

@ -83,9 +83,13 @@ export class HttpServer {
});
}
this.log.info(`starting http server [${config.host}:${config.port}]`);
await this.server.start();
this.log.info(
`Server running at ${this.server.info.uri}${config.rewriteBasePath ? config.basePath : ''}`,
// The "legacy" Kibana will output log records with `listening` tag even if `quiet` logging mode is enabled.
{ tags: ['listening'] }
);
}
public async stop() {

View file

@ -85,7 +85,7 @@ export class HttpService implements CoreService {
'Router will **not** be applied.'
);
} else {
this.log.info(`registering route handler for [${router.path}]`);
this.log.debug(`registering route handler for [${router.path}]`);
this.httpServer.registerRouter(router);
}
}

View file

@ -33,7 +33,7 @@ export class Server {
}
public async start() {
this.log.info('starting server :tada:');
this.log.debug('starting server :tada:');
const router = new Router('/core');
router.get({ path: '/', validate: false }, async (req, res) => res.ok({ version: '0.0.1' }));

View file

@ -72,5 +72,25 @@ Array [
"message-8-with-message",
2012-02-01T11:22:33.044Z,
],
Array [
Array [
"info",
"context-9",
"sub-context-9",
],
"message-9-with-message",
2012-02-01T11:22:33.044Z,
],
Array [
Array [
"info",
"context-10",
"sub-context-10",
"tag1",
"tag2",
],
"message-10-with-message",
2012-02-01T11:22:33.044Z,
],
]
`;

View file

@ -86,6 +86,20 @@ test('`append()` correctly pushes records to legacy platform.', () => {
message: 'message-8-with-message',
timestamp,
},
{
context: 'context-9.sub-context-9',
level: LogLevel.Info,
message: 'message-9-with-message',
timestamp,
meta: { someValue: 3 },
},
{
context: 'context-10.sub-context-10',
level: LogLevel.Info,
message: 'message-10-with-message',
timestamp,
meta: { tags: ['tag1', 'tag2'] },
},
];
const rawKbnServerMock = {

View file

@ -41,12 +41,10 @@ export class LegacyAppender implements DisposableAppender {
* write record to the configured destination.
* @param record `LogRecord` instance to forward to.
*/
public append(record: LogRecord) {
this.kbnServer.log(
[record.level.id.toLowerCase(), ...record.context.split('.')],
record.error || record.message,
record.timestamp
);
public append({ level, context, message, error, timestamp, meta = {} }: LogRecord) {
const tags = [level.id.toLowerCase(), ...context.split('.'), ...(meta.tags || [])];
this.kbnServer.log(tags, error || message, timestamp);
}
public async dispose() {

View file

@ -140,10 +140,7 @@ export default class KbnServer {
* @return undefined
*/
async listen() {
const {
server,
config,
} = this;
const { server } = this;
await this.ready();
await fromNode(cb => server.start(cb));
@ -153,11 +150,6 @@ export default class KbnServer {
process.send(['WORKER_LISTENING']);
}
server.log(['listening', 'info'], `Server running at ${server.info.uri}${
config.get('server.rewriteBasePath')
? config.get('server.basePath')
: ''
}`);
return server;
}