The World’s Largest Online Community for Developers

'; How to get values from logs into java list? <hibernate> - LavOzs.Com

Is this possible to take that values from console: enter image description here and save them into java list/map?

I printed that logs in that way:

My query:

public String executeSQL(String[] split){
    SessionFactory hibernateFactory = someService.getHibernateFactory();
    String message = null;
    int rows = 0;
    EntityManager entityManager = hibernateFactory.createEntityManager();
    EntityTransaction utx = entityManager.getTransaction();
    for (int i = 0; i < split.length; i++) {
        String query = split[i];
        try {
            Query query1 = entityManager.createNativeQuery(query);
            rows = query1.executeUpdate();
                resultList = query1.getResultList();
            catch(Exception e){
            message = "Success \n{ ["+rows+"] <--- affected rows}";
        }catch (PersistenceException e){
            message = (((SQLGrammarException)e.getCause()).getSQLException()).getMessage();
    return message;

I know how to save values into list as you can see but i can't extract columns... because there is no information about columns name. In that logs columns have names and also columns have type, that informations would be usefull for me.

As an option how it could be implemented is Logback Appender Once you will have logs into appender you can implement filtering and whatever you need.

1.Add dependency to logback-classic


2.Add logback.xml to resources

    <appender name="list" class="com.test.ListAppender"/>
    <root level="info">
        <appender-ref ref="list"/>

3.Implement Appender class

package com.test;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;

import java.util.LinkedList;
import java.util.List;

public class ListAppender extends AppenderBase<ILoggingEvent> {

    private static List<ILoggingEvent> eventList = new LinkedList<>();

    protected void append(ILoggingEvent event) {

    public List<ILoggingEvent> getEventList() {
        return eventList;

4.Test your code

package com.test;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main {
    private static final Logger logger = LoggerFactory.getLogger(Main.class);

    static ListAppender listAppender = new ListAppender();

    public static void main(String[] args) {"Hello World");
        listAppender.getEventList().forEach(entry -> System.out.println("print log from list:" + entry));
Is Java “pass-by-reference” or “pass-by-value”?
How do I efficiently iterate over each entry in a Java Map?
Does a finally block always get executed in Java?
How do I call one constructor from another in Java?
How do I read / convert an InputStream into a String in Java?
How do I generate random integers within a specific range in Java?
How to get an enum value from a string value in Java?
How do I determine whether an array contains a particular value in Java?
How do I convert a String to an int in Java?
How to create a memory leak in Java?