简体   繁体   中英

Getting the stack trace or current file from Appcelerator Titanium?

I want to make a logging mechanism that also includes the file that the log statement was written from.

So for instance, if I have a file:

//foo.js
log("stuff");

Then I want the log function to be able to include the file name "foo.js" in the logs.

Is this possible? I haven't been able to find anything about it anywhere.

You can trigger a new error and catch it internally. That way, you can access the stack trace using myError.stack , which will print a list of files that have led to your execution point. Example:

try {
    throw new Error('Trace!');
} catch (err) {
    console.log(err.trace);
}

If you have more questions, let me know!

As an alternative, you could throw the error and handle it in the uncaughtException event. Note that this should only be done for development purposes.

除了触发新错误外,另一种可能的解决方案是创建并维护自己的全局数组,该数组包含已打开的所有控制器的名称。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM