-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TIMOB-12169] Create build log with compilation #6297
Changes from 5 commits
fc4a8e5
5f0e7d0
841d963
fef55d9
4d62526
3f8ccdc
c70bc37
2e9ce8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,6 +106,9 @@ exports.config = function (logger, config, cli) { | |
} | ||
} | ||
|
||
// start file logging here | ||
logger = patchLogger(logger, cli); | ||
|
||
// load the tiapp.xml | ||
try { | ||
var tiapp = cli.tiapp = new tiappxml(path.join(projectDir, 'tiapp.xml')); | ||
|
@@ -253,3 +256,86 @@ exports.run = function (logger, config, cli, finished) { | |
} | ||
}); | ||
}; | ||
|
||
/** | ||
* Monkey-patch the logger object to enable file logging during build | ||
* @param {Object} logger - The logger instance | ||
* @param {Object} cli - The CLI instance | ||
*/ | ||
function patchLogger(logger, cli) { | ||
var origLoggerLog = logger.log, | ||
platform = ti.resolvePlatform(cli.argv.platform), | ||
logFileStream; | ||
// create our write stream | ||
logFileStream = fs.createWriteStream(path.join(cli.argv['project-dir'], 'build', 'build_' + platform + '.log'), { 'flags': 'w', 'encoding': 'ascii' }); | ||
// write the banner to start out the log | ||
logFileStream.write(logBanner(cli)); | ||
// override the existing log function | ||
logger.log = function() { | ||
// most of this copied from the CLI's logger.js logger.log() function | ||
var args = Array.prototype.slice.call(arguments), | ||
padLevels = logger.padLevels, | ||
prefix; | ||
|
||
// if there are no args (i.e. a blank line), we need at least one space | ||
args.length || args.unshift(' '); | ||
|
||
// if we're not being called from info/warn/error/debug, then set this as a general log entry | ||
args[0] in logger.levels || args.unshift('_'); | ||
|
||
// turn off padding | ||
logger.padLevels = args[0] != '_'; | ||
|
||
// get rid of any null args | ||
while (args.length && args[args.length-1] == null) args.pop(); | ||
|
||
// if we're logging an error, we need to cast to a string so that sprintf doesn't complain | ||
if (args[1] instanceof Error || Object.prototype.toString.call(args[1]) == '[object Error]') { | ||
args[1] = (args[1].stack || args[1].toString()) + '\n'; | ||
} else if (args[1] == null || args[1] == undefined) { | ||
args[1] = ''; | ||
} | ||
|
||
typeof type != 'string' && (args[1] = ''+args[1]); | ||
|
||
// strip off starting full colons | ||
args[1] = args[1].replace(/:\s{1}/, ' '); | ||
|
||
// add [INFO] type prefixes for each line | ||
prefix = (args[0] != "_") ? "[" + args[0].toUpperCase() + "]" + ((args[0].length===5) ? ' ' : ' ') : ""; | ||
|
||
// log it to our log file, stripping out the color codes | ||
logFileStream.write("\n" + prefix + args[1].replace(/\x1B\[\d+m/g, '')); | ||
|
||
// call the original logger with our cleaned up args | ||
origLoggerLog.apply(logger, [args[0], args.length > 2 ? sprintf.apply(null, args.slice(1)) : args[1]]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line fails with:
You forgot to add
Then you need to add the module to the Titanium SDK repo:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. |
||
|
||
// restore padding | ||
logger.padLevels = padLevels; | ||
|
||
return logger; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to return logger here. Logger is passed by reference. |
||
} | ||
} | ||
|
||
/** | ||
* Outputs environment details at the top of the log file | ||
* for each run of `titanium build` | ||
* @param {Object} cli - The CLI instance | ||
* | ||
* See http://en.wikipedia.org/wiki/Darwin_%28operating_system%29#Release_history for | ||
* os.release() to version mapping for OS X. (e.g. 14.0.0 is v10.10 Yosemite) | ||
*/ | ||
function logBanner(cli) { | ||
var os = require('os'); | ||
return '\n\n---------------------------------\n\n' + | ||
new Date().toLocaleString() + '\n\n' + | ||
'Build Environment \n' + | ||
' Host OS = ' + (os.platform()==='darwin' ? "OS X" : os.platform()) + ' ' + os.release() + ', ' + os.arch() + '\n' + | ||
' Target platform = ' + ti.resolvePlatform(cli.argv.platform) + '\n' + | ||
' CLI version = ' + cli.version + '\n' + | ||
' SDK version = ' + cli.argv.sdk + '\n' + | ||
' SDK path = ' + cli.sdk.path + '\n' + | ||
' Node version = ' + process.version + '\n' + | ||
' Command = ' + cli.argv.$ + ' ' + cli.argv.$_.join(' ') + '\n' + | ||
'\n'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to return logger here. Logger is passed by reference.