Kaynağa Gözat

日志配置

wangtuohang@126.com 1 ay önce
ebeveyn
işleme
fd7d610ccb

+ 137 - 0
src/main/java/org/springblade/modules/log/controller/LogYysdController.java

@@ -0,0 +1,137 @@
+package org.springblade.modules.log.controller;
+
+import io.swagger.v3.oas.annotations.tags.Tag;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
+import lombok.AllArgsConstructor;
+import jakarta.validation.Valid;
+
+import org.springblade.core.secure.BladeUser;
+import org.springblade.core.secure.annotation.PreAuth;
+import org.springblade.core.mp.support.Condition;
+import org.springblade.core.mp.support.Query;
+import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.utils.Func;
+import org.springblade.modules.log.excel.LogYysdExcel;
+import org.springblade.modules.log.pojo.entity.LogYysdEntity;
+import org.springblade.modules.log.pojo.vo.LogYysdVO;
+import org.springblade.modules.log.service.ILogYysdService;
+import org.springblade.modules.log.wrapper.LogYysdWrapper;
+import org.springframework.web.bind.annotation.*;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.springblade.core.boot.ctrl.BladeController;
+import org.springblade.core.tool.utils.DateUtil;
+import org.springblade.core.excel.util.ExcelUtil;
+import org.springblade.core.tool.constant.RoleConstant;
+import java.util.Map;
+import java.util.List;
+import jakarta.servlet.http.HttpServletResponse;
+
+/**
+ * 应用商店日志 控制器
+ *
+ * @author BladeX
+ * @since 2024-10-30
+ */
+@RestController
+@AllArgsConstructor
+@RequestMapping("/logYysd")
+@Tag(name = "应用商店日志", description = "应用商店日志接口")
+public class LogYysdController extends BladeController {
+
+	private final ILogYysdService logYysdService;
+
+	/**
+	 * 应用商店日志 详情
+	 */
+	@GetMapping("/detail")
+	@ApiOperationSupport(order = 1)
+	@Operation(summary = "详情", description  = "传入logYysd")
+	public R<LogYysdVO> detail(LogYysdEntity logYysd) {
+		LogYysdEntity detail = logYysdService.getOne(Condition.getQueryWrapper(logYysd));
+		return R.data(LogYysdWrapper.build().entityVO(detail));
+	}
+
+	/**
+	 * 应用商店日志 分页
+	 */
+	@GetMapping("/list")
+	@ApiOperationSupport(order = 2)
+	@Operation(summary = "分页", description  = "传入logYysd")
+	public R<IPage<LogYysdVO>> list(@Parameter(hidden = true) @RequestParam Map<String, Object> logYysd, Query query) {
+		IPage<LogYysdEntity> pages = logYysdService.page(Condition.getPage(query), Condition.getQueryWrapper(logYysd, LogYysdEntity.class));
+		return R.data(LogYysdWrapper.build().pageVO(pages));
+	}
+
+
+	/**
+	 * 应用商店日志 自定义分页
+	 */
+	@GetMapping("/page")
+	@ApiOperationSupport(order = 3)
+	@Operation(summary = "分页", description  = "传入logYysd")
+	public R<IPage<LogYysdVO>> page(LogYysdVO logYysd, Query query) {
+		IPage<LogYysdVO> pages = logYysdService.selectLogYysdPage(Condition.getPage(query), logYysd);
+		return R.data(pages);
+	}
+
+	/**
+	 * 应用商店日志 新增
+	 */
+	@PostMapping("/save")
+	@ApiOperationSupport(order = 4)
+	@Operation(summary = "新增", description  = "传入logYysd")
+	public R save(@Valid @RequestBody LogYysdEntity logYysd) {
+		return R.status(logYysdService.save(logYysd));
+	}
+
+	/**
+	 * 应用商店日志 修改
+	 */
+	@PostMapping("/update")
+	@ApiOperationSupport(order = 5)
+	@Operation(summary = "修改", description  = "传入logYysd")
+	public R update(@Valid @RequestBody LogYysdEntity logYysd) {
+		return R.status(logYysdService.updateById(logYysd));
+	}
+
+	/**
+	 * 应用商店日志 新增或修改
+	 */
+	@PostMapping("/submit")
+	@ApiOperationSupport(order = 6)
+	@Operation(summary = "新增或修改", description  = "传入logYysd")
+	public R submit(@Valid @RequestBody LogYysdEntity logYysd) {
+		return R.status(logYysdService.saveOrUpdate(logYysd));
+	}
+
+	/**
+	 * 应用商店日志 删除
+	 */
+	@PostMapping("/remove")
+	@ApiOperationSupport(order = 7)
+	@Operation(summary = "逻辑删除", description  = "传入ids")
+	public R remove(@Parameter(description = "主键集合", required = true) @RequestParam String ids) {
+		return R.status(logYysdService.deleteLogic(Func.toLongList(ids)));
+	}
+
+	/**
+	 * 导出数据
+	 */
+	@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
+	@GetMapping("/export-logYysd")
+	@ApiOperationSupport(order = 8)
+	@Operation(summary = "导出数据", description  = "传入logYysd")
+	public void exportLogYysd(@Parameter(hidden = true) @RequestParam Map<String, Object> logYysd, BladeUser bladeUser, HttpServletResponse response) {
+		QueryWrapper<LogYysdEntity> queryWrapper = Condition.getQueryWrapper(logYysd, LogYysdEntity.class);
+		//if (!AuthUtil.isAdministrator()) {
+		//	queryWrapper.lambda().eq(LogYysdEntity::getTenantId, bladeUser.getTenantId());
+		//}
+		//queryWrapper.lambda().eq(LogYysdEntity::getIsDeleted, BladeConstant.DB_NOT_DELETED);
+		List<LogYysdExcel> list = logYysdService.exportLogYysd(queryWrapper);
+		ExcelUtil.export(response, "应用商店日志数据" + DateUtil.time(), "应用商店日志数据表", list, LogYysdExcel.class);
+	}
+
+}

+ 42 - 0
src/main/java/org/springblade/modules/log/excel/LogYysdExcel.java

@@ -0,0 +1,42 @@
+package org.springblade.modules.log.excel;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.write.style.ColumnWidth;
+import com.alibaba.excel.annotation.write.style.ContentRowHeight;
+import com.alibaba.excel.annotation.write.style.HeadRowHeight;
+
+import java.io.Serial;
+
+/**
+ * 应用商店日志 Excel实体类
+ *
+ * @author BladeX
+ * @since 2024-10-30
+ */
+@Data
+@ColumnWidth(25)
+@HeadRowHeight(20)
+@ContentRowHeight(18)
+public class LogYysdExcel implements Serializable {
+
+	@Serial
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * 请求参数
+	 */
+	@ColumnWidth(20)
+	@ExcelProperty("请求参数")
+	private String requestParams;
+	/**
+	 * 相应结果
+	 */
+	@ColumnWidth(20)
+	@ExcelProperty("相应结果")
+	private String responseBody;
+
+}

+ 38 - 0
src/main/java/org/springblade/modules/log/mapper/LogYysdMapper.java

@@ -0,0 +1,38 @@
+package org.springblade.modules.log.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.apache.ibatis.annotations.Param;
+import org.springblade.modules.log.excel.LogYysdExcel;
+import org.springblade.modules.log.pojo.entity.LogYysdEntity;
+import org.springblade.modules.log.pojo.vo.LogYysdVO;
+
+import java.util.List;
+
+/**
+ * 应用商店日志 Mapper 接口
+ *
+ * @author BladeX
+ * @since 2024-10-30
+ */
+public interface LogYysdMapper extends BaseMapper<LogYysdEntity> {
+
+	/**
+	 * 自定义分页
+	 *
+	 * @param page 分页参数
+	 * @param logYysd 查询参数
+	 * @return List<LogYysdVO>
+	 */
+	List<LogYysdVO> selectLogYysdPage(IPage page, LogYysdVO logYysd);
+
+	/**
+	 * 获取导出数据
+	 *
+	 * @param queryWrapper 查询条件
+	 * @return List<LogYysdExcel>
+	 */
+	List<LogYysdExcel> exportLogYysd(@Param("ew") Wrapper<LogYysdEntity> queryWrapper);
+
+}

+ 19 - 0
src/main/java/org/springblade/modules/log/mapper/LogYysdMapper.xml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.springblade.modules.log.mapper.LogYysdMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="logYysdResultMap" type="org.springblade.modules.log.pojo.entity.LogYysdEntity">
+        <result column="request_params" property="requestParams"/>
+        <result column="response_body" property="responseBody"/>
+    </resultMap>
+
+    <select id="selectLogYysdPage" resultMap="logYysdResultMap">
+        select * from log_yysd where is_deleted = 0
+    </select>
+
+    <select id="exportLogYysd" resultType="org.springblade.modules.log.excel.LogYysdExcel">
+        SELECT * FROM log_yysd ${ew.customSqlSegment}
+    </select>
+
+</mapper>

+ 22 - 0
src/main/java/org/springblade/modules/log/pojo/dto/LogYysdDTO.java

@@ -0,0 +1,22 @@
+package org.springblade.modules.log.pojo.dto;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.springblade.modules.log.pojo.entity.LogYysdEntity;
+
+import java.io.Serial;
+
+/**
+ * 应用商店日志 数据传输对象实体类
+ *
+ * @author BladeX
+ * @since 2024-10-30
+ */
+
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class LogYysdDTO extends LogYysdEntity {
+	@Serial
+	private static final long serialVersionUID = 1L;
+
+}

+ 37 - 0
src/main/java/org/springblade/modules/log/pojo/entity/LogYysdEntity.java

@@ -0,0 +1,37 @@
+package org.springblade.modules.log.pojo.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.springblade.core.mp.base.BaseEntity;
+
+import java.io.Serial;
+
+/**
+ * 应用商店日志 实体类
+ *
+ * @author BladeX
+ * @since 2024-10-30
+ */
+@Data
+@TableName("log.log_yysd")
+@EqualsAndHashCode(callSuper = true)
+@Schema(description = "LogYysdEntity对象")
+public class LogYysdEntity extends BaseEntity {
+
+	@Serial
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * 请求参数
+	 */
+	@Schema(description = "请求参数")
+	private String requestParams;
+	/**
+	 * 相应结果
+	 */
+	@Schema(description = "响应结果")
+	private String responseBody;
+
+}

+ 21 - 0
src/main/java/org/springblade/modules/log/pojo/vo/LogYysdVO.java

@@ -0,0 +1,21 @@
+package org.springblade.modules.log.pojo.vo;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.springblade.modules.log.pojo.entity.LogYysdEntity;
+
+import java.io.Serial;
+
+/**
+ * 应用商店日志 视图实体类
+ *
+ * @author BladeX
+ * @since 2024-10-30
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class LogYysdVO extends LogYysdEntity {
+	@Serial
+	private static final long serialVersionUID = 1L;
+
+}

+ 36 - 0
src/main/java/org/springblade/modules/log/service/ILogYysdService.java

@@ -0,0 +1,36 @@
+package org.springblade.modules.log.service;
+
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.springblade.core.mp.base.BaseService;
+import org.springblade.modules.log.excel.LogYysdExcel;
+import org.springblade.modules.log.pojo.entity.LogYysdEntity;
+import org.springblade.modules.log.pojo.vo.LogYysdVO;
+
+import java.util.List;
+
+/**
+ * 应用商店日志 服务类
+ *
+ * @author BladeX
+ * @since 2024-10-30
+ */
+public interface ILogYysdService extends BaseService<LogYysdEntity> {
+	/**
+	 * 自定义分页
+	 *
+	 * @param page 分页参数
+	 * @param logYysd 查询参数
+	 * @return IPage<LogYysdVO>
+	 */
+	IPage<LogYysdVO> selectLogYysdPage(IPage<LogYysdVO> page, LogYysdVO logYysd);
+
+	/**
+	 * 导出数据
+	 *
+	 * @param queryWrapper 查询条件
+	 * @return List<LogYysdExcel>
+	 */
+	List<LogYysdExcel> exportLogYysd(Wrapper<LogYysdEntity> queryWrapper);
+
+}

+ 37 - 0
src/main/java/org/springblade/modules/log/service/impl/LogYysdServiceImpl.java

@@ -0,0 +1,37 @@
+package org.springblade.modules.log.service.impl;
+
+import org.springblade.modules.log.excel.LogYysdExcel;
+import org.springblade.modules.log.mapper.LogYysdMapper;
+import org.springblade.modules.log.pojo.entity.LogYysdEntity;
+import org.springblade.modules.log.pojo.vo.LogYysdVO;
+import org.springblade.modules.log.service.ILogYysdService;
+import org.springframework.stereotype.Service;
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.springblade.core.mp.base.BaseServiceImpl;
+import java.util.List;
+
+/**
+ * 应用商店日志 服务实现类
+ *
+ * @author BladeX
+ * @since 2024-10-30
+ */
+@Service
+public class LogYysdServiceImpl extends BaseServiceImpl<LogYysdMapper, LogYysdEntity> implements ILogYysdService {
+
+	@Override
+	public IPage<LogYysdVO> selectLogYysdPage(IPage<LogYysdVO> page, LogYysdVO logYysd) {
+		return page.setRecords(baseMapper.selectLogYysdPage(page, logYysd));
+	}
+
+	@Override
+	public List<LogYysdExcel> exportLogYysd(Wrapper<LogYysdEntity> queryWrapper) {
+		List<LogYysdExcel> logYysdList = baseMapper.exportLogYysd(queryWrapper);
+		//logYysdList.forEach(logYysd -> {
+		//	logYysd.setTypeName(DictCache.getValue(DictEnum.YES_NO, LogYysdEntity.getType()));
+		//});
+		return logYysdList;
+	}
+
+}

+ 34 - 0
src/main/java/org/springblade/modules/log/wrapper/LogYysdWrapper.java

@@ -0,0 +1,34 @@
+package org.springblade.modules.log.wrapper;
+
+import org.springblade.core.mp.support.BaseEntityWrapper;
+import org.springblade.core.tool.utils.BeanUtil;
+import org.springblade.modules.log.pojo.entity.LogYysdEntity;
+import org.springblade.modules.log.pojo.vo.LogYysdVO;
+
+import java.util.Objects;
+
+/**
+ * 应用商店日志 包装类,返回视图层所需的字段
+ *
+ * @author BladeX
+ * @since 2024-10-30
+ */
+public class LogYysdWrapper extends BaseEntityWrapper<LogYysdEntity, LogYysdVO> {
+
+	public static LogYysdWrapper build() {
+		return new LogYysdWrapper();
+ 	}
+
+	@Override
+	public LogYysdVO entityVO(LogYysdEntity logYysd) {
+		LogYysdVO logYysdVO = Objects.requireNonNull(BeanUtil.copyProperties(logYysd, LogYysdVO.class));
+
+		//User createUser = UserCache.getUser(logYysd.getCreateUser());
+		//User updateUser = UserCache.getUser(logYysd.getUpdateUser());
+		//logYysdVO.setCreateUserName(createUser.getName());
+		//logYysdVO.setUpdateUserName(updateUser.getName());
+
+		return logYysdVO;
+	}
+
+}

+ 151 - 0
src/main/resources/log/logback-net.xml

@@ -0,0 +1,151 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration scan="true" scanPeriod="60 seconds">
+    <!-- 自定义参数监听 -->
+    <contextListener class="org.springblade.core.log.listener.LoggerStartupListener"/>
+    <springProperty scope="context" name="springAppName" source="spring.application.name"/>
+
+    <!-- 彩色日志依赖的渲染类 -->
+    <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
+    <conversionRule conversionWord="wex"
+                    converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
+    <conversionRule conversionWord="wEx"
+                    converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
+    <!-- 彩色日志格式 -->
+    <property name="CONSOLE_LOG_PATTERN"
+              value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
+    <!-- 控制台输出 -->
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+            <pattern>${CONSOLE_LOG_PATTERN}</pattern>
+            <charset>utf8</charset>
+        </encoder>
+    </appender>
+
+    <!-- 生成日志文件 -->
+    <appender name="INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 日志文件输出的文件名 -->
+            <FileNamePattern>target/blade/log/info-%d{yyyy-MM-dd}.log</FileNamePattern>
+        </rollingPolicy>
+        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+            <pattern>%n%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%X{traceId}] [%logger{50}] %n%-5level: %msg%n</pattern>
+        </encoder>
+        <!-- 打印日志级别 -->
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <level>INFO</level>
+            <onMatch>ACCEPT</onMatch>
+            <onMismatch>DENY</onMismatch>
+        </filter>
+    </appender>
+
+    <!-- 生成日志文件 -->
+    <appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 日志文件输出的文件名 -->
+            <FileNamePattern>target/blade/log/error-%d{yyyy-MM-dd}.log</FileNamePattern>
+        </rollingPolicy>
+        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+            <pattern>%n%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%X{traceId}] [%logger{50}] %n%-5level: %msg%n</pattern>
+        </encoder>
+        <!-- 打印日志级别 -->
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <level>ERROR</level>
+            <onMatch>ACCEPT</onMatch>
+            <onMismatch>DENY</onMismatch>
+        </filter>
+    </appender>
+
+    <if condition='property("ELK_MODE").toUpperCase().contains("TRUE")'>
+        <then>
+            <!-- 推送日志至elk -->
+            <appender name="INFO_LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
+                <destination>${DESTINATION}</destination>
+                <!-- 日志输出编码 -->
+                <encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
+                    <providers>
+                        <timestamp>
+                            <timeZone>UTC</timeZone>
+                        </timestamp>
+                        <pattern>
+                            <pattern>
+                                {
+                                "traceId": "%X{traceId}",
+                                "requestId": "%X{requestId}",
+                                "accountId": "%X{accountId}",
+                                "tenantId": "%X{tenantId}",
+                                "logLevel": "%level",
+                                "serviceName": "${springAppName:-SpringApp}",
+                                "pid": "${PID:-}",
+                                "thread": "%thread",
+                                "class": "%logger{40}",
+                                "line":"%L",
+                                "message": "%message"
+                                }
+                            </pattern>
+                        </pattern>
+                        <mdc/>
+                        <stackTrace/>
+                    </providers>
+                </encoder>
+                <!-- 打印日志级别 -->
+                <filter class="ch.qos.logback.classic.filter.LevelFilter">
+                    <level>INFO</level>
+                    <onMatch>ACCEPT</onMatch>
+                    <onMismatch>DENY</onMismatch>
+                </filter>
+            </appender>
+
+            <!-- 推送日志至elk -->
+            <appender name="ERROR_LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
+                <destination>${DESTINATION}</destination>
+                <!-- 日志输出编码 -->
+                <encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
+                    <providers>
+                        <timestamp>
+                            <timeZone>UTC</timeZone>
+                        </timestamp>
+                        <pattern>
+                            <pattern>
+                                {
+                                "traceId": "%X{traceId}",
+                                "requestId": "%X{requestId}",
+                                "accountId": "%X{accountId}",
+                                "tenantId": "%X{tenantId}",
+                                "logLevel": "%level",
+                                "serviceName": "${springAppName:-SpringApp}",
+                                "pid": "${PID:-}",
+                                "thread": "%thread",
+                                "class": "%logger{40}",
+                                "line":"%L",
+                                "message": "%message"
+                                }
+                            </pattern>
+                        </pattern>
+                        <mdc/>
+                        <stackTrace/>
+                    </providers>
+                </encoder>
+                <!-- 打印日志级别 -->
+                <filter class="ch.qos.logback.classic.filter.LevelFilter">
+                    <level>ERROR</level>
+                    <onMatch>ACCEPT</onMatch>
+                    <onMismatch>DENY</onMismatch>
+                </filter>
+            </appender>
+        </then>
+    </if>
+
+    <!-- 日志输出级别 -->
+    <root level="INFO">
+        <appender-ref ref="STDOUT"/>
+        <appender-ref ref="${INFO_APPENDER}"/>
+        <appender-ref ref="${ERROR_APPENDER}"/>
+    </root>
+
+    <logger name="net.sf.ehcache" level="INFO"/>
+    <logger name="druid.sql" level="INFO"/>
+
+    <!-- 减少nacos日志 -->
+    <logger name="com.alibaba.nacos" level="ERROR"/>
+
+</configuration>