![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
xyz.ronella.logging:logger-plus
Advanced tools
Additional functionality to logging.
Add the following maven dependency to your project:
Property | Value |
---|---|
Group ID | xyz.ronella.logging |
Artifact ID | logger-plus |
Version | 1.2.0 |
Using gradle, this can be added as a dependency entry like the following:
implementation 'xyz.ronella.logging:logger-plus:1.2.0'
Include the following to your module-info.java:
requires xyz.ronella.logging.logger.plus;
Within your class, you can create an instance LoggerPlus like the following:
private final static LoggerPlus LOGGER_PLUS = new LoggerPlus(LoggerFactory.getLogger(Main.class));
The LoggerFactory class here must be from SLF4J.
There are two sets of log level methods available. One that accepts message as String parameter and the one that accepts an instance of Supplier to generate the message.
String Parameter | Instance of Supplier as Parameter |
---|---|
error(String) | error(Supplier) |
warn(String) | warn(Supplier) |
info(String) | info(Supplier) |
debug(String) | debug(Supplier) |
trace(String) | trace(Supplier) |
The more efficient sets of method to use are the ones that accepts an instance of Supplier that generates the message since it already called the enabled methods (i.e. isErrorEnabled(), isWarnEnabled(), isInfoEnabled(), isDebugEnabled() and isTraceEnabled()).
Use the following syntax for the formatted message.
<LOG_LEVEL_METHOD>(String format, Object ... values)
LOG_LEVEL_METHOD can be one of the following: debug, error, info, trace, warn.
Formatting is done using the String.format method. Hence you can use all the formatting values available with that method.
Example
logger.info("Hello %s", "world")
Having a log entries that you can identify what group (or part of the codes) wrote them is very helpful. For example, if you have an accept method that you wanted it's log entries trackable. You can do it like the following:
public void accept(Boolean mustProvision) {
try(var gLOG = LOGGER_PLUS.groupLog("accept")) {
/*
*
*/
gLOG.info("Processing");
/*
*
*/
}
}
Expect an output similar to the following:
22:26:53.237 DEBUG accept [BEGIN]
22:26:53.239 INFO accept Processing
22:26:54.824 DEBUG accept [END]
Notice that all the log entries made by the accept method has the group name included and with [BEGIN] and [END] marker. The markers will be at DEBUG level. If you wanted to remove the markers, you pass false as a second argument to the groupLog method invocation, like the following:
LOGGER_PLUS.groupLog("accept", false)
Normally, we wanted to catch the actual error stack trace as string into the log file. This can be simplified by the getStackTraceAsString method that accepts an instance of Exception. See the sample usage as follows:
LOGGER_PLUS.error(LOGGER_PLUS.getStackTraceAsString(exception));
If you need some specific functionality of the Logger, you can get an instance of it using the getLogger() method. The instance that you will receive is the one you've passed from the constructor.
package main;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xyz.ronella.logging.LoggerPlus;
public class Main {
private final static Logger LOGGER = LoggerFactory.getLogger(Main.class);
private final static LoggerPlus LOGGER_PLUS = new LoggerPlus(LOGGER);
public static void main(String ... args) {
final var message = "An info logger";
LOGGER_PLUS.info(message::toString); //Using the supplier argument.
LOGGER_PLUS.info("Hello %s", "world"); //Using arguments with format.
}
}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Properties>
<Property name="filename">logs/logger-plus.log</Property>
</Properties>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<RollingFile name="File" fileName="${filename}" filePattern="logs/$${date:yyyy-MM}/logger-plus-%d{MM-dd-yyyy}-%i.log.gz">
<PatternLayout pattern="%d [%t] %-5level %logger{36} - %msg%n"/>
<DefaultRolloverStrategy max="10"/>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Root level="TRACE">
<AppenderRef ref="Console"/>
<AppenderRef ref="File"/>
</Root>
</Loggers>
</Configuration>
module logger.plus.test.main {
requires xyz.ronella.logging.logger.plus;
requires org.apache.logging.log4j;
}
package main;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xyz.ronella.logging.LoggerPlus;
public class Main {
private final static Logger LOGGER = LoggerFactory.getLogger(Main.class);
private final static LoggerPlus LOGGER_PLUS = new LoggerPlus(LOGGER);
public static void main(String ... args) {
final var message = "A logger info";
LOGGER_PLUS.info(message::toString); //Using the supplier argument.
LOGGER_PLUS.info("Hello %s", "world"); //Using arguments with format.
}
}
This project is licensed under the MIT License - see the LICENSE.md file for details
FAQs
Unknown package
We found that xyz.ronella.logging:logger-plus demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.