I have a Swing-based application that logs all messages to text files through slf4j with logback underneath.
I'd like to add a feature to show all messages at a certain level(e.g. fatal) logged in the current session on demand, say in a JTable.
Does slf4j provide API that lets you access historical log messages, preferably filtered by level or time?
Try to use Logback, there is a ch.qos.logback.classic.db.DBAppender class that you can use as an Appender to your fatal errors. You can define your own data structure, just provide the SQL Insert statement. Also, other variants of this DBAppender are provided, so you can choose when do you want to customize the behavior.
The next thing is that you tie your appender to those loggers that you want to log.
Finally you can manage your logged data within your application (filter, purge/archive) just like your application business data.
Related
I use HSQLDB on OSGI framework. And it is common solution to use pax-logging that support many logging frameworks (java logging, slf4j, jboss logging etc).
I don't have problems with pax-logging, however, I have problems with HSQLDB logging messages. HSQLDB logging component is very tricky - some messages go to pax-logging system, some go to console.
Could anyone explain what messages where must go and why.
There are separate logging components in HSQLDB.
The Server uses separate writers for log and error messages. The logs default to stdout and stderr but you can set each one to use a custom PrintWriter.
The optional SQL log is always a file. It can be turned on and off live for checking the SQL statements being executed.
The optional event log is a file or an external logging framework. The latter is used when the database is in-process in an application. In both configurations, it reports general persistence events at different levels of detail selected by the user.
I have 4 appllications (ear) on my WAS. I need them to write in SystemOut.log some sign. I.e each application must write to log file its own sign. For example:
[16.01.17 3:50:05:592 GMT+05:00] ADMIN 000005e0 SubsystemMess I com.docflow.core.integration.jms.SubsystemMessageListener onMessage_aroundBody0 Subsystem integration message ID:f5392a5ec3b3f41502095b00110a134f0000000000000001 of type DP_EKS_BANK_GUARANTEE_RECEIVED process finished
Here ADMIN is sign of the application.
How i can do that?
It's not possible to adjust the default logging format in this way. Your options would be to use java.util.logging.Logger with a particular name (to replace the "SubsystemMess" part) or to use a separate logging package and configure it to log to a separate file.
Look at log4j and configuring each app's log4j to go to a different file.
Log4j's file appender can be configured to also include timestamp and more.
The only catch is you can't configure it from WAS's admin console then.
Note that java.util.Logger writes to the trace.log. If you use a different logger name, it will list as such in the same trace.log file. Upside is you can now configure it from the admin console.
One potential solution could be to switch to HPEL logging. Then you could query log entries for your given application using logviewer, like:
logViewer.sh -includeExtensions appName=PlantsByWebSphere
I know that it is not exactly what you are looking for, but maybe it will be sufficient for your needs.
I would like to inject a piece of information into all messages logged by anything, including third-party code. The reason is that, in our web-services-oriented application, requests come in with unique IDs and I want those unique IDs to be attached to all log messages that occur while processing a request, to assist in later analysis. I am already tracking the "current request" using ThreadLocal<> techniques, so I have the ability to fetch the "current request" from anywhere.
To that end, I would like to configure log4j such that I can inject the requestID into messages before they reach the root logger (or appender?). I know that I can just make a whole new Appender that implements append() and does whatever it wants with the output, but that's not what I'm asking for. I want output to ultimately go to whatever appender is configured at startup, but with the additional information attached.
I am using log4j 1.x, but if a move to log4j 2.x or using slf4j makes this significantly easier, I would consider it.
I am very much new to multi-tenancy. We have an application based on Java, Spring, Hibernate/JPA etc. which doesn't support multi-tenancy.
Now, we want to convert that application into multi-tenant one. I have read about multi-tenancy and even wrote one standalone application using hibernate with separate schema approach. Link referred is here.
I think about the logging part which is bound to be changed now as log files will be maintained per tenant(client) now. So, for each tenant a separate log file will be there.Also, log file for a particular tenant shouldn't be accessed by another tenant.
Is there any logging API specific to support multi-tenancy? If not, how should i go ahead with implementing logging in multi-tenant application? What should be taken care of while implementing logging in multi-tenant application.
you can use MDC (mapped diagnostic context) support to route logging for each tenant into a separate file/dir/whatever.
you can read up on the concept here. it exists in slf4/logback and log4j
simply put, you set some property like tenantName in the MDC at the beginning of every request processing according to the specific tenant making the request and then use this property in your logging configuration to determine the log file into which log messages are written.
I'm creating a Java JWS application. That application is logging some useful (for me) debug stuff to the system.out. Now, application will be used by 3rd party and i don't want them to see debug log.
My idea is following: application should write all the status messages to the custom stream. If logged user is "dev", then custom stream should be "merged" with system.out and console should print all new and prior (already existing) data from my custom stream. If logged user is somebody other than "dev", all status messages will remained logged into the custom stream and won't be visible in the console.
How could i achieve this functionality?
You can use Apache's log4j or commons logging with cutom filters. There's a Logger that comes with the JDK. You can also create a custom logger considering the types of users. You can direct the logs in proper output destination depending on the user type. All logs should be stored somewhere regardless of user type to monitor though.