Skip to content

Commit

Permalink
refactor: extract #formatMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
blackxored committed Nov 15, 2017
1 parent f710975 commit c77b2c7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
18 changes: 18 additions & 0 deletions src/formatMessage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const formatMessage = (operationType, operation, ellapsed) => {
const headerCss = [
'color: gray; font-weight: lighter', // title
`color: ${operationType === 'query' ? '#03A9F4' : 'red'};`, // operationType
'color: #000;', // operationName
'color: gray; font-weight: lighter;', // time, etc
];

const parts = ['%c apollo'];

parts.push(`%c${operationType}`);
parts.push(`%c${operation.operationName}`);
parts.push(`%c(in ${ellapsed} ms)`);

return [parts.join(' ', ...headerCss)];
};

module.exports = formatMessage;
18 changes: 1 addition & 17 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
const { ApolloLink } = require('apollo-link');

const formatMessage = (operationType, operation, ellapsed) => {
const headerCss = [
'color: gray; font-weight: lighter', // title
`color: ${operationType === 'query' ? '#03A9F4' : 'red'};`, // operationType
'color: #000;', // operationName
'color: gray; font-weight: lighter;', // time, etc
];

const parts = ['%c apollo'];

parts.push(`%c${operationType}`);
parts.push(`%c${operation.operationName}`);
parts.push(`%c(in ${ellapsed} ms)`);

return [parts.join(' ', ...headerCss)];
};
const formatMessage = require('./formatMessage');

const loggerLink = new ApolloLink((operation, forward) => {
const startTime = new Date().getTime();
Expand Down

0 comments on commit c77b2c7

Please sign in to comment.