Giter VIP home page Giter VIP logo

looklog's Introduction

说明

这是一个在线查看日志的工具, 基于mongoDB存储日志. 通过访问 http://{应用域名根目录}/lookLog 地址可以实时查看当前应用打出的日志

环境要求

  • spring-boot项目
  • JDK8

使用方式

  1. 将源代码pull到本地执行mvn install命令, 在应用项目的pom.xml中添加如下依赖,(版本号与依赖的spring-boot版本号保持一致)

        <dependency>
            <groupId>novayoung</groupId>
            <artifactId>spring-boot-looklog</artifactId>
            <version>1.4.1.RELEASE</version>
        </dependency>
        
  2. 添加配置, 在application.properties中加入以下配置项.

    \# 是否开启日志查看功能, 值为 true/false
    
    lookLog.enable=
    
    \# 日志缓存的秒数, 默认是一天, 如果为-1表示永不过期
    
    lookLog.cachedSecond=
    
    \# 日志临时存储的MongoDB表名
    
    lookLog.mongoDbCollectionName=
    
    \# MongoDB Uri
    spring.data.mongodb.uri=
    
  3. 在logback.xml文件中增加如下代码.

     <include resource="looklog.xml"/>
    
  4. 在main函数的启动类中, 增加对包"novayoung.log"的扫描, 同时将spring上下文对象注入到LookLogAppender中, 代码如下

        @SpringBootApplication(scanBasePackages = {"当前应用需要扫描的包", "novayoung.log"})   //此处增加对"novayoung.log"包的扫描
        public class TestApplication {
        
            public static void main(String[] args) {
                ApplicationContext applicationContext = SpringApplication.run(TestApplication.class, args);
                LookLogAppender.setApplicationContext(applicationContext);   //此处增加spring上下文的注入
            }
        }
  5. 打开浏览器, 访问 http://{应用域名根目录}/lookLog

关于traceId

traceId即请求跟踪的ID, 如果在并发的情况下出现异常, 我们需要对出现异常的那次调用进行日志分析, 这个时候我们就可以根据traceId来进行过滤, 找出该次调用的所有日志进行分析.

looklog的traceId分两种

  • http请求

    默认已经实现了traceId,不需要增加额外的代码

  • 跑批

    需要加注解实现, 代码如下

        public class SimpleJob {
        
            @TraceIdJobFilter.TraceId       //此处增加注解即可
            public void doJob() {
                // do something...
            }
        
        }

looklog's People

Watchers

James Cloos avatar Changguo.Peng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.