Browse Source

修改log包结构,避免gitignore忽略文件
修改log文件位置 统一置入logs目录中

NorthLan 6 years ago
parent
commit
d0fe0bea63

+ 26 - 0
zen-api/src/main/kotlin/com/gxzc/zen/logging/constants/LogConstants.kt

@@ -0,0 +1,26 @@
+package com.gxzc.zen.logging.constants
+
+/**
+ * 日志各种常量
+ * @author NorthLan
+ * @date 2018/8/23
+ * @url https://noahlan.com
+ */
+object LogConstants {
+    /*-------------------------------------------
+    |              登 录 日 志 常 量              |
+    ============================================*/
+    const val AUTH_TYPE_LOGIN = 1 // 登录
+    const val AUTH_TYPE_LOGOUT = 2 // 登出
+
+    const val AUTH_METHOD_ACCOUNT_PASSWORD = 1 // 账号密码登录
+    const val AUTH_METHOD_USBKEY = 2 // 通过 USBKEY 登陆
+
+    /*-------------------------------------------
+    |               D B 日 志 常 量              |
+    ============================================*/
+    const val DB_TYPE_INSERT = 1 // 新增
+    const val DB_TYPE_UPDATE = 2 // 修改
+    const val DB_TYPE_DELETE = 3 // 删除
+    const val DB_TYPE_SELECT = 4 // 查询
+}

+ 31 - 0
zen-api/src/main/kotlin/com/gxzc/zen/logging/model/LogAuth.kt

@@ -0,0 +1,31 @@
+package com.gxzc.zen.logging.model
+
+import java.io.Serializable
+import java.util.*
+
+/**
+ * 登录/登出 日志 data class
+ * @author NorthLan
+ * @date 2018/8/23
+ * @url https://noahlan.com
+ */
+data class LogAuth(val type: Int, val method: Int, val operator: String) : Serializable {
+    companion object {
+        private const val serialVersionUID = 10000000000000001L
+    }
+
+    /**
+     * 操作时间
+     */
+    val time: Date = Date()
+
+    /**
+     * 客户端host
+     */
+    var host: String? = null
+
+    /**
+     * 备注
+     */
+    var remark: String? = null
+}

+ 46 - 0
zen-api/src/main/kotlin/com/gxzc/zen/logging/model/LogBiz.kt

@@ -0,0 +1,46 @@
+package com.gxzc.zen.logging.model
+
+import java.io.Serializable
+import java.util.*
+
+/**
+ *
+ * @author NorthLan
+ * @date 2018/8/23
+ * @url https://noahlan.com
+ */
+data class LogBiz(val pid: Int, val operator: String) : Serializable {
+    companion object {
+        private const val serialVersionUID = 10000000000000004L
+    }
+
+    /**
+     * 业务ID
+     */
+    var bizId: String? = null
+
+    /**
+     * 业务名称
+     */
+    var bizName: String? = null
+
+    /**
+     * 业务内容(需自行组装)
+     */
+    var bizContent: String? = null
+
+    /**
+     * 操作时间
+     */
+    var operTime = Date()
+
+    /**
+     * 客户端host
+     */
+    var host: String? = null
+
+    /**
+     * 备注
+     */
+    var remark: String? = null
+}

+ 41 - 0
zen-api/src/main/kotlin/com/gxzc/zen/logging/model/LogDB.kt

@@ -0,0 +1,41 @@
+package com.gxzc.zen.logging.model
+
+import java.io.Serializable
+import java.util.*
+
+/**
+ * 数据库日志 model
+ * @author NorthLan
+ * @date 2018/8/23
+ * @url https://noahlan.com
+ */
+data class LogDB(val pid: Int, val type: Int, val operator: String) : Serializable {
+    companion object {
+        private const val serialVersionUID = 10000000000000003L
+    }
+
+    /**
+     * 操作时间
+     */
+    var operTime: Date = Date()
+
+    /**
+     * 执行sql
+     */
+    var sql: String? = null
+
+    /**
+     * 表名
+     */
+    var tableId: String? = null
+
+    /**
+     * 表名 Comment中的
+     */
+    var tableName: String? = null
+
+    /**
+     * 备注
+     */
+    var remark: String? = null
+}

+ 56 - 0
zen-api/src/main/kotlin/com/gxzc/zen/logging/model/LogRequest.kt

@@ -0,0 +1,56 @@
+package com.gxzc.zen.logging.model
+
+import java.io.Serializable
+import java.util.*
+
+/**
+ * 请求日志 model
+ * @author NorthLan
+ * @date 2018/8/23
+ * @url https://noahlan.com
+ */
+data class LogRequest(val pid: Int, val operator: String) : Serializable {
+    companion object {
+        private const val serialVersionUID = 10000000000000002L
+    }
+
+    /**
+     * 请求URI
+     */
+    var requestUri: String? = null
+
+    /**
+     * 请求方法
+     */
+    var requestMethod: String? = null
+
+    /**
+     * 请求携带参数
+     */
+    var requestParam: String? = null
+
+    /**
+     * 请求内容体
+     */
+    var requestBody: String? = null
+
+    /**
+     * 操作时间
+     */
+    var operTime: Date = Date()
+
+    /**
+     * 客户端host
+     */
+    var host: String? = null
+
+    /**
+     * 客户端用户代理
+     */
+    var userAgent: String? = null
+
+    /**
+     * 备注
+     */
+    var remark: String? = null
+}

+ 11 - 0
zen-api/src/main/kotlin/com/gxzc/zen/logging/util/LoggerUtils.kt

@@ -0,0 +1,11 @@
+package com.gxzc.zen.logging.util
+
+/**
+ * 日志工具类
+ * @author NorthLan
+ * @date 2018/8/23
+ * @url https://noahlan.com
+ */
+object LoggerUtils {
+
+}

+ 78 - 0
zen-api/src/main/kotlin/com/gxzc/zen/logging/util/MQLogUtil.kt

@@ -0,0 +1,78 @@
+package com.gxzc.zen.logging.util
+
+import com.gxzc.zen.logging.model.LogAuth
+import com.gxzc.zen.logging.model.LogBiz
+import com.gxzc.zen.logging.model.LogDB
+import com.gxzc.zen.logging.model.LogRequest
+import com.gxzc.zen.msg.mq.MQProducerUtil
+import com.gxzc.zen.msg.mq.constants.MQConstants
+import com.maihaoche.starter.mq.base.MessageBuilder
+import org.apache.rocketmq.client.producer.SendCallback
+import org.apache.rocketmq.client.producer.SendResult
+import org.slf4j.LoggerFactory
+
+/**
+ * 基于消息队列MQ的日志工具类
+ * @author NorthLan
+ * @date 2018/8/23
+ * @url https://noahlan.com
+ */
+object MQLogUtil {
+    private val logger = LoggerFactory.getLogger(MQLogUtil::class.java)
+    private val mqProducer = MQProducerUtil.producer!!
+
+    /**
+     * 发送 登陆日志 消息
+     */
+    fun logAuth(logAuth: LogAuth) {
+        mqProducer.asyncSend(MessageBuilder.of(logAuth).topic(MQConstants.TOPIC_LOGS).tag(MQConstants.TAGS_LOGS_AUTH).build(),
+                object : SendCallback {
+                    override fun onException(e: Throwable) {
+                        logger.error("Send logAuth error, cause ", e)
+                    }
+
+                    override fun onSuccess(sendResult: SendResult) {
+                        logger.debug("Send logAuth success! {0}", sendResult.sendStatus)
+                    }
+                })
+    }
+
+    fun logRequest(logRequest: LogRequest) {
+        mqProducer.asyncSend(MessageBuilder.of(logRequest).topic(MQConstants.TOPIC_LOGS).tag(MQConstants.TAGS_LOGS_REQUEST).build(),
+                object : SendCallback {
+                    override fun onException(e: Throwable) {
+                        logger.error("Send logRequest error, cause ", e)
+                    }
+
+                    override fun onSuccess(sendResult: SendResult) {
+                        logger.debug("Send logRequest success! {0}", sendResult.sendStatus)
+                    }
+                })
+    }
+
+    fun logDB(logDB: LogDB) {
+        mqProducer.asyncSend(MessageBuilder.of(logDB).topic(MQConstants.TOPIC_LOGS).tag(MQConstants.TAGS_LOGS_DB).build(),
+                object : SendCallback {
+                    override fun onException(e: Throwable) {
+                        logger.error("Send logDB error, cause ", e)
+                    }
+
+                    override fun onSuccess(sendResult: SendResult) {
+                        logger.debug("Send logDB success! {0}", sendResult.sendStatus)
+                    }
+                })
+    }
+
+    fun logBiz(logBiz: LogBiz) {
+        mqProducer.asyncSend(MessageBuilder.of(logBiz).topic(MQConstants.TOPIC_LOGS).tag(MQConstants.TAGS_LOGS_BIZ).build(),
+                object : SendCallback {
+                    override fun onException(e: Throwable) {
+                        logger.error("Send logBiz error, cause ", e)
+                    }
+
+                    override fun onSuccess(sendResult: SendResult) {
+                        logger.debug("Send logBiz success! {0}", sendResult.sendStatus)
+                    }
+                })
+    }
+}

+ 0 - 56
zen-web/src/main/kotlin/com/gxzc/zen/web/sys/controller/TestController.kt

@@ -1,11 +1,6 @@
 package com.gxzc.zen.web.sys.controller
 
-import com.gxzc.zen.api.sys.service.ISysUploadInfoService
 import com.gxzc.zen.common.base.BaseController
-import com.gxzc.zen.msg.mq.MQProducerUtil
-import com.maihaoche.starter.mq.base.MessageBuilder
-import org.apache.shiro.SecurityUtils
-import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.http.ResponseEntity
 import org.springframework.web.bind.annotation.GetMapping
 import org.springframework.web.bind.annotation.RequestMapping
@@ -22,59 +17,8 @@ import org.springframework.web.bind.annotation.RestController
 @RequestMapping("test")
 class TestController : BaseController() {
 
-    @Autowired
-    private lateinit var sysUploadInfoService: ISysUploadInfoService
-
-    //    @Autowired
-    //    private lateinit var mqProducer: ZenMQProducer
-
     @GetMapping("a")
     fun get(): ResponseEntity<*> {
         return ResponseEntity.ok(2)
     }
-
-
-    @GetMapping("b")
-    fun getb(): ResponseEntity<*> {
-        return ResponseEntity.ok(sysUploadInfoService.selectList(null))
-    }
-
-    @GetMapping("thread")
-    fun niubi(): ResponseEntity<*> {
-        val subject = SecurityUtils.getSubject()
-        println(subject.principal)
-        val runnable = Thread(Runnable {
-            kotlin.run {
-                Thread.sleep(2000)
-                val sub = SecurityUtils.getSubject()
-                println(sub.principal)
-            }
-        })
-        //        subject.execute {
-        runnable.start()
-        //        }
-        return ResponseEntity.ok("2333")
-    }
-
-    @GetMapping("mq")
-    fun mq(): ResponseEntity<*> {
-        MQProducerUtil.producer?.syncSend(MessageBuilder.of("2333").build())
-        return ResponseEntity.ok(1234)
-    }
-
-    @GetMapping("file")
-    fun md5(): ResponseEntity<*> {
-        //        println(FileUtil.md5HeadTail("/newfile/4/WS·1983/综合/永久/4·WS-1983-综合-0001.pdf", null))
-        //        println(FileUtil.md5HeadTail("D:/data/4·WS-1983-综合-0001.pdf", null))
-
-        //
-        //        FileUtils.copyFile(File("D:/data/123.pdf"),File("D:/321.pdf"))
-        //
-        //        println(FileUtil.md5HeadTail("D:/data/123.pdf", 10485760))
-        //        println(FileUtil.md5HeadTail("D:/321.pdf", 10485760))
-
-        //        println(FileUtil.md5HeadTail("D:/123.pdf", null))
-        //        println(FileUtil.md5HeadTail("D:/data/", null))
-        return ResponseEntity.ok(2333)
-    }
 }

+ 2 - 4
zen-web/src/main/resources/application.yml

@@ -32,8 +32,7 @@ logging:
     com.xxl.job.core: warn
     com.atomikos: warn
     com.maihaoche: debug
-  path: ./logs/
-  file: zen.log
+  file: logs/zen.log
 
 ---
 spring:
@@ -64,5 +63,4 @@ logging:
       zen.umps.config: warn
     com.xxl.job.core: warn
     com.atomikos: warn
-  path: ./logs/
-  file: zen.log
+  file: logs/zen.log