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

com.janeluo.jfinalplus.interceptor.syslog.DefaultLogProccesor Maven / Gradle / Ivy

There is a newer version: 2.2.0.r3
Show newest version
package com.janeluo.jfinalplus.interceptor.syslog;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;
import org.apache.commons.beanutils.BeanUtils;

import java.util.Map;
import java.util.Set;

public class DefaultLogProccesor implements LogProcessor {

    @SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
    public void process(SysLog sysLog) {
        Map map = null;
        try {
            map = BeanUtils.describe(sysLog);
            map.remove("class");
        } catch (Exception e) {
            e.printStackTrace();
        }
        Record record = new Record();
        record.setColumns(map);
        System.out.println(record);
//        Db.save("syslog", record);
    }

    @Override
    public String getUsername(Controller c) {
        return c.getSessionAttr("username");
    }

    @Override
    public String formatMessage(String title, Map message) {
        String result = title;
        if (message.isEmpty()) {
            return result;
        }
        result += ", ";
        Set> entrySet = message.entrySet();
        for (Map.Entry entry : entrySet) {
            String key = entry.getKey();
            String value = entry.getValue();
            result += key + ":" + value;
        }
        return result;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy