Skip to content

Commit

Permalink
Move logger context generation
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover committed Feb 1, 2021
1 parent 2106bca commit 5f17c38
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/core/server/elasticsearch/client/configure_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const configureClient = (
const clientOptions = parseClientOptions(config, scoped);

const client = new Client(clientOptions);
addLogging(client, logger, type);
addLogging(client, logger.get('query', type));

return client;
};
Expand Down Expand Up @@ -67,15 +67,13 @@ function getResponseMessage(event: RequestEvent): string {
return `${event.statusCode}\n${params.method} ${url}${body}`;
}

const addLogging = (client: Client, logger: Logger, type: string) => {
const queryLogger = logger.get('query', type);

const addLogging = (client: Client, logger: Logger) => {
client.on('response', (error, event) => {
if (event) {
if (error) {
queryLogger.debug(getErrorMessage(error, event));
logger.debug(getErrorMessage(error, event));
} else {
queryLogger.debug(getResponseMessage(event));
logger.debug(getResponseMessage(event));
}
}
});
Expand Down

0 comments on commit 5f17c38

Please sign in to comment.