I want to change the log output settings of UtilLoggingJdbcLogger

1. Use java.util.logging.config.file

Doma2 uses the JDBCLogger interface for log output, and UtilLoggingJdbcLogger is provided as an example of its implementation. Since this UtilLoggingJdbcLogger adopts JUL (java.util.logging) for log output, the system property java.util.logging.config.file can be used for the settings related to log output.

logging.properties


handlers= java.util.logging.ConsoleHandler, java.util.logging.FileHandler

java.util.logging.FileHandler.level = INFO
java.util.logging.FileHandler.pattern = logging_by_propertiesfile.log
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter

java.util.logging.ConsoleHandler.level = INFO
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

For example, if you have the above logging.properties and want to set it to UtilLoggingJdbcLogger, you can do it with -Djava.util.logging.config.file = \ path \ to \ logging.properties. is.

2. Use java.util.logging.config.file

You can also extend UtilLoggingJdbcLogger yourself without using the system properties file.

First, create a class that inherits UtilLoggingJdbcLogger. At this time, set the log output for super.logger (instance of JUL).

MyUtilLoggingJdbcLogger.java


public class MyUtilLoggingJdbcLogger extends UtilLoggingJdbcLogger {
    public MyUtilLoggingJdbcLogger() {
        try {
            Formatter formatter = new SimpleFormatter();

            Handler consoleHandler = new ConsoleHandler();
            consoleHandler.setFormatter(formatter);
            consoleHandler.setLevel(Level.INFO);

            Handler fileHandler = new FileHandler("logging_by_class.log");
            fileHandler.setFormatter(formatter);
            fileHandler.setLevel(Level.INFO);

            super.logger.addHandler(consoleHandler);
            super.logger.addHandler(fileHandler);
        } catch (SecurityException | IOException e) {
            e.printStackTrace();
        }
    }
}

After that, set to use the MyUtilLoggingJdbcLogger created in the Config class of Doma2. Specifically, just override the getJdbcLogger method and return the MyUtilLoggingJdbcLogger instance.

AppConfig.java


@SingletonConfig
public class AppConfig implements Config {
    private final JdbcLogger logger;

    private AppConfig() {
        logger = new MyUtilLoggingJdbcLogger();
    }

    @Override
    public JdbcLogger getJdbcLogger() {
        return logger;
    }
}

Environmental information

Recommended Posts

I want to change the log output settings of UtilLoggingJdbcLogger
I want to output the day of the week
I want to simplify the log output on Android
I want to change the value of Attribute in Selenium of Ruby
I want to var_dump the contents of the intent
I want to know the answer of the rock-paper-scissors app
I want to display the name of the poster of the comment
I want to be aware of the contents of variables!
I want to return the scroll position of UITableView!
[Rails] [bootstrap] I want to change the font size responsively
(ยด-`) .. oO (I want to easily find the standard output "Hello".
I want to expand the clickable part of the link_to method
When you want to change the MySQL password of docker-compose
I want to narrow down the display of docker ps
[Ruby] I want to reverse the order of the hash table
I want to temporarily disable the swipe gesture of UIPageViewController
I want to change the color of the upper control navigation bar (Control menu) in Liferay 7 / DXP
I want to understand the flow of Spring processing request parameters
The story of Collectors.groupingBy that I want to keep for posterity
I want to limit the input by narrowing the range of numbers
I want to control the default error message of Spring Boot
I made a tool to output the difference of CSV file
Output HTTP header of google-http-client to log
Output of the book "Introduction to Java"
[Ruby] I want to output only the odd-numbered characters in the character string
I want to display the number of orders for today using datetime.
[Ruby] I want to extract only the value of the hash and only the key
I want to pass the argument of Annotation and the argument of the calling method to aspect
I want to get the field name of the [Java] field. (Old tale tone)
I want you to use Enum # name () for the Key of SharedPreference
[Apache Camel] Easy output of throughput to log
Change the timezone of the https-portal container to JST
Output of how to use the slice method
I want to truncate after the decimal point
I want to get the value in Ruby
[RxSwift] I want to deepen my understanding by following the definition of Observable
I want to get the value of Cell transparently regardless of CellType (Apache POI)
I want to separate the handling of call results according to the API caller (call trigger)
I want to see the contents of Request without saying four or five
I want to recursively get the superclass and interface of a certain class
Format of the log output by Tomcat itself in Tomcat 8
I want to call a method of another class
[Java] I want to calculate the difference from the date
I was addicted to the record of the associated model
I tried to summarize the state transition of docker
Convert the array of errors.full_messages to characters and output
I want to judge the range using the monthly degree
I tried to reduce the capacity of Spring Boot
I want to dark mode with the SWT app
[Rails] How to change the column name of the table
I want to call the main method using reflection
[Rough commentary] I want to marry the pluck method
I want to add a delete function to the comment function
I want to output the character number from the left where an arbitrary character string appears.
[Ruby] I want to make a program that displays today's day of the week!
Rails The concept of view componentization of Rails that I want to convey to those who want to quit
[rails] After option useful when you want to change the order of DB columns
I tried to create a log reproduction script at the time of apt install
I want to change the path after new registration after logging in with multiple devises.
I want to morphologically analyze the log in the DB and put it in the DB to classify messages 1
[Active Admin] I want to specify the scope of the collection to be displayed in select_box