Is there a way to get the Log of Kryonet? - java

I want to get the Console Log of the Kryonet as String so that i can display it in a TextArea.
Now my question, is there a way to do it?
I'm stuck at this problem..
Any suggestions would be so much appreciated.
Thanks

From the Kryonet documentation:
KryoNet makes use of the low overhead, lightweight MinLog logging library.
So looking at MinLog, which is just one source file, you just need to extend Logger to override the print method, and then call
Log.setLogger(new DifferentLoggerImplementation());

Related

cups4j settings or attributes using cups

I am using Cups4j and try to figure out, how to use the impressions to send attributes for the job, like colorprint or especially the finisher to staple the printjob.
If i setup the default printsettings # my Docker Cups-server, the settings will be acceptet in every job. i dit this to make sure, my Printer supports it via ipp.
I use this Documentation to get my job-attributes work, but it wont.
attributes.put("finishings", "staple:enum:4");
attributes.put("job-attributes", "finishings:enum:4");
attributes.put("job-attributes", "finishings:enum:4#staple-top-left:boolean:true");
i tried these sets and many more already. Maybe someone can help with it.
The rest of my method looks similar to the cups4j basic usage example.
I have to use the Java library, because its for a microservice-strucure thats already widley implemented.
Thank u!

logging data using log4j into a TextArea is there an easy way to do this

I am logging messages via log 4 j logger and I want to somehow get this stream of data and display it in a JTextArea for display. Is there any easy way to do this?
thanks you
Never tried it myself, but most straight-forward way would be to implement org.apache.log4j.Appender, so your implementation's constructor would accept instance of GUI object where you want to show log entries.
Check it out here for solution and suggestion as well jtextarea-as-listener-for-log4j-logger . I hope it's helpful.

Getting back to the console in Java

I'm writing a Java class which plugs into a larger framework. Somewhere upstream, the code is redirecting System.out to somewhere other than standard out, but I really want to print a debugging message to standard out. Is there a way for me to get a hook back into standard out?
Perhaps an easier solution is to use System.err instead of System.out for debugging messages? It would be a lot easier and would not introduce any side-effects of that redirection.
Why not use System.err?
The most straightforward solution I see is just store System.out somewhere in your class before calling the library.
After looking around a bit, you should be able to use System.console().printf(...).
You can simply write:
System.setOut(System.out);

Simple logger, how to?

I want to write a default Logger for my application. Currently I am using the default Java API Class Logger .
I was wondering if it's possible to format my logs to look somthing like this:
[level] [dd:MM:YYYY] [hh:mm:ss] message
The logger should also be able to print the messages into the System.out and into a file ?
Where should I look for this functionality ?
Can you please give me some code snippets ?
Extend java.util.logging.Formatter, overide format(LogRecord record) method.
LogRecord contains all data you need to build up your custom message.
Then change standard SimpleFormatter in logging.properties file in properties
java.util.logging.ConsoleHandler.formatter/java.util.logging.FileHandler.formatter
to your formatter.
Have you considered using Log4j?
If that is not an option for you, you could change the output format of the logger you are currently using. The following article shows a way to do just that and provide a custom formatter for the java.util.logging API.
I should also mention that, unless doing this to learn and expand your knowledge, or beeing forced by ugly circumstances, it is never a good idea to write your own logger implementation.
Check this question. I think I was asking a similar one.
A simple log file format
EDIT:
As I wrote there, I found a tool called LogExpert. You can write to a file in a format like "level;dd:MM:YYYY;hh:mm:ss;message" and view it with this tool, changind columnizer to CSV.

Is there a Log4J Layout/Formatter that prunes Stack Traces for exceptions?

I'm looking for a Log4J Layout/Formatter that helps me prune stack-traces in exceptions a little better than the defaults. That the stack-execution is somewhere below main() is quite obvious and unnecessary for me to know, and that the exception occurred deeply within some other library is really nothing I can do too much about.
What I would like is a Layout that trims the stack-trace to, say the last 5 method-calls of method within my own code, identified by containing jar-file, package or something else.
Is there something along these lines, or do I have to write some magic myself?
I asked a similar question (about completely suppressing the stack trace a while back.
Unfortunately, there is no setting for that, you need to subclass PatternLayout to do it.
I tried looking for this as well but didn't find anything satisfactory so I wrote up a custom ThrowableRenderer which prunes out extraneous stack frames. I've open sourced the code for others to use. Check out my blog post on it; you can find a link to the code there.
The "ex" or "exception" conversion word in logback-classic (log4j's successor) supports printing the specified number of stack trace lines. The "ex" conversion word is documented with the rest of conversion words. You need to scroll down a little.
If you need further information on this topic, please contact the logback-user mailing list.
There are three ways to do this:
Find a library or code that someone else did
Write it yourself (extend/implement)
Use the default Layout, but prune the exception's stack before passing it to logger
You can write a custom Appender that has the special logic you need. That might be a good way to go.

Categories