Skip to content

Commit 77ced8e

Browse files
author
Jose San Leandro
committed
version 0.1
- Logging and LoggingFactory API. - LoggingConfiguration producers are auto-discovered (if they are annotated). - LoggingConfiguration Listeners are auto-discovered (via inheritance). - LoggingConfigurationRegistry contains all valid logging configurations available. - LoggingAdapterBuilderRegistry contains all available logging adapter builders. - Included adapters for AWS Lambda and ElasticSearch (REST-based).
1 parent 3a46b18 commit 77ced8e

File tree

66 files changed

+4166
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+4166
-0
lines changed

.arcconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"project_id": "JavaLogging",
3+
"conduit_uri" : "http://phabricator.osoco.es",
4+
"arc.land.onto.default" : "develop"
5+
}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@
2020

2121
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2222
hs_err_pid*
23+
24+
.gradle/
25+
.idea/
26+
*.iml
27+
target/

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# How to contribute
2+
3+
Thank you for your interest.
4+
Please fork this repository and create a pull request. We take pull requests seriously.

README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,107 @@
11
# java-logging
22
A (yet another) Logging framework for Java / Groovy.
3+
4+
# Getting Started
5+
6+
This framework provides your application multiple logging capabilities hiding you the details of how it's working internally.
7+
You express your logging preferences using the `@LoggingPreferences` annotation. Within that execution context, your preferences will be honored.
8+
To log a message, you just need to call `LoggingFactory.getInstance().createLogging()`. It will return a `Logging` instance which gives you the methods you are expecting: `info(String)`, `debug(String)` and the like.
9+
10+
Besides that, the `Logging` instance also provides you a way to pass additional context information so that the logging mechanism can optionally use it. By calling `Logging#getLoggingContext()`, you get a `LoggingContext`, which is a Map-like API storing the information locally to the thread.
11+
12+
# Prerequisites
13+
14+
First, add Java-Logging as dependency in your `pom.xml` or `build.gradle`.
15+
16+
## Maven dependency
17+
18+
Currently we're in the process of releasing the pre-built binaries to jcenter(). The Maven dependency will be:
19+
20+
```
21+
<dependency>
22+
<groupId>es.osoco.logging</groupId>
23+
<artifactId>java-logging</artifactId>
24+
<version>0.1</version>
25+
</dependency>
26+
```
27+
28+
## Gradle coordinates
29+
30+
Similarly, the Gradle coordinates are:
31+
32+
```
33+
dependencies {
34+
compile(es.osoco.logging:java-logging:0.1)
35+
}
36+
```
37+
38+
# Usage
39+
40+
When your code needs to log anything, first import the required classes:
41+
```
42+
import es.osoco.logging.Logging;
43+
import es.osoco.logging.LoggingFactory;
44+
```
45+
46+
Then, retrieve the `Logging` instance using the `LoggingFactory`:
47+
```
48+
Logging logging = LogFactory.getLogging();
49+
```
50+
51+
Once you have the `Logging` instance, use it for, well, logging:
52+
```
53+
logging.info("Use case started");
54+
```
55+
56+
## Logging preferences
57+
58+
The underlying logging mechanisms are auto-discovered at runtime. However, you can
59+
specify your preferences, by using the `@LoggingPreferences` annotation either in a method or a class.
60+
Your preferences will define which logging will be used, in the execution context they are defined.
61+
The general use case is to define your preferences in the application's entry points.
62+
That way, they'll "stick" to all the code run within that execution flow.
63+
64+
For example, you could express your preferences in a `static void main()` method:
65+
```
66+
import es.osoco.logging.LoggingFactory;
67+
import es.osoco.logging.annotations.LoggingPreferences;
68+
69+
public class EntryPoint {
70+
@LoggingPreferences(preferred="ElasticSearch", fallback="System.err")
71+
public static void main(String[] args) {
72+
LoggingFactory.getInstance().createLogging().info("Application started");
73+
}
74+
}
75+
```
76+
77+
## Building it yourself
78+
79+
To build the artifact(s) yourself, just install Maven (2 or 3) and run
80+
```
81+
mvn install
82+
```
83+
84+
It will generate the artifacts under the `target/` folder.
85+
86+
# Running the tests
87+
88+
Java-Logging uses Spock as testing framework. To run the specifications, run
89+
90+
```
91+
mvn test
92+
```
93+
94+
# Contributing
95+
96+
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
97+
98+
# Versioning
99+
100+
# Authors
101+
102+
# License
103+
104+
This project is licensed under the GPLv3 License - see the LICENSE.md file for details
105+
106+
# Acknowledgments
107+

build.gradle

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
project.version = '0.2-SNAPSHOT'
2+
3+
buildscript {
4+
repositories {
5+
jcenter()
6+
}
7+
dependencies {
8+
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3'
9+
classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.9'
10+
classpath "net.saliman:gradle-cobertura-plugin:2.4.0"
11+
}
12+
}
13+
14+
apply plugin: 'java'
15+
apply plugin: 'groovy'
16+
apply plugin: 'org.asciidoctor.convert'
17+
apply plugin: "net.saliman.cobertura"
18+
19+
repositories {
20+
mavenCentral()
21+
maven {
22+
url 'http://nexus.osoco.es/repository/maven-public'
23+
}
24+
}
25+
26+
ext.targetJavaVersion = JavaVersion.VERSION_1_8
27+
28+
configurations {
29+
checkerFrameworkAnnotatedJDK {
30+
description = 'a copy of JDK classes with Checker Framework type qualifers inserted'
31+
}
32+
checkerFramework {
33+
description = 'The Checker Framework: custom pluggable types for Java'
34+
}
35+
}
36+
37+
dependencies {
38+
compile(
39+
'io.github.lukehutch:fast-classpath-scanner:LATEST',
40+
'com.amazonaws:aws-lambda-java-core:1.1.0',
41+
'com.amazonaws:aws-lambda-java-events:1.1.0',
42+
'com.amazonaws:aws-java-sdk-dynamodb:1.11.52',
43+
"org.projectlombok:lombok:1.16.12",
44+
'com.xebia:jackson-lombok:1.1',
45+
'org.elasticsearch.client:rest:5.1.2',
46+
'org.apache.httpcomponents:httpcore:4.4.5',
47+
'org.apache.httpcomponents:httpcore-nio:4.4.5',
48+
'org.apache.httpcomponents:httpasyncclient:4.1.2',
49+
'commons-validator:commons-validator:1.6',
50+
'com.google.code.gson:gson:2.8.0'
51+
)
52+
53+
testCompile 'junit:junit:4.12'
54+
testCompile 'org.codehaus.groovy:groovy-all:2.4.4'
55+
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
56+
testRuntime "org.slf4j:slf4j-api:1.7.10"
57+
testCompile 'info.cukes:cucumber-groovy:1.2.5'
58+
testCompile 'info.cukes:cucumber-junit:1.2.5'
59+
60+
testCompile 'info.cukes:cucumber-picocontainer:1.2.5'
61+
testCompile 'org.picocontainer:picocontainer:2.14'
62+
testCompile 'org.hamcrest:hamcrest-library:1.3'
63+
64+
testCompile 'cglib:cglib-nodep:3.2.4'
65+
testCompile 'org.objenesis:objenesis:2.4'
66+
67+
ext.checkerFrameworkVersion = '2.1.6'
68+
ext.jdkVersion = 'jdk8'
69+
checkerFrameworkAnnotatedJDK "org.checkerframework:${jdkVersion}:${checkerFrameworkVersion}"
70+
71+
// checkerFrameworkJavac "org.checkerframework:compiler:${checkerFrameworkVersion}"
72+
checkerFramework "org.checkerframework:checker:${checkerFrameworkVersion}"
73+
compile "org.checkerframework:checker-qual:${checkerFrameworkVersion}"
74+
}
75+
76+
apply plugin: 'maven'
77+
78+
task buildZip(type: Zip) {
79+
baseName = "bbva-ats-forms"
80+
from compileJava
81+
from processResources
82+
into('lib') {
83+
from configurations.runtime
84+
}
85+
}
86+
87+
build.dependsOn buildZip
88+
89+
task wrapper(type: Wrapper) {
90+
gradleVersion = '3.1'
91+
}
92+
93+
test {
94+
testLogging {
95+
showStandardStreams = true
96+
exceptionFormat = 'full'
97+
}
98+
systemProperties System.getProperties()
99+
outputs.upToDateWhen { false }
100+
}
101+
102+
103+
tasks.withType(Test) {
104+
reports.html.destination = file("${reporting.baseDir}/${name}")
105+
}
106+
107+
task generateCukesDoc(type: JavaExec) {
108+
classpath buildscript.configurations.classpath
109+
main = 'com.github.cukedoctor.CukedoctorMain'
110+
args = ['-o', 'build/cucumber/living-specs.adoc',
111+
'-p', 'build/reports/cucumber/cucumber.json',
112+
'-toc', 'left',
113+
'-t', '\"BBVA-ATS-Forms Living Specs\"']
114+
}
115+
116+
asciidoctor {
117+
dependsOn generateCukesDoc
118+
sourceDir = file('src/docs')
119+
outputDir = file("${buildDir}/docs")
120+
separateOutputDirs = true
121+
options doctype: 'book'
122+
123+
System.setProperty("cukedoctor.disable.filter", "true")
124+
System.setProperty("cukedoctor.disable.theme", "true")
125+
126+
backends = ['html5']
127+
attributes 'source-highlighter': 'coderay',
128+
'coderay-linenums-mode': 'table',
129+
icon: 'font',
130+
linkattrs: true,
131+
encoding: 'utf-8'
132+
}
133+
134+
asciidoctor.doFirst {
135+
copy {
136+
from "${buildDir}/cucumber"
137+
into "src/docs"
138+
include 'living-specs.adoc'
139+
}
140+
}
141+
142+
if (project.hasProperty('doc')) {
143+
test.finalizedBy asciidoctor
144+
}
145+
146+
allprojects {
147+
tasks.withType(JavaCompile).all { JavaCompile compile ->
148+
compile.options.compilerArgs = [
149+
'-processor', 'org.checkerframework.checker.nullness.NullnessChecker',
150+
'-processorpath', "${configurations.checkerFramework.asPath}",
151+
// uncomment to turn Checker Framework errors into warnings
152+
'-Awarns',
153+
'-AprintErrorStack',
154+
"-Xbootclasspath/p:${configurations.checkerFrameworkAnnotatedJDK.asPath}"
155+
]
156+
}
157+
}
158+
159+
test {
160+
testLogging {
161+
showStandardStreams = true
162+
exceptionFormat = 'full'
163+
}
164+
// testClassesDir = sourceSets.integrationTest.output.classesDir
165+
// classpath = sourceSets.integrationTest.runtimeClasspath
166+
167+
outputs.upToDateWhen { false }
168+
}
169+
170+
// apply from: 'integrationTest.gradle'
171+
172+
//check.dependsOn integrationTest
173+
//integrationTest.mustRunAfter test

0 commit comments

Comments
 (0)