We've added logging to our Java SDKs. Logging-enabled SDKs will log important events in the API lifecycle for troubleshooting or debugging later.
Enable Logging in SDKs
By default, APIMatic CodeGen does not add the ability to perform logging in SDKs.
To turn on this feature, just switch on the Enable Logging flag in Code Generation Settings.
How Java does Logging
Our Java SDKs use Simple Logging Facade for Java (SLF4J). From SLF4J website:
The Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction for various logging frameworks (e.g.
java.util.logging
,logback
,log4j
) allowing the end user to plug in the desired logging framework at deployment time.
Configuring SLF4J
SLF4J requires a logging backend to be added by installing a separate dependency.
For example, to use Log4J, you must add the following dependency to your application's pom.xml
:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.7</version>
</dependency>
Now you just need to add a configuration file such as src/main/resources/log4j.properties
.
Here’s a sample configuration:
log4j.rootLogger=TRACE, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd'T'HH:mm:ss.SSS} %-5p [%c] - %m%n
Using Other Logging Frameworks
To learn how to add other logging frameworks, checkout this link: