Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
Changes to logging
Browse files Browse the repository at this point in the history
* Remove file logger
* Always log to stderr, not stdout
* Add loglevel flags to set logging level
  • Loading branch information
Andrew Nowak committed Dec 21, 2016
1 parent c036066 commit 4b89da4
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 55 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ LIST OF CHANGES for npg_ranger project
- do not allow query strings containing multiple attribute-value pairs
for the same attribute
- upgrade Freebayes to 1.1.0 from 1.0.2-npg-Aug2016 in TravisCI and docs
- remove directly logging to file due to winston bug
- add flags to change logging level
- all logging output is now sent to stderr

release 1.0.0
- show error in log when controller tests fail to cleanup
Expand Down
8 changes: 2 additions & 6 deletions bin/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ cline
.version(require('../package.json').version)
.description('Command line client for GA4GH data streaming')
.arguments('<url> [output]')
.option('--debug', 'Show debug output')
.option('--loglevel <level>', 'level of logging output', /^(error|warn|info|debug)$/i, 'error')
.option('--accept-trailers', 'Request trailers from server')
.parse(process.argv);

Expand All @@ -91,11 +91,7 @@ cline.on('--help', () => {
if ( !cline.args.length ||
( cline.args.length != 1 && cline.args.length != 2 ) ) { cline.help(); }

if ( !cline.debug ) {
LOGGER.level = 'warn';
} else {
LOGGER.level = 'debug';
}
LOGGER.level = cline.loglevel;

var url = cline.args[0];
var output = cline.args.length == 2 ? cline.args[1] : undefined;
Expand Down
17 changes: 15 additions & 2 deletions bin/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,22 @@ if ( require.main === module ) {
if ( options.get('version') ) {
console.log(require('../package.json').version);
process.exit(0);
} else if ( options.get('debug') ) {
LOGGER.level = 'debug';
}

let loglevel = options.get('loglevel');
let knownLevels = ['error', 'warn', 'info', 'debug', 'silly'];
if (loglevel) {
if (knownLevels.indexOf(loglevel) !== -1) {
LOGGER.level = loglevel;
} else {
// --loglevel was given an invalid parameter - log error and quit
LOGGER.error('configuration error: loglevel flag expects one of ' +
knownLevels.join(', ') + ', but actually received ' +
loglevel);
process.exit(1);
}
}

let numWorkers = options.get('numworkers');
let waitingConsec = options.get('clustertimeout');
let maxConsec = options.get('clustermaxdeaths');
Expand Down
9 changes: 5 additions & 4 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
* // The values from this object will override any
* // found elsewhere, in config files or similar.
* function func() {
* return { debug: true };
* return { loglevel: 'debug' };
* }
* config.provide(func);
* // Retrieve the 'debug' setting
* options.get('debug'); // true
* // Retrieve the 'loglevel' setting
* options.get('loglevel'); // true
*
* @author Andrew Nowak
* @copyright Genome Research Limited 2016
Expand Down Expand Up @@ -56,12 +56,13 @@ const optionsList = [
['s','skipauth' ,'skip authorisation steps'],
['' ,'anyorigin' ,'accept CORS requests from any origin'],
['e','emaildomain=DOMAIN' ,'email domain to validate the remote user value against'],
['d','debug' ,'debugging mode for this server'],
['' ,'loglevel=[error|warn|info|debug]','set logging level [default: error]'],
['V','version' ,'print version and exit'],
['h','help' ,'display this help']
];

const defaultOptions = {
loglevel: 'error',
[RO_OPTION_KEY]: false,
/* cluster */
numworkers: 1,
Expand Down
12 changes: 2 additions & 10 deletions lib/logsetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,11 @@ var getTimeStamp = function() {
try {
LOGGER.remove(LOGGER.transports.Console);
LOGGER.add(LOGGER.transports.Console, {
level: 'warn',
level: 'error',
colorize: true,
json: false,
timestamp: getTimeStamp,
stderrLevels: [ 'error' ] // Which levels to send to stderr
});
LOGGER.add(LOGGER.transports.File, {
level: 'warn',
filename: 'npg_ranger.winston.log',
json: false,
timestamp: getTimeStamp,
maxsize: 10 * 1000 * 1000,
maxFiles: 20
stderrLevels: [ 'error', 'warn', 'info', 'verbose', 'debug', 'silly' ] // Which levels to send to stderr (all)
});
} catch (e) {
console.error('Error when trying to init logging with Winston');
Expand Down
10 changes: 5 additions & 5 deletions test/client/highLevelClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ describe('Running with ranger server with a', () => {
let startServer = ( myDone, myFail ) => {
let serv = spawn(serverCommand, [
'-s',
'-d',
'--loglevel=debug',
'-n0',
`-p${SERV_PORT}`,
`-m${mongourl}`]);
Expand All @@ -256,7 +256,7 @@ describe('Running with ranger server with a', () => {
it('file url', (done) => {
let serv = startServer( done, fail );

serv.stdout.on('data', (data) => {
serv.stderr.on('data', (data) => {
if (data.toString().match(/Server listening on /)) {
// Server is listening and ready for connection
let client = spawn('bin/client.js', [
Expand All @@ -278,7 +278,7 @@ describe('Running with ranger server with a', () => {
it('sample url', (done) => {
let serv = startServer( done, fail );

serv.stdout.on('data', (data) => {
serv.stderr.on('data', (data) => {
if (data.toString().match(/Server listening on /)) {
// Server is listening and ready for connection
let client = spawn('bin/client.js', [
Expand All @@ -304,7 +304,7 @@ describe('Running with ranger server with a', () => {
it('sample url returning vcf', (done) => {
let serv = startServer( done, fail );

serv.stdout.on('data', (data) => {
serv.stderr.on('data', (data) => {
if (data.toString().match(/Server listening on /)) {
// Server is listening and ready for connection
let body = '';
Expand All @@ -327,7 +327,7 @@ describe('Running with ranger server with a', () => {
it('GA4GH url and the redirect is followed', (done) => {
let serv = startServer( done, fail );

serv.stdout.on('data', (data) => {
serv.stderr.on('data', (data) => {
if (data.toString().match(/Server listening on /)) {
// Server is listening and ready for connection
let client = spawn('bin/client.js', [
Expand Down
46 changes: 23 additions & 23 deletions test/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('Listing config options', function() {
hostname: 'myhost',
tempdir: '/tmp/mydir',
port: 9999,
debug: true,
loglevel: 'debug',
emaildomain: 'some.com',
help: true,
clustertimeout: 1,
Expand All @@ -128,9 +128,9 @@ describe('Listing config options', function() {
'clustermaxdeaths=2',
'clustertimeout=1',
'configfile=undefined',
'debug=true',
'emaildomain="some.com"',
'hostname="myhost"',
'loglevel="debug"',
'mongourl="mymongourl"',
'multiref=undefined',
'numworkers=3',
Expand Down Expand Up @@ -164,7 +164,7 @@ describe('Validating CORS options', function() {
hostname: 'myhost',
tempdir: '/tmp/yourdir',
port: 9999,
debug: true,
loglevel: 'debug',
help: true,
anyorigin: 'true'
};});
Expand All @@ -179,7 +179,7 @@ describe('Validating CORS options', function() {
hostname: 'myhost',
tempdir: '/tmp/mydir',
port: port - 1,
debug: true,
loglevel: 'debug',
help: true,
anyorigin: true,
originlist: ['url1','url2']
Expand All @@ -195,7 +195,7 @@ describe('Validating CORS options', function() {
hostname: 'myhost',
tempdir: '/tmp/mydir',
port: 9999,
debug: true,
loglevel: 'debug',
help: true,
anyorigin: true,
skipauth: false
Expand All @@ -210,7 +210,7 @@ describe('Validating CORS options', function() {
hostname: 'myhost',
tempdir: '/tmp/mydir',
port: 9999,
debug: true,
loglevel: 'debug',
help: true,
anyorigin: false,
originlist: 'some,urls'
Expand All @@ -223,7 +223,7 @@ describe('Validating CORS options', function() {
hostname: 'myhost',
tempdir: '/tmp/mydir',
port: 9999,
debug: true,
loglevel: 'debug',
help: true,
anyorigin: false,
originlist: ['myurl']
Expand All @@ -235,7 +235,7 @@ describe('Validating CORS options', function() {
hostname: 'myhost',
tempdir: '/tmp/mydir',
port: 9999,
debug: true,
loglevel: 'debug',
help: true,
anyorigin: false,
originlist: ['https://myurl']
Expand All @@ -247,7 +247,7 @@ describe('Validating CORS options', function() {
hostname: 'myhost',
tempdir: '/tmp/mydir',
port: 9999,
debug: true,
loglevel: 'debug',
help: true,
anyorigin: false,
originlist: ['http://']
Expand All @@ -259,7 +259,7 @@ describe('Validating CORS options', function() {
hostname: 'myhost',
tempdir: '/tmp/mydir',
port: 9999,
debug: true,
loglevel: 'debug',
help: true,
anyorigin: false,
originlist: ['http://server.com/foo']
Expand All @@ -271,7 +271,7 @@ describe('Validating CORS options', function() {
hostname: 'myhost',
tempdir: '/tmp/mydir',
port: 9999,
debug: true,
loglevel: 'debug',
help: true,
anyorigin: false,
originlist: ['http://server.com/']
Expand All @@ -283,7 +283,7 @@ describe('Validating CORS options', function() {
hostname: 'myhost',
tempdir: '/tmp/mydir',
port: 9999,
debug: true,
loglevel: 'debug',
help: true,
anyorigin: false,
originlist: ['http://server.com//']
Expand All @@ -295,7 +295,7 @@ describe('Validating CORS options', function() {
hostname: 'myhost',
tempdir: '/tmp/mydir',
port: 9999,
debug: true,
loglevel: 'debug',
help: true,
anyorigin: false,
originlist: ['http://server.com/', ' ','http://server.org']
Expand All @@ -306,7 +306,7 @@ describe('Validating CORS options', function() {
hostname: 'myhost',
tempdir: '/tmp/mydir',
port: 9999,
debug: true,
loglevel: 'debug',
help: true,
anyorigin: false,
originlist: ['http://server.com:8080?foo=2']
Expand All @@ -317,7 +317,7 @@ describe('Validating CORS options', function() {
hostname: 'myhost',
tempdir: '/tmp/mydir',
port: 9999,
debug: true,
loglevel: 'debug',
help: true,
anyorigin: false,
originlist: ['http://server.com:8080?']
Expand All @@ -329,7 +329,7 @@ describe('Validating CORS options', function() {
hostname: 'myhost',
tempdir: '/tmp/mydir',
port: 9999,
debug: true,
loglevel: 'debug',
help: true,
anyorigin: false,
originlist: ['http://localhost:9999#mttag']
Expand All @@ -340,7 +340,7 @@ describe('Validating CORS options', function() {
hostname: 'myhost',
tempdir: '/tmp/mydir',
port: 9999,
debug: true,
loglevel: 'debug',
help: true,
anyorigin: false,
originlist: ['http://server.com:9999#']
Expand All @@ -352,7 +352,7 @@ describe('Validating CORS options', function() {
hostname: 'myhost',
tempdir: '/tmp/mydir',
port: 9999,
debug: true,
loglevel: 'debug',
help: true,
anyorigin: false,
originlist: ['http://server.com:9999/#tag']
Expand All @@ -365,7 +365,7 @@ describe('Validating CORS options', function() {
hostname: 'myhost',
tempdir: '/tmp/mydir',
port: 9999,
debug: true,
loglevel: 'debug',
help: true,
originlist: ['http://my.com']
};});
Expand All @@ -378,7 +378,7 @@ describe('Validating CORS options', function() {
hostname: 'myhost',
tempdir: '/tmp/mydir',
port: 9999,
debug: true,
loglevel: 'debug',
help: true,
originlist: ['http://my.com:80','http://your.org']
};});
Expand All @@ -390,7 +390,7 @@ describe('Validating CORS options', function() {
hostname: 'myhost',
tempdir: '/tmp/mydir',
port: 9999,
debug: true,
loglevel: 'debug',
help: true,
originlist: ['http://my.com:80','','http://your.org']
};});
Expand All @@ -401,7 +401,7 @@ describe('Validating CORS options', function() {
hostname: 'myhost',
tempdir: '/tmp/mydir',
port: 9999,
debug: true,
loglevel: 'debug',
help: true,
originlist: []
};});
Expand All @@ -417,7 +417,7 @@ describe('Secure server options', () => {
mongourl: 'mymongourl',
hostname: 'myhost',
port: 9999,
debug: true,
loglevel: 'debug',
help: true
};
});
Expand Down
6 changes: 3 additions & 3 deletions test/server/bin_server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ describe('Sockets are cleaned', () => {
let socketPath = `${tmp_dir}/${socketName}`;
fse.close(fse.openSync(socketPath, 'w'));
child = spawn(serverCommand,[
'-d',
'--loglevel=debug',
`-mmongodb://localhost:${PORT}`,
'-k2', '-l1', // Max 2 deaths in 1 second
'-n', `${numWorkers}`,
Expand All @@ -279,7 +279,7 @@ describe('Sockets are cleaned', () => {
expect(err).toBeDefined();
});
child = spawn(serverCommand,[
'-d',
'--loglevel=debug',
`-mmongodb://localhost:${PORT}`,
`-n0`,
'-p', `${socketPath}`]
Expand Down Expand Up @@ -311,7 +311,7 @@ describe('Sockets are cleaned', () => {
expect(err).toBeDefined();
});
child = spawn(serverCommand,[
'-d',
'--loglevel=debug',
`-mmongodb://localhost:${PORT}`,
`-n5`,
'-p', `${socketPath}`]
Expand Down
Loading

0 comments on commit 4b89da4

Please sign in to comment.