Home | Tutorials | Smart-Cloud | Smart-EIS | License | FAQ | Contact

Last Updated: March 12, 2021

Steps:

  1. Create Maven project with the following pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.jalalkiswani</groupId>
	<version>4.0.4</version>
	<artifactId>smart-cloud-util-examples</artifactId>
	<dependencies>
		<dependency>
			<groupId>com.jalalkiswani</groupId>
			<artifactId>smart-cloud-util</artifactId>
			<version>4.0.8</version>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.8.1</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

If you are using Eclipse, be sure to refresh your project (select your project→ right click→ Maven→ Update Project)

  1. [Optional] Create log config file at src/main/resources/logback.xml with the following contents:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Check full configurations documentation at: http://logback.qos.ch/manual/configuration.html -->
<configuration debug="false" scan="true" scanPeriod="60 seconds" packagingData="true">
	<!-- <shutdownHook/> -->
	<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
	<contextName>Smart-Cloud</contextName>
	<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
		<layout class="ch.qos.logback.classic.PatternLayout">
			<Pattern>
				%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
			</Pattern>
		</layout>
	</appender>

	<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<file>logs/jk.log</file>
		<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
			<!-- rollover daily -->
			<fileNamePattern>logs/jk-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
			<!-- each file should be at most 100MB, keep 30 days worth of history, but at most 10GB -->
			<maxFileSize>100MB</maxFileSize>
			<maxHistory>30</maxHistory>
			<totalSizeCap>10GB</totalSizeCap>
		</rollingPolicy>
		<encoder>
			<pattern>%d [%thread] %level %mdc %logger{35} - %msg%n</pattern>
		</encoder>
	</appender>

	<!-- Levels are: TRACE, DEBUG, INFO, WARN, info, ALL or OFF -->
	<logger name="com.jk" level="info" />

	<logger name="com.jk.util.exceptions" level="debug" />
	<logger name="org.springframework" level="info" />
	<logger name="org.springframework.security.web" level="info" />
	<logger name="com.jk.util.factory.spring" level="info" />
	<logger name="org.hibernate" level="info" />
	<logger name="log.org.jboss.logging" level="info" />

	<logger name="javax.enterprise" level="info" />
	<logger name="javax.faces" level="info" />
	<logger name="org.primefaces" level="info" />
	<logger name="com.sun.faces" level="info" />
	<logger name="org.apache.catalina" level="info" />
	<logger name="org.apache" level="info" />
	<logger name="com.mchange" level="info" />
	<logger name="org.omnifaces" level="info" />

	<root level="trace">
		<appender-ref ref="CONSOLE" />
		<appender-ref ref="FILE" />
	</root>

</configuration>
  1. Create Main class with the following contents:

package com.app.logger;

import com.jk.util.logging.JKLogger;
import com.jk.util.logging.JKLoggerFactory;

public class JKLoggerExample {
	public static void main(String[] args) {
		JKLogger logger=JKLoggerFactory.getLogger(JKLoggerExample.class);
		String value="Dummy value";
		logger.trace("Print trace message with value {}", value);
		logger.debug("Print debug message with value {}", value);
		logger.info("Print info message with value {}", value);
		logger.error("Print error message with value {}", value);
	}
}

Thats it, now run your App class, and you should see something line this:

logging

Full example source-code can be found at https://github.com/smartapi-com/smart-cloud-util


Home | Tutorials | Smart-Cloud | Smart-EIS | License | FAQ | Contact