首页 > 其他 > 详细

用户行为日志

时间:2019-02-02 16:12:51      阅读:170      评论:0      收藏:0      [点我收藏+]

 

 

@Data
@NoArgsConstructor
@AllArgsConstructor
public class LogObject {

    /** 日志动作类型 */
    private String action;

    /** 用户 id */
    private Long userId;

    /** 当前时间戳 */
    private Long timestamp;

    /** 客户端 ip 地址 */
    private String remoteIp;

    /** 日志信息 */
    private Object info = null;
}

 

/**
 * <h1>日志生成器</h1>
 */
@Slf4j
public class LogGenerator {

    /**
     * <h2>生成 log</h2>
     * @param request {@link HttpServletRequest}
     * @param userId 用户 id
     * @param action 日志类型
     * @param info 日志信息, 可以是 null
     * */
    public static void genLog(HttpServletRequest request, Long userId, String action, Object info) {

        log.info(
                JSON.toJSONString(
                        new LogObject(action, userId, System.currentTimeMillis(), request.getRemoteAddr(), info)
                )
        );
    }
}

 

使用: 

    @ResponseBody
    @PostMapping("/createuser")
    Response createUser(@RequestBody User user) throws Exception {

        LogGenerator.genLog(
                httpServletRequest,
                -1L,
                LogConstants.ActionName.CREATE_USER,
                user
        );
        return userService.createUser(user);
    }

 

/**
 * <h1>日志记录常量定义</h1>
 */
public class LogConstants {

    /**
     * <h2>用户动作名称</h2>
     * */
    public class ActionName {

        /** 用户查看优惠券信息 */
        public static final String USER_PASS_INFO = "UserPassInfo";

        /** 用户查看已使用的优惠券信息 */
        public static final String USER_USED_PASS_INFO = "UserUsedPassInfo";

        /** 用户使用优惠券 */
        public static final String USER_USE_PASS = "UserUsePass";

        /** 用户获取库存信息 */
        public static final String INVENTORY_INFO = "InventoryInfo";

        /** 用户领取优惠券 */
        public static final String GAIN_PASS_TEMPLATE = "GainPassTemplate";

        /** 用户创建评论 */
        public static final String CREATE_FEEDBACK = "CreateFeedback";

        /** 用户获取评论 */
        public static final String GET_FEEDBACK = "GetFeedback";

        /** 创建用户 */
        public static final String CREATE_USER = "CreateUser";
    }
}

 

用户行为日志

原文:https://www.cnblogs.com/yintingting/p/10348534.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!