Android. Alternative way for logging Application Output - java

I'm currently working on an App, which writes millions of lines to logcat (debugging output). I catch all these Informations (at runtime) by filtering the logoutput (of logcat) and write all the information in a file (redirect locat to a file). Unfortunately this takes very long and therefore the app runs very slow.
Now I wanted to ask, if there is a way, how i could get all these information faster. Is it faster, instead of writing the debugging information to logcat, to directly write the information to a textfile (on the device), or does anyone know a better way to gather these lines more efficient??!.
Thanks for reading,
greetings B.

There exist multiple logging tools. I recommend having a look at Timber trees.
But please listen on Jake Wharton:
Every time you log in production, a puppy dies.
Here is a list of logger tools from awesome-android:
logger - Simple, pretty and powerful logger for android
timber - A logger with a small, extensible API which provides utility on top of Android's normal Log class.
LoggingInterceptor - An OkHttp interceptor which pretty logs request and response data.
Bugfender - Upload your logs and check them online, specially made for mobile
EzyLogger - Simple Lightweight logger
Logback Android - Logback port to Android which provides a highly configurable logging framework for Android apps.
Punt - cli tool that makes adb logcat better

Related

Where Does Azure Functions Store Logs And How Can I View Them?

Whilst my Azure Function app is running I can stream the logs and see everything I need to.
Later on the log stream is empty, probably because it is a stream of live logs and not a log viewer.
Where are the logs stored and how do I see them?
When you created your functions app you should have also linked it to an Application Insights workspace- this is where logs are stored. If you aren't sure which workspace it is, then you can usually find the connection string in the app settings.
Each functions's invocation logs should also link to the relevant data in App Insights- that is a good place to start if you aren't familiar with how to query AI logs.
Which table the data is stored in depends on the information that you are looking for- errors will be in the exceptions table for example. It is worth noting that Functions makes use of the customEvents and customMetrics tables quite heavily so there will be a quite a bit of useful data landing in those two tables.

Best practices for writing a log for a Java server

I'm looking for some advice on best/common practices with writing a log for a game server I wrote in Java (first time with server/client concept and I've never done anything with logging). I've tried some Googling, but the keywords involved are kind of vague and not coming up with any answers to my questions.
I have a server with users, game lobbies, and games. I think that I should create a log to keep a history of everything that happens on the server. And in this log I think I should record status changes of both the server itself (startup, shutdown, commands being processed), and socket connections (new/lost clients, incoming/outgoing messages).
I'm not sure if that's the best thing to do, or instead/also have a log with more human readable messages like "Bob781 joined lobby #4." or "microman12 beat sun44 in a game."
Should I write logs to the console or to a file? (2 separate files?)
What formats are best or most commonly used? Should they be the same formats?
I've come across the "Common Log Format", is this the best format choice for socket connections? Can it be used for the server statuses?
Should I use something in java.util.logging or just output the strings myself?
You always want to look for existing solutions before starting from scratch. When you use/create the logging, I would suggest the following tips based on my experience
Make sure you can reliable retrieve the logs whenever you might need them.
Make it easy to find a log file based on what you're looking for. For example if there is a problem with a specific game lobby, you should be able to easily navigate to the file or directory of files that pertain to that game lobby in question. Nothing worse than having to parse a huge gigantic log file...
Make each logging message meaningful. Don't just log stuff for the sake of logging. You will want to be able to read a log message and know relatively where in the server code that message is coming from. This will help later down the road when you run into bugs in your server code.
Have each log message time stamped at the point it's created and not when it's written to the log file.

Collect exception reports in Java application

I'm currently maintaining a Desktop Java application that has a small to medium user base. I often get some pretty useless mails saying that "something went wrong" and I'm left digging through the source code, often unable to reproduce the problem.
Now I'm wondering if there is a library that would allow me to collect Exceptions when they happen, present a small dialog to the users and if/when they agree, post the stack trace to my webserver. Basically what I'm looking for is something similar to Application Crash Report for Android (ACRA), but for desktop Java applications.
If you are using SLF4J and Logback, you can configure an appender to send detailed error reports to a Ctrlflow Automated Error Reporting server (which offers filtering and aggregation of incoming reports + dashboards + email digest). This blog post has all the information on how to configure Logback accordingly.
If you want to present your user with a confirmation dialog first, you may have to extend the existing appender, though – unless your “Desktop Java application” is an “Eclipse Rich Client Platform applications.” In that case the work has already been done for you. See this webinar for more information.

Java app startup with computer and be able to see system.out.println?

I wrote a simple Java app which I have placed in the start up folder of my programs which makes the program starts when the computer starts up. what is the easiest way to make it open a command line or something which I can see the System.out.println results instead of just running in the background?
You should familiarize yourself with logging frameworks such as logback and log4j. Instead of using System.out.println you use some special API and the logging library redirects all messages to preconfigured appenders like console or file.
In your case you can configure your application to log on console while developing and switch to file when configuring an application to run from startup.
This won't really open a new command line window on startup, but instead it will store all messages to some predefined file on disk - which is actually even better.
You can use Log4j API for logging the details with the predefined outputs. It is far better then using SOP. Because it is light waighted and also very simple to configure the logs in the other files with the output format whichever you want to make.
http://logging.apache.org/log4j/1.2/ Go to this url where you can find log4j api available.
Hope this work for you
Enjoy !!!

Best way to interact with application logs output from log4j (while also are being updated by application)

May be it is simpler than I think but I am confused on the following:
I want to be able to present to a user (in a graphical interface) the logs produced by Log4j.
I could just read the files as it is and present it, but I was wondering if there is a standard way to do it to so as to also get any updates that happen at the same time from the other parts of the application that log concurrently.
The log4j files could be multiple i.e. rolling appender
Also the presentation could be while there is no logging happening.
I.e. view of logs up to date
UPDATE:
I am constraint to Java 6
You can use Java 7's NIO2 libraries to get notified when one of multiple files get's modified in a directory, and reread & display it:
http://blogs.oracle.com/thejavatutorials/entry/watching_a_directory_for_changes
Have you tried the following tools :
Chainsaw
Xpolog
Perhaps add a database appender (JDBCAppender) and present the log entries from that?
Fro the official documentation of log4j:
Is there a way to get log4j to automatically reload a configuration file if it changes?
Yes. Both the DOMConfigurator and the PropertyConfigurator support automatic reloading
through the configureAndWatch method. See the API documentation for more details.
PropertyConfigurator#configureAndWatch
DOMConfigurator#configureAndWatch
For the on-demand reload of log4j config using GUI I would suggest expose it via a servlet in your J2EE application so that whole file can be edited in a web page (text area may be) and once saved you can overwrite your existing log4j file and reload the log4j config.
Maybe you could think about more "OS-level" solution.
I don't know if you are using win or linux, but on linux there is this realy nice command "tail".
So you could use ProcessBuilder to create OS process which goes something like "tail -f yourLogFile.txt".
And then read the OutputStream of the returned Process. Reading the stream will block waiting for new output from the process to be available, and will immediately unblock when such is available, giving you immediate feedback and possibility to read the latest changes of the log file.
However, you might have problems shutting this process down from Java.
You should be able to send SIGTERM signal to it if you know the process id. Or you could start a different process which could lookup the id of the "tail" process and kill it via "kill" command or something similar.
Also I am not sure if there is similar tool available on windows, if this is your platform.
If you write your own simple appender and have your application include that appender in your log4j configuration, your appender will be called whenever events are written to other appenders, and you can choose to display the event messages, timestamps, etc. in a UI.
Try XpoLog log4j/log4net connector. It parses the data automaticly and has predefined set of dashboards for it:
Follow the below steps
Download and install XpoLog from here
Add the log4j data using the log4j data connector from here and
deploy the log4j app here

Categories