Skip to content
This repository has been archived by the owner on Dec 3, 2018. It is now read-only.

Commit

Permalink
actual logs to shell.log
Browse files Browse the repository at this point in the history
  • Loading branch information
camilleanne committed Jan 21, 2015
1 parent 805f3d0 commit 289fbd4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 44 deletions.
13 changes: 4 additions & 9 deletions index-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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');
Expand All @@ -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 = [
Expand All @@ -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);
}

Expand Down Expand Up @@ -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+'/');
}

63 changes: 29 additions & 34 deletions index-shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 289fbd4

Please sign in to comment.