I'm trying to use logCat.
I have the following code that gets executed
Log.i("MyLog", "Test to see if it works");
But the Logcat on eclipse only shows
All messages (no filters)
Is there a setting or something in eclipse?
In the Logcat menu there is a Green plus above the All messages (no filters)
Either use "MyLog" at the Log Tag input-field to only see your log that is tagged with "MyLog",
or use your applications namespace (like com.example.your_app) at the by Application Name to show all logs of your application without the spam you got with all messages of Eclipse and the Emulator. (This does still include the dalvikvm that increases the heap size, Choreographer which warns you when you do too much work on the Main Thread, and similar app-related logs though.)
Add a filter (the green plus) with by Log Tag:MyLog and by Log Level:info.
You have to create a filter manually with that tag from the Log.i in the LogCat view. You can use the + icon next to the Saved filters label
Related
I am using the examples from https://developer.glympse.com/docs/core/client-sdk/downloads link.
I tried the GlympseSendDemo and GlympseCreateDemo using Android Studio(without any changes apart from editing the temporary developer API key that I created by creating an account online).
When I run both examples, I get a
"Failed to create"
message. What could be wrong with this?
EDIT 1
Debugging both the samples, the _glympse member is null when it hits the breakpoint i set at createGlympse() method of GlympseWrapper class.
EDIT 2
The GE.PLATFORM_STOPPED event from the Glympse SDK is getting fired that causes the _glympse variable to be set to null through the call GlympseWrapper.instance().clear();.
So my question is why is this event getting fired within a few seconds of the app starting up?
Try setting a breakpoint in GlympseWrapper.clear(). I suspect the platform is stopping after starting causing _glympse to be set to null. If that's happening, double check the api key is entered correctly.
_glympse = GlympseFactory.createGlympse(context, BASE_URL, API_KEY);
// Also try adding this line here to get some additional log information
_glympse.overrideLoggingLevels(CoreConstants.INFO, CoreConstants.INFO);
I've been trying to get errors to display in a text field within the app for ease of error reporting from users.
I've had some success using this code I found on stackoverflow. It's used at the top level of the app but it's not working on device:
//start code
this.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, errorHandler);
function globalErrorHandler(event:UncaughtErrorEvent):void
{
var message:String;
//check for runtime error
if (event.error is Error)
message = (event.error as Error).getStackTrace();
//handle other errors
else if (event.error is ErrorEvent)
message = (event.error as ErrorEvent).text;
else
message = event.error.toString();
//do something with message (eg display it in textfield)
myTextfield.text = message;
}
//end code
At first this wouldn't work on the device and I thought it was because upon the error, when developing on the pc, flashplayer would display the actionscript popup with the error. Which you would need to click "dismiss all" or close and then the globalErrorHandler was called after and then the error written to the textfield. I thought this is what was keeping it from showing up on the device. However, by adding event.preventDefault() I was able to suppress the actionscript popup when developing on the desktop and the error was written to the textfield successfully. This was not the case however on the andriod device. It still just hangs on the error. It's as if the default error event cannot be suppressed on android.
Thanks for your time. Any help appreciated!
EDIT 22/09/2017: I was able to see the error on device finally. It had to do with while on desktop publishing the error would be shown. However, on device the behavior was different and something was covering the textfield, by bring it to the front on error I was able to see it. However, I still see that some errors deeper in the class hierarchy are not being caught.
In our project we have it simpler (and it is working):
stage.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtError);
private function onUncaughtError(e:UncaughtErrorEvent):void
{
// Console is basically a TextField for debug/diagnosis output.
if (e.error) Console.error(e.error.getStackTrace());
e.preventDefault();
}
The other thing you should probably check is whether your TextField actually displays any text at all for there might be text embedding issues, unrelated to the error handling routine.
UPD: Loading SWFs so it doesn't mix with the parent.
var request:URLRequest = new URLRequest(path);
var context:LoaderContext = new LoaderContext;
context.applicationDomain = ApplicationDomain.currentDomain;
var loader:Loader = new Loader;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
loader.load(request, context);
I would like to get a object dump additionally sent during a crashlytics exception logging. So for example lets say there is a nullPointerException that occurs. i'd like to additionally add a large object which would be my model and include that in the stack trace area in crashlytics. this way when i see the stacktrace i can also view the model information from the dump. How would i send this info in additional to the usual crashlytics logging ? Here is what i have so far:
try{
//....
throw new NullPointerException("my cool msg");
}
catch(Exception e){
Crashlytics.setInt("priority", 4);
Crashlytics.setString("tag", "mytag");
Crashlytics.setString("message", Model.toString());
Crashlytics.logException(e);
}
What is occuring now is that nothing is appearing. but if i comment out the setString for "message" then i get a stacktrace with the message "my cool msg".
UPDATE: I even tried Crashlytics.log(Model.toString()); but that shows nothing on crashlytics. i am setting up crashlytics from Application subclass in onCreate like this: Fabric.with(this, new Crashlytics());
from the cashlytics docs i found this:
To make sure that sending crash reports has the smallest impact on your user’s devices, Crashlytics logs have a maximum size of 64 KB. When a log exceeds 64 KB, the earliest logged values will be dropped in order to maintain this threshold.
this could be my issue. checking my size now...
adjusting the size of the payload did not work. i made the payload 9 characters but still its not appearing.
UPDATE:
Lets start again but more simply. why does the following not work for me ?
try{
//....
throw new NullPointerException("my cool msg");
}
catch(Exception e){
Crashlytics.setInt("priority", 4);
Crashlytics.setString("tag", "mytag");
Crashlytics.setString("message", "");
Crashlytics.logException(e);
}
What happens here is indeed a stacktrace appears in crasylytics dashboard with the words "my cool message" but there is nothing about priority, tag or message. Only the stacktrace is appearing. should there
not be entries there with these headings or something ?
AFter clicking on the green "view all sessions" button i was able to see the custom information. they could have made it more obvious.
and also from the docs it seems the non-fatal exceptions are batched and sent the next time the app launches:
Crashlytics processes exceptions on a dedicated background thread, so the performance impact to your app is minimal. To reduce your users’ network traffic, Crashlytics batches logged exceptions together and sends them the next time the app launches.
I have a problem setting up Robotium tests to run on Travis without random false posivities.
Every couple of builds I get
pl.mg6.agrtt.TestActivityTests > testCanEnterTextAndPressButton[test(AVD) - 4.4.2] FAILED
junit.framework.AssertionFailedError: EditText is not found!
at com.robotium.solo.Waiter.waitForAndGetView(Waiter.java:540)
on all my tests.
I have created a simple project on GitHub to show the issue.
You may see how it builds on Travis. Note build #7 failed after modyfing unrelated file.
I'm suspecting this to be caused by emulator being locked or its sceeen dimmed. I could reproduce this issue on local machine by turning connected device's screen off and then running
./gradlew connectedAndroidTest
After modyfing tests I got a different error message, which is somewhat more informative, so I'm adding it just in case someone tries to find a solution:
pl.mg6.agrtt.TestActivityTests > testCanFindViewsEnterTextAndPressButton[test(AVD) - 4.4.2] FAILED
junit.framework.AssertionFailedError: Click at (160.0, 264.0) can not be completed! (java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission)
at com.robotium.solo.Clicker.clickOnScreen(Clicker.java:106)
While the root cause of this problem is still unknown to me, after some investigation and with a help from Robotium's author Renas Reda I could confirm what I initially suspected that emulator indeed locks itself.
A workaround I'm using now is this code put in setUp method:
getInstrumentation().runOnMainSync(new Runnable() {
#Override
public void run() {
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
}
});
Robotium discards invisible views when using enterText(int, String). Instead use getView(int) of Solo to use resulting view in enterText(View, String).
Like this:
public void testCanEnterTextAndPressButton() {
solo.enterText(((EditText) solo.getView(R.id.editText1)), "my login");
solo.enterText(((EditText) solo.getView(R.id.editText2)), "my password");
solo.clickOnView(solo.getView(R.id.button));
}
And if the device screen is locked Robotium fails to run those instructions you gave. You might want to disable screen locking.
By code above my tests pass.
Your guess is probably right. One way to be sure that it is is to catch the exception that is thrown and call
solo.takeScreenshot("screenshotFileName");
and then take a look at the screenshot that is saved to your phone's SD card to see what your phone was doing at the time of the error.
I solved this problem by turning on the device's "Stay Awake" setting so it won't sleep while recharging.
In Eclipse, I notice that Logcat only retains a few dozen entries and deletes the older ones as soon as a new one come in. Is there a way to prevent this? I need my app to run for a long time and not lose any entries because my app eventually hangs or crashes after a few days, and I want to see if something in Logcat has been recorded.
I am not sure if this is the most elegant solution to the problem, but you can always increase the LogCat message size in Eclipse.
Window -> Preferences -> Android -> LogCat -> Maximum number of LogCat messages to buffer
The default is 5000, I believe. You can set it to be very high if you are planning to run your application for a long time.
i think you need to increase this show image
Here's a better solution:
Set the Default Uncaught Exception Handler. Whenever the app crashes, this will be called with the exception. Simply write a log entry saying it crashed then dump the logcat to a file. Finally, make sure you re-throw the exception to make sure the app crashes and funky things don't happen. Note: This is per thread, keep that in mind.
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
#Override
public void uncaughtException(Thread thread, Throwable ex) {
Log.e("TAG", "---My app crashed just now---", ex);
//TODO: Dump logcat to file
throw new RuntimeException(ex);
}
});
if you want to keep your app running for days.. its better you capture your logs from adb shell.
the common shell command would be :
logcat -c \\ to clear previous logs
logcat -v time>yourLogs.txt & \\ to capture fresh logs