Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display server Log in Primefaces Log Component

I see it is possible in the docs but can't seem to find a way of implementing it.

 Log API is also available via global PrimeFaces object in case you’d like to use the log component to display your logs.

Using Primefaces 6.2

Primefaces Log Component

Binding Log4J to <p:log id="log" />

like image 642
Kyle Smit Avatar asked Apr 12 '18 11:04

Kyle Smit


People also ask

What is PrimeFaces showcase?

PrimeFaces is a lightweight library with one jar, zero-configuration and no required dependencies.

Is PrimeFaces a JSF?

Primefaces is an open source UI component suite for Java Server Faces (JSF) applications. In this tutorial, we'll give an introduction to Primefaces, and demonstrate how to configure it and use some of its main features.

What is PrimeFaces used for?

PrimeFaces provides the most advanced Client Side Validation for JavaServer Faces and Java EE. It is used to validate data at client side. It is compatible with Server Side Implementation and provides Advanced Bean Validation Integration.

Is PrimeFaces popular?

PrimeFaces is one of the most popular UI libraries in Java Ecosystem and widely used by software companies, world renowned brands, banks, financial institutions, insurance companies, universities and more.


1 Answers

Everything in @Kukeltje's answer is true.

Still, if your end-game is to see your server logs in the front-end of your JSF app, I would do the following:

  1. Add a DB appender to your logging framework so that all logs are written to the database. https://logging.apache.org/log4j/2.x/manual/appenders.html#JDBCAppender https://logback.qos.ch/manual/appenders.html#DBAppender
  2. Create a jsf datatable to view the logs in. https://www.primefaces.org/showcase/ui/data/datatable/basic.xhtml

Initially, I would recommend that you filter the logs when retrieving it from the DB to only show the newest ones in the table, otherwise the table might be too big to load within a reasonable time. As a permanent solution, I would recommend that you implement the LazyDataModel https://www.primefaces.org/showcase/ui/data/datatable/lazy.xhtml

It can be very handy to be able to filter and /or sort by log severity, time, and all the fields supported by by your logging framework.

Non related: Splunk has a universal forwarder utility that can submit a copy of your logs to a splunk server so that you can analyze your logs in near realtime. https://www.splunk.com/en_us/download/universal-forwarder.html

like image 162
Max Avatar answered Sep 19 '22 16:09

Max