Admin supports visual viewing of request logs on the interface. In the early version, you can view the service list that reports logs and the latest link logs. You can also integrate Spring Security to configure user names and passwords

Create the Logging Admin project

We need to create a SpringBoot project and add ApiBoot Logging Admin related dependencies and configuration information.

Blog address: blog.yuqiyu.com/apiboot-log…

Add the dependent

Add the following dependencies to the project’s POM.xml configuration file:

<dependencies>
  <! --Spring Web-->
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
  <! --MySQL-->
  <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <scope>runtime</scope>
  </dependency>

  <dependency>
    <groupId>com.zaxxer</groupId>
    <artifactId>HikariCP</artifactId>
  </dependency>

  <! --ApiBoot Logging Admin-->
  <dependency>
    <groupId>org.minbox.framework</groupId>
    <artifactId>api-boot-starter-logging-admin</artifactId>
  </dependency>

  <! --ApiBoot Mybatis Enhance-->
  <dependency>
    <groupId>org.minbox.framework</groupId>
    <artifactId>api-boot-starter-mybatis-enhance</artifactId>
  </dependency>
<! -- Version dependency -->
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.minbox.framework</groupId>
      <artifactId>api-boot-dependencies</artifactId>
      <version>2.1.5. RELEASE</version>
      <scope>import</scope>
      <type>pom</type>
    </dependency>
  </dependencies>
</dependencyManagement>
Copy the code

Configuring a Data Source

We need to connect to the database required by Logging Admin. For detailed database table structure, please visit “Reporting Logs Collected by ApiBoot Logging to Admin”.

Modify the application.yml configuration file to add relevant data source information as follows:

# service name
spring:
  application:
    name: logging-admin
  Configure data sources
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/test
    username: root
    password: 123456
    type: com.zaxxer.hikari.HikariDataSource
# Service port number
server:
  port: 8080
Copy the code

Configure log output & beautification

Modify the application.yml configuration file to add ApiBoot Logging Admin configuration information, as shown below:

api:
  boot:
    logging:
      # Logging Admin related configuration
      admin:
        The console displays the collected log information
        show-console-report-log: true
        # Beautify the log
        format-console-log-json: true
Copy the code

Integrated Spring Security

When we integrate Spring Security, we can see the visual interface provided by ApiBoot Logging Admin directly at http://localhost:8080, but just to be safe, We added the Spring Security dependency and configured the memory user information accordingly, adding the dependency to the POM.xml file as follows:

<! --Spring Security-->
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-security</artifactId>
</dependency>
Copy the code

Configuring Security Users

The spring-boot-starter-security dependency provides in-memory configuration of user information. Configure the user in the application.yml file as follows:

# service name
spring:
  # Integrate Spring Security and configure memory users
  security:
    user:
      name: admin
      password: admin123
Copy the code

Run the test

Start the chapter project using XxxApplication.

If you visit http://localhost:8080 in your browser, the result is as follows:

Because of Spring Security interception, it will directly jump to the built-in login page of ApiBoot Logging Admin. Enter the user name and password configured in application. Yml to log in.

Link Log List

After successful login, the link log list page is displayed. Click each line to view details, as shown below:

Log Service List

In the log service menu, you can view the basic information about each service, the time when the last log is reported, and the time when the first log is reported, as shown in the following figure:

Type on the blackboard and underline

Admin currently supports visual interface to view logs and basic service information. Its functions are still being enriched and its integrity needs to be improved.

Code sample

If you like this article please click Star for source repository, thanks!! The source code for this article can be obtained from the following directory: springboot2.x/APIboot-logging-admin-visual-interface-management-log:

  • Gitee:Gitee.com/hengboy/spr…

Author’s personal blog uses the open source framework ApiBoot to help you become an Api service architect