# 日志

## 访问日志 API

引入依赖

{% code title="pom.xml" %}

```markup
  <dependency>
      <groupId>org.hswebframework.web</groupId>
      <artifactId>hsweb-access-logging-api</artifactId>
      <version>${hsweb.framework.version}</version>
  </dependency>
```

{% endcode %}

Controller类或者方法上,注解 `@AccessLogger("功能描述")` 如果正在使用swagger,只需要注解swagger的`@Api(tags="功能说明",value="XXX功能")`

## 开启访问日志

引入依赖

{% code title="pom.xml" %}

```markup
<dependency>
      <groupId>org.hswebframework.web</groupId>
      <artifactId>hsweb-access-logging-aop</artifactId>
      <version>${hsweb.framework.version}</version>
  </dependency>
```

{% endcode %}

引入依赖,`hsweb-access-logging-aop`,在启动类中注解`@EnableAccessLogger`.

日志模块只生产日志，日志产生后会推送2个事件:

1. AccessLoggerBeforeEvent 在接收到请求，执行被请求接口之前触发
2. AccessLoggerAfterEvent 在请求接口被执行后触发

事件中包含了`AccessLoggerInfo`日志信息

如:&#x20;

```java
@EventListener
public void handleAccessLogger(AccessLoggerAfterEvent event){
     AccessLoggerInfo logInfo =event.getLogger();
    //提取日志并记录到数据库
}
```

{% hint style="danger" %}
注意，AccessLoggerInfo不能直接序列化，请提取出需要的信息进行处理。
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hsweb.io/framework/ri-zhi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
