Skip to content

Commit

Permalink
fix: logger
Browse files Browse the repository at this point in the history
  • Loading branch information
foxhound87 committed Jan 11, 2017
1 parent 9c9090d commit 4d5bad7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
58 changes: 32 additions & 26 deletions src/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,50 @@ import getenv from 'getenv';
// set log as cli mode
log.cli();

function logInit() {
export const webhost = key => ['http://',
getenv([key.toUpperCase(), 'HOST'].join('_')), ':',
getenv([key.toUpperCase(), 'PORT'].join('_')),
].join('');

const logInit = () => {
log.info('------------------------------------------');
log.info('--------------- RFX STACK ----------------');
log.info('------------------------------------------');
}
};

function logServerAPI(url) {
logInit();
const logServerAPI = (url) => {
log.info('API Listening at:', url);
log.info('Environment:', getenv('NODE_ENV'));
log.info('------------------------------------------');
log.info('Database Host:', getenv('DB_HOST'));
log.info('Database Name:', getenv('DB_NAME'));
log.info('Database Port:', getenv('DB_PORT'));
log.info('------------------------------------------');
}

function logServerWEB(url) {
return [
'RFX STACK',
`WEB Listening at: ${url}`,
`Environment: ${getenv('NODE_ENV')}`,
`IO Host: ${getenv('IO_HOST')}`,
`IO Port: ${getenv('IO_PORT')}`,
];
}
};

function logServerConfig($key = null) {
const key = $key.toUpperCase();

const port = getenv([key, 'PORT'].join('_'));
const host = getenv([key, 'HOST'].join('_'));
const logServerWEB = (url) => {
log.info('API Listening at:', url);
log.info('Environment:', getenv('NODE_ENV'));
log.info('------------------------------------------');
log.info('IO Host:', getenv('IO_HOST'));
log.info('IO Port:', getenv('IO_PORT'));
log.info('------------------------------------------');
};

const url = ['http://', host, ':', port].join('');
export const logServerConfigWebpack = url => ([
'RFX STACK',
`WEB Listening at: ${webhost(url)}`,
`Environment: ${getenv('NODE_ENV')}`,
`IO Host: ${getenv('IO_HOST')}`,
`IO Port: ${getenv('IO_PORT')}`,
]);

if (key === 'API') return logServerAPI(url);
if (key === 'WEB') return logServerWEB(url);
return [];
}
export const logServerConfig = (key = null) => {
logInit();
const url = webhost(key);
return (key.toUpperCase() === 'API')
? logServerAPI(url)
: logServerWEB(url);
};

export { log, logInit, logServerConfig };
export { log };
1 change: 0 additions & 1 deletion src/utils/server.start.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class ServerStart {
const configkey = this.configkey || 'server';
const logger = props.logger || null;
const config = this.getFeathersConfig(configkey) || this.getEnvConfig(key);

this.start(config, key, logger);
}

Expand Down
9 changes: 2 additions & 7 deletions webpack/config.client.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@ import webpack from 'webpack';
import getenv from 'getenv';
import path from 'path';

import { logServerConfig } from '@/utils/logger';
import { logServerConfigWebpack, webhost } from '@/utils/logger';

const Dir = global.DIR;

const webhost = key => ['http://',
getenv([key.toUpperCase(), 'HOST'].join('_')), ':',
getenv([key.toUpperCase(), 'PORT'].join('_')),
].join('');

export function loader() {
return {
jsx: {
Expand Down Expand Up @@ -63,7 +58,7 @@ export function config(entry) {
new FriendlyErrorsWebpackPlugin({
clearConsole: true,
compilationSuccessInfo: {
messages: logServerConfig(entry),
messages: logServerConfigWebpack(entry),
},
}),
new BrowserSyncPlugin({
Expand Down

0 comments on commit 4d5bad7

Please sign in to comment.