Closed daserge closed 8 years ago
Great writeup! I've been wanting to look at our logging support and standardizing it across our projects.
I like variant A and the idea that can try out different loggers.
I also like the idea of having error codes we define/standardize and use for cordova that persist among our various projects.
:+1: I'm all in for a standardized logging. Error verbosity will also give us the ability to debug things much more efficiently. This will make verbose mode much more useful.
This is great! I like variant A.
+1 Variant A
Looks like most of this is implemented now. We should close this issue.
Cordova unified logging
Note: The issue is associated with Cordova-lib refactoring proposal .
Existing architecture issues and proposed solutions
1.
cordova-lib
and cordovaplatforms
have logging set up inconsistentlyCurrent implementation details:
cordova-lib
usesEventEmitter
, which is further listened incordova-cli
and redirected toconsole
calls,platforms
useconsole
methods directly.This leads to the following issue: log level of
cordova-cli
doesn't affectplatforms
at all.Proposed solutions:
Variant A: Platforms can use
EventEmitter
passed as a dependency module viaPlatformApi
' interface (f.e. as a ctor parameter).In case of CLI-mode
cordova-lib
EventEmitter
will be used (and logs handling will be unified therefore).In case of platform-standalone mode
EventEmitter
will be defaulted in the platform.Variant B: Pass
logger
class fromcordova-lib
down toplatforms
and call its methods further.Variant A is recommended as it separates aspects of events emitting from logging and is more flexible in terms of substituting logger module.
2. The log messages aren't standardized
Proposed solution:
logger
module verbosity-based prefixing can be used (WARN :
,ERROR:
, etc.),CordovaError
extended with an error code).3. Platforms logging mechanism does not allow plugging in a custom handling code/module (integration & custom transport levels)
Proposed solution:
cordova.on
event can be used to subscribe for error events sincecordova-lib
'EventEmitter
will be used,logger
module used in CLI or platform-standalone mode can be substituted to a pluggable one, for example winston,console
(file, couchdb, etc.).4. Errors from third-party components (
ant
,gradle
, etc.) can't be easily distinguishedProposed solution: Attach to
process.spawn
stdout
andstderr
, supply caught errors with their source inmeta
object (f.e. extendedCordovaError
- see2.
).