Giter Club home page Giter Club logo

java-stream-api-logger's Introduction

Travis CI

Java Stream API Logger

Java Stream API Logger is an instrumentation library for logging of API methods returning Stream. It is needed when you want to understand what happens in the Streams created inside of your code.

Command Line to Use the Logger

java -Xbootclasspath/a:javassist-3.25.0-GA.jar;slf4j-api-2.0.0-alpha0.jar;java-stream-api-logger-1.0.jar -javaagent:java-stream-api-logger-1.0.jar <YourClass>

-Xbootclasspath/a is needed because java-stream-api-logger-1.0.jar contains a class injected into instrumented classes. javassist-3.25.0-GA.jar;slf4j-api-2.0.0-alpha0.jar are needed because java-stream-api-logger-1.0.jar uses them.

Dependencies

Your project needs to have a runtime dependency to any SLF4J implementation, e.g. runtime 'ch.qos.logback:logback-classic:1.3.0-alpha4', to see log messages.

Example

Code

package com.peshchuk.java.stream.api.logger.demo;

import java.util.stream.Stream;

public class Test {

  public static void main(String[] args) {
    final Integer min = Stream.iterate(1, i -> i + 1)
        .sequential()
        .map(i -> i + 1)
        .limit(5)
        .filter(i -> i % 2 == 0)
        .skip(1)
        .distinct()
        .sorted()
        .peek(i -> System.out.printf("Peek: %d\n", i))
        .min(Integer::compareTo)
        .orElse(-1);
    System.out.printf("Min: %d\n\n", min);
  }
}

Output

22:29:35.337 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.iterate - 1 (Test.java:17)
22:29:35.339 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.map - 2 (Test.java:17)
22:29:35.340 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.limit - 2 (Test.java:17)
22:29:35.340 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.filter - 2 (Test.java:17)
22:29:35.340 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.iterate - 2 (Test.java:17)
22:29:35.340 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.map - 3 (Test.java:17)
22:29:35.340 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.limit - 3 (Test.java:17)
22:29:35.340 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.iterate - 3 (Test.java:17)
22:29:35.340 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.map - 4 (Test.java:17)
22:29:35.340 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.limit - 4 (Test.java:17)
22:29:35.340 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.filter - 4 (Test.java:17)
22:29:35.340 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.skip - 4 (Test.java:17)
22:29:35.340 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.distinct - 4 (Test.java:17)
22:29:35.340 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.iterate - 4 (Test.java:17)
22:29:35.340 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.map - 5 (Test.java:17)
22:29:35.341 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.limit - 5 (Test.java:17)
22:29:35.341 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.iterate - 5 (Test.java:17)
22:29:35.341 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.map - 6 (Test.java:17)
22:29:35.341 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.limit - 6 (Test.java:17)
22:29:35.341 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.filter - 6 (Test.java:17)
22:29:35.341 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.skip - 6 (Test.java:17)
22:29:35.341 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.distinct - 6 (Test.java:17)
22:29:35.342 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.sorted - 4 (Test.java:17)
Peek: 4
22:29:35.345 [main] DEBUG com.peshchuk.java.stream.api.logger.demo.Test.main.sorted - 6 (Test.java:17)
Peek: 6
Min: 4


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.