diff --git a/index-server.js b/index-server.js index f523c930..ecb73fc9 100644 --- a/index-server.js +++ b/index-server.js @@ -2,11 +2,9 @@ // In an ideal world this would be run in the same process/context of // atom-shell but there are many hurdles atm, see // https://github.com/atom/atom-shell/issues/533 -var logger = require('fastlog')('', 'debug', '<${timestamp}>'); // increase the libuv threadpool size to 1.5x the number of logical CPUs. process.env.UV_THREADPOOL_SIZE = Math.ceil(Math.max(4, require('os').cpus().length * 1.5)); - process.title = 'mapbox-studio'; if (process.platform === 'win32') { @@ -16,10 +14,6 @@ if (process.platform === 'win32') { process.env.PATH = ''; } -process.on('exit', function(code) { - console.warn('Mapbox Studio exited with', code + '.'); -}); - var tm = require('./lib/tm'); var path = require('path'); var getport = require('getport'); @@ -30,6 +24,7 @@ config.shell = config.shell || false; config.port = config.port || undefined; config.test = config.test || false; config.cwd = path.resolve(config.cwd || process.env.HOME); +var logger = require('fastlog')('', 'debug', '<${timestamp}>'); var usage = function usage() { var str = [ @@ -51,12 +46,12 @@ var usage = function usage() { } if (config.version) { - console.log(package_json.version); + logger.debug(package_json.version); process.exit(0); } if (config.help || config.h) { - console.log(usage()); + logger.debug(usage()); process.exit(0); } @@ -85,6 +80,6 @@ function listen(err) { function finish(err) { if (err) throw err; server.emit('ready'); - console.log('Mapbox Studio @ http://localhost:'+tm.config().port+'/'); + logger.debug('Mapbox Studio @ http://localhost:'+tm.config().port+'/'); } diff --git a/index-shell.js b/index-shell.js index 109b3e6c..47e60b4c 100644 --- a/index-shell.js +++ b/index-shell.js @@ -10,45 +10,40 @@ var node = path.resolve(path.join(__dirname, 'vendor', 'node')); var script = path.resolve(path.join(__dirname, 'index-server.js')); var shellLog = path.join(process.env.HOME, '.mapbox-studio', 'shell.log'); var logger = require('fastlog')('', 'debug', '<${timestamp}>'); - -log(shellLog, 10e6, function(err) { - if (err) throw err; -}); - -// Start the server child process. -var server = spawn(node, [script, '--shell=true']); -server.on('exit', process.exit); -server.stdout.once('data', function(data) { - var matches = data.toString().match(/Mapbox Studio @ http:\/\/localhost:([0-9]+)\//); - if (!matches) { - console.warn('Server port not found'); - process.exit(1); - } - var serverPort = matches[1]; - loadURL(); -}); -server.stdout.pipe(process.stdout); -server.stderr.pipe(process.stderr); - -process.on('exit', function(code) { - console.warn('Mapbox Studio exited with', code + '.'); -}); - var serverPort = null; var mainWindow = null; +// set up shell.log and log rotation +log(shellLog, 10e6, shellsetup); -// // TEMP! -// var serverPort = 3000; -// loadURL(); +function shellsetup(err){ + process.on('exit', function(code) { + logger.debug('Mapbox Studio exited with', code + '.'); + }); -// Report crashes to our server. -require('crash-reporter').start(); + // Start the server child process. + var server = spawn(node, [script, '--shell=true']); + server.on('exit', process.exit); + server.stdout.once('data', function(data) { + var matches = data.toString().match(/Mapbox Studio @ http:\/\/localhost:([0-9]+)\//); + if (!matches) { + console.warn('Server port not found'); + process.exit(1); + } + serverPort = matches[1]; + logger.debug('Mapbox Studio @ http://localhost:'+serverPort+'/'); + loadURL(); + }); + + // Report crashes to our server. + require('crash-reporter').start(); + + atom.on('window-all-closed', function() { + if (server) server.kill(); + process.exit(); + }); -atom.on('window-all-closed', function() { - if (server) server.kill(); - process.exit(); -}); -atom.on('ready', makeWindow); + atom.on('ready', makeWindow); +}; function makeWindow() { // Create the browser window. diff --git a/lib/server.js b/lib/server.js index 2eb1dd14..65cb5dcc 100755 --- a/lib/server.js +++ b/lib/server.js @@ -20,7 +20,7 @@ var gazetteer = require('gazetteer'); var carto = require('carto'); var version = require('./../package.json').version.replace(/^\s+|\s+$/g, ''); var nocache = Math.random().toString(36).substr(-8); -var logger = require('fastlog')('debug', 'error', '${level} <${timestamp}>'); +var logger = require('fastlog')('', 'debug', '<${timestamp}> ${level}'); var mapnik = require('mapnik'); if (!carto.tree.Reference.setVersion(mapnik.versions.mapnik)) { throw new Error("Could not set mapnik version to " + mapnik.versions.mapnik);