All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.seahuang.log.formatter.LogFormatterSupport Maven / Gradle / Ivy

There is a newer version: 1.3.0
Show newest version
package com.github.seahuang.log.formatter;

import org.aspectj.lang.JoinPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.GenericTypeResolver;

import com.github.seahuang.log.Level;
import com.github.seahuang.log.duration.DurationFormatter;
import com.github.seahuang.log.formatter.type.TypeFormatterAdaper;

public abstract class LogFormatterSupport implements LogFormatter {
	@Autowired
	protected TypeFormatterAdaper typeFormatterAdapter;
	@Autowired
	protected DurationFormatter durationFormatter;
	
	@SuppressWarnings("unchecked")
	protected Class targetType = (Class)GenericTypeResolver
		.resolveTypeArgument(this.getClass(), LogFormatter.class);

	public Class getTargetType() {
		return targetType;
	}
	
	public String format(Level level, JoinPoint jp, T throwable, Long milliseconds){
		if(milliseconds != null){
			return format(level, jp, throwable) + " in " + durationFormatter.format(milliseconds);
		}
		return format(level, jp, throwable);
	}
	
	protected abstract String format(Level level, JoinPoint jp, T throwable);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy