项目作者: mfalcier

项目描述 :
Kotlin Annotation Logger
高级语言: Kotlin
项目地址: git://github.com/mfalcier/YesSir.git
创建时间: 2019-07-03T13:56:58Z
项目社区:https://github.com/mfalcier/YesSir

开源协议:

下载


YesSir

A Kotlin Autologger

Image of YesSir

This library provides an annotation, @LogMe that will log your functions in order to monitor their execution (with input parameters and results if those are available) and duration.
When a function is annotated, it will create a log before and after it’s execution, showing all the details.

For Example:

  1. class Foo {
  2. private val log = LoggerFactory.getLogger(this::class.java)
  3. @LogMe
  4. fun foo(name: String){
  5. Thread.sleep(1000) // I.E.
  6. val result = "Hello $name!"
  7. log.info(result)
  8. return result
  9. }
  10. }

When foo() is executed will result in:

  1. 23:29:26.969 [main] INFO com.mfalcier.yessir.Foo - [com.mfalcier.yessir.Foo.foo] has started its execution with parameters {name=Marco}
  2. 23:29:27.971 [main] INFO com.mfalcier.yessir.Foo - Hello Marco!
  3. 23:29:27.972 [main] INFO com.mfalcier.yessir.Foo - [com.mfalcier.yessir.Foo.foo] has ended its execution after 1000ms with result [Hello Marco!]

The @LogMe annotation can also be used on classes, in order to automatically log each of its method:

  1. @LogMe
  2. class Foo {
  3. private val log = LoggerFactory.getLogger(this::class.java)
  4. fun foo(){
  5. Thread.sleep(1000) // I.E.
  6. log.info("Hello World!")
  7. }
  8. }

In order to weave, your POM.xml plugins section must at least contains:

  1. <plugins>
  2. <!-- KAPT EXECUTION -->
  3. <plugin>
  4. <artifactId>kotlin-maven-plugin</artifactId>
  5. <configuration>
  6. <jvmTarget>1.8</jvmTarget>
  7. </configuration>
  8. <groupId>org.jetbrains.kotlin</groupId>
  9. <version>${kotlin.version}</version>
  10. <executions>
  11. <execution>
  12. <id>kapt</id>
  13. <goals>
  14. <goal>kapt</goal>
  15. </goals>
  16. </execution>
  17. <execution>
  18. <id>compile</id>
  19. <phase>compile</phase>
  20. <goals> <goal>compile</goal> </goals>
  21. </execution>
  22. <execution>
  23. <id>test-compile</id>
  24. <phase>test-compile</phase>
  25. <goals> <goal>test-compile</goal> </goals>
  26. </execution>
  27. </executions>
  28. </plugin>
  29. <!-- WEAVER -->
  30. <plugin>
  31. <groupId>com.jcabi</groupId>
  32. <artifactId>jcabi-maven-plugin</artifactId>
  33. <version>0.14.1</version>
  34. <configuration>
  35. <source>1.8</source>
  36. <target>1.8</target>
  37. </configuration>
  38. <executions>
  39. <execution>
  40. <goals>
  41. <goal>ajc</goal>
  42. </goals>
  43. </execution>
  44. </executions>
  45. <dependencies>
  46. <dependency>
  47. <groupId>org.aspectj</groupId>
  48. <artifactId>aspectjrt</artifactId>
  49. <version>${aspectj.version}</version>
  50. </dependency>
  51. <dependency>
  52. <groupId>org.aspectj</groupId>
  53. <artifactId>aspectjtools</artifactId>
  54. <version>${aspectj.version}</version>
  55. </dependency>
  56. </dependencies>
  57. </plugin>
  58. <!-- FAT JAR -->
  59. <plugin>
  60. <groupId>org.apache.maven.plugins</groupId>
  61. <artifactId>maven-shade-plugin</artifactId>
  62. <version>2.4.3</version>
  63. <executions>
  64. <execution>
  65. <phase>package</phase>
  66. <goals>
  67. <goal>shade</goal>
  68. </goals>
  69. </execution>
  70. </executions>
  71. </plugin>
  72. </plugins>

Dependencies

Maven:

  1. <dependency>
  2. <groupId>com.github.mfalcier</groupId>
  3. <artifactId>YesSir</artifactId>
  4. <version>1.1.0</version>
  5. </dependency>
  6. ...
  7. <repositories>
  8. <repository>
  9. <id>jitpack.io</id>
  10. <url>https://jitpack.io</url>
  11. </repository>
  12. </repositories>