'How to disable time and date info in console logs Spring

enter image description here

How to disable time and date for console logs ? Is there any way ? Screen is not wide enough and this takes unnecessary place . Really annoys me



Solution 1:[1]

If you are using spring-boot, then by default it is using logback as it's logging mechanism. My suggestion is for you to do changes via logback.xml file in-order to change the log pattern.

It is a easy fix and create logback.xml file in your project's resources directory. I will mention below a sample xml for that. You can use my example and it will solve your issue.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <!-- Appender for logging within the console -->
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <!-- Pattern of the console logging -->
 
            <!-- %d - Date and time -->
            <!-- %thread - Thread name -->
            <!-- %level - Log level (%p also works) -->
            <!-- %logger - Logger name -->
            <!-- %msg - Log message (%m also works) -->
            <!-- %n - Line separator -->
 
            <!-- %d{yyyy-MMM-dd HH:mm:ss} - Custom Date/Time format -->
            <!-- %-5level - Left justification flag - Use spaces for right padding if characters < 5 -->
            <!-- %logger{36} - Abbreviate -->
 
            <!-- [Date and time] [Thread] LoggingLevel : LoggerName - Logging message -->
            <pattern>[%thread] %-5level: %logger - %msg%n</pattern>
        </encoder>
    </appender>
 
    <!-- Logging levels are, in order of precedence -> TRACE, DEBUG, INFO, WARN and ERROR -->
    <root level="info">
        <appender-ref ref="STDOUT"/>
    </root>
 
</configuration>

Above logback.xml contains more comments for better understanding. You can control the pattern of your logs as you wish via modifying the <pattern>.

Hope this solves the issue.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1