// Path: teemo/src/main/java/core/util/IpUtil.java
// public class IpUtil {
// 
//     /**
//      * 从Spring上下文中获取Request，然后从Request对象中获取IP
//      * @return {@link String}
//      */
//     public static String getIp() {
//         RequestAttributes requestAttributes = null;
// 
//         try {
//             requestAttributes = RequestContextHolder.currentRequestAttributes();
//         } catch (Exception e) {
//             //ignore  如unit test
//         }
// 
//         if (requestAttributes != null && requestAttributes instanceof ServletRequestAttributes) {
//             return getIpAddr(((ServletRequestAttributes) requestAttributes).getRequest());
//         }
// 
//         return "unknown";
//     }
// 
//     /**
//      * 从Request获取IP
//      * 如果请求时通过反向代理过来的，需要在从代理字段中获取真实IP
//      * @param request
//      * @return {@link String}
//      */
//     public static String getIpAddr(HttpServletRequest request) {
//         if (request == null) {
//             return "unknown";
//         }
//         String ip = request.getHeader("x-forwarded-for");
//         if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
//             ip = request.getHeader("Proxy-Client-IP");
//         }
//         if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
//             ip = request.getHeader("X-Forwarded-For");
//         }
//         if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
//             ip = request.getHeader("WL-Proxy-Client-IP");
//         }
//         if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
//             ip = request.getHeader("X-Real-IP");
//         }
// 
//         if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
//             ip = request.getRemoteAddr();
//         }
//         return ip;
//     }
// }


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import core.util.IpUtil;

/**
 * Copyright (c) 2016- https://github.com/beiyoufx
 *
 * Licensed under the GPL-3.0
 */
package com.teemo.core.util;


/**
 * @author yongjie.teng
 * @date 16-11-2 下午3:27
 * @email yongjie.teng@foxmail.com
 * @package com.teemo.core.util
 */
public class UserLogUtil {
    private static final Logger USER_LOGGER = LoggerFactory.getLogger("USER_LOG");

    /**
     * <p>记录格式 [ip][用户名][操作][错误消息]<p/>
     * 注意操作如下：
     * loginError 登录失败
     * loginSuccess 登录成功
     * passwordError 密码错误
     * changePassword 修改密码
     * changeStatus 修改状态
     *
     * @param username
     * @param op
     * @param msg
     * @param args
     */
    public static void log(String username, String op, String msg, Object... args) {
        StringBuilder s = new StringBuilder();

// Path: teemo/src/main/java/core/util/IpUtil.java
// public class IpUtil {
// 
//     /**
//      * 从Spring上下文中获取Request，然后从Request对象中获取IP
//      * @return {@link String}
//      */
//     public static String getIp() {
//         RequestAttributes requestAttributes = null;
// 
//         try {
//             requestAttributes = RequestContextHolder.currentRequestAttributes();
//         } catch (Exception e) {
//             //ignore  如unit test
//         }
// 
//         if (requestAttributes != null && requestAttributes instanceof ServletRequestAttributes) {
//             return getIpAddr(((ServletRequestAttributes) requestAttributes).getRequest());
//         }
// 
//         return "unknown";
//     }
// 
//     /**
//      * 从Request获取IP
//      * 如果请求时通过反向代理过来的，需要在从代理字段中获取真实IP
//      * @param request
//      * @return {@link String}
//      */
//     public static String getIpAddr(HttpServletRequest request) {
//         if (request == null) {
//             return "unknown";
//         }
//         String ip = request.getHeader("x-forwarded-for");
//         if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
//             ip = request.getHeader("Proxy-Client-IP");
//         }
//         if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
//             ip = request.getHeader("X-Forwarded-For");
//         }
//         if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
//             ip = request.getHeader("WL-Proxy-Client-IP");
//         }
//         if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
//             ip = request.getHeader("X-Real-IP");
//         }
// 
//         if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
//             ip = request.getRemoteAddr();
//         }
//         return ip;
//     }
// }


// Path: teemo/src/main/java/com/teemo/core/util/UserLogUtil.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import core.util.IpUtil;

/**
 * Copyright (c) 2016- https://github.com/beiyoufx
 *
 * Licensed under the GPL-3.0
 */
package com.teemo.core.util;


/**
 * @author yongjie.teng
 * @date 16-11-2 下午3:27
 * @email yongjie.teng@foxmail.com
 * @package com.teemo.core.util
 */
public class UserLogUtil {
    private static final Logger USER_LOGGER = LoggerFactory.getLogger("USER_LOG");

    /**
     * <p>记录格式 [ip][用户名][操作][错误消息]<p/>
     * 注意操作如下：
     * loginError 登录失败
     * loginSuccess 登录成功
     * passwordError 密码错误
     * changePassword 修改密码
     * changeStatus 修改状态
     *
     * @param username
     * @param op
     * @param msg
     * @param args
     */
    public static void log(String username, String op, String msg, Object... args) {
        StringBuilder s = new StringBuilder();

        s.append(getBlock(IpUtil.getIp()));
