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
feat: extend global console API to be more Node-compatible #11425
Conversation
Tests:
|
if (options && options.apiName === 'Ti.API') { | ||
this._apiModule = options; | ||
} else { | ||
// if (!options || typeof options.write === 'function') { |
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.
It might be good to spit out a warning / error here since this will practically create a broken console
object which will lead to a crash when used due to _apiModule
being undefined.
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.
I forgot to push my last 2 commits which implemented the stream codepath. Oops! Anyways, please re-check.
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.
Just two notes about TODO items that i think can be quickly added.
JIRA: https://jira.appcelerator.org/browse/TIMOB-26572
Description:
This moves the
global.console
definition entirely into thecommon
JS-layer so that it is defined in a cross-platform way. The removes the JS definition baked into Android's runtime JS, and removes the native Obj-c console on iOS.Our global console object receives the
Ti.API
module (so that we can callinfo
,warn
,error
anddebug
on it). Note that native logging and Ti.API have the concept of log levels, whereas node console really treats log/info/debug as just going tostdout
and warn/error as going tostderr
. So we have to try and retain the log level notion when possible (we sniff for being constructed with an object that has a propertyapiName === 'Ti.API'
, which allows "hijacking" the actual underlying writes in JS tests to verify the strings passed along). It also supports NodeJs stream-like objects in the constructor (but then loses the log level concept - instead passing log/info/debug tostdout
and warn/error tostderr
)Note that we don't have any real shim API for NodeJS streams yet, though (so I couldn't say test a console that actually wrapped a file stream to write to files).
Oh, an important thing to note as well: I did not try to implement
console.table()
. It seemed... extensive.