Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions .travis.yml

This file was deleted.

57 changes: 4 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
[![Build Status](https://travis-ci.org/hmcts/java-logging.svg?branch=master)](https://travis-ci.org/hmcts/java-logging)
[![GitHub version](https://badge.fury.io/gh/hmcts%2Fjava-logging.svg)](https://badge.fury.io/gh/hmcts%2Fjava-logging)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/ebac86c131154ef2b59ab302d1d75fd9)](https://www.codacy.com/app/HMCTS/java-logging)
[![codecov](https://codecov.io/gh/hmcts/java-logging/branch/master/graph/badge.svg)](https://codecov.io/gh/hmcts/java-logging)
[![Known Vulnerabilities](https://snyk.io/test/github/hmcts/java-logging/badge.svg)](https://snyk.io/test/github/hmcts/java-logging)
[ ![Download](https://api.bintray.com/packages/hmcts/hmcts-maven/logging/images/download.svg) ](https://bintray.com/hmcts/hmcts-maven/logging/_latestVersion)

# Reform Java logging module
# Java logging

A Java module which standardises the logging for the reform projects.

## Prerequisites

- [Java 8](https://www.oracle.com/java)
- [Java 11](https://adoptium.net/)

## User guide

Expand All @@ -25,46 +22,13 @@ Simply add base component as your project's dependency and then one or more of t

Base component dependency, gradle:
```groovy
compile group: 'uk.gov.hmcts.reform', name: 'logging', version: '5.1.1'
implementation group: 'com.github.hmcts.java-logging', name: 'logging', version: '5.1.9'
```

#### java-logging-insights

Use for automatic configuration of Azure Application Insights for a Spring Boot project. [Read more](java-logging-appinsights/README.md)

#### java-logging-spring

Use for formatting log output in Spring Boot applications.


Gradle:
```groovy
compile group: 'uk.gov.hmcts.reform', name: 'logging-spring', version: '5.1.1'
```

#### java-logging-httpcomponents

Use for adding request IDs to external HTTP / HTTPS requests.

Gradle:
```groovy
compile group: 'uk.gov.hmcts.reform', name: 'logging-httpcomponents', version: '5.1.1'
```

**Please note:** You will also need to implement a class that configures an HTTP client with interceptors for outbound HTTP requests and responses. See https://github.com/hmcts/cmc-claim-store/blob/master/src/main/java/uk/gov/hmcts/cmc/claimstore/clients/RestClient.java#L98 for an example.

After that you can log like you would do with any [SLF4J](https://www.slf4j.org/) logger. Define it as a class field:

```java
private static final Logger log = LoggerFactory.getLogger(SomeResource.class);
```

And do the actual logging, e.g.:

```java
log.info("An important business process has finished");
```

### Configuration defaults

By default the module will use a simple, human-friendly logging format which can be used out-of-the-box for development:
Expand Down Expand Up @@ -143,19 +107,6 @@ To install the artifact to a local Maven repository:
./gradlew install
```

### Exception logging

Since [v1.5.0](https://github.com/hmcts/java-logging/releases/tag/1.5.0) Alert level and error code are required fields for any exception to be logged.
In order to correctly stream log events for all exceptions one must be extended with `AbstractLoggingException`.
Error code is introduced as legacy error group not minding the fact exceptions themselves represent relevant error group.
There is a helper `UnknownErrorCodeException` class which populates the field with `UNKNOWN` as error code.

Alert level is still required.

### Releasing

Run the script `./prepare-for-release.sh` select an appropriate version and follow the instructions the script provides

## Future development considerations

- [MDC](https://logback.qos.ch/manual/mdc.html) for capturing and logging request identifiers.
Create a release via the GitHub UI, the tag selected will be used as the version number
64 changes: 11 additions & 53 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
buildscript {
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
}
}

plugins {
id 'org.owasp.dependencycheck' version '6.3.2'
id 'org.owasp.dependencycheck' version '6.5.2.1'
id 'com.github.ben-manes.versions' version '0.39.0'
}

Expand All @@ -19,19 +13,18 @@ allprojects {
apply plugin: 'java-library'
apply plugin: 'maven-publish'
apply plugin: 'checkstyle'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'jacoco'
apply plugin: 'com.github.ben-manes.versions'
apply plugin: 'pmd'

checkstyle {
toolVersion = '8.24'
toolVersion = '9.2.1'
maxWarnings = 0
getConfigDirectory().set(new File(rootDir, "config/checkstyle"))
}

pmd {
toolVersion = "6.25.0"
toolVersion = "6.41.0"
ignoreFailures = true
incrementalAnalysis = true
sourceSets = [sourceSets.main, sourceSets.test]
Expand All @@ -43,36 +36,18 @@ allprojects {
toolVersion = "0.8.4"
}

sourceCompatibility = 1.8
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}

repositories {
mavenLocal()
mavenCentral()
jcenter()
}

configurations.all {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
if (details.requested.group in ['com.fasterxml.jackson.core', 'com.fasterxml.jackson.module', 'com.fasterxml.jackson.datatype']) {
details.useVersion '2.9.9'
}
if (details.requested.name == 'jackson-databind') {
details.useVersion '2.9.10'
}
if (details.requested.name == 'guava') {
details.useVersion '28.0-jre'
}
}
}
}

dependencies {
implementation group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: '6.6'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
implementation group: 'org.slf4j', name: 'jul-to-slf4j', version: '1.7.32'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.6'
api group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
}

Expand Down Expand Up @@ -112,10 +87,10 @@ task codeCoverageReport(type: JacocoReport, dependsOn: allprojects*.test) {
}

reports {
csv.enabled = false
html.enabled = true
csv.required = false
html.required = true
html.destination = file("${buildDir}/reports/jacoco/html")
xml.enabled = true
xml.required = true
xml.destination = file("${buildDir}/reports/jacoco/jacocoTestReport.xml")
}
}
Expand All @@ -136,23 +111,6 @@ publishing {
}
}

bintray {
user = System.getenv('BINTRAY_USER')
key = System.getenv('BINTRAY_KEY')
publications = ['Main']
publish = true
pkg {
repo = 'hmcts-maven'
name = 'logging'
userOrg = 'hmcts'
licenses = ['MIT']
vcsUrl = 'https://github.com/hmcts/java-logging'
version {
name = project.version
}
}
}

dependencies {
testImplementation group: 'org.mockito', name: 'mockito-core', version: '4.0.0'
testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.21.0'
Expand Down
4 changes: 0 additions & 4 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,9 @@
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
</module>
<module name="JavadocMethod">
<property name="scope" value="nothing"/>
<property name="allowMissingParamTags" value="true"/>
<property name="allowMissingThrowsTags" value="true"/>
<property name="allowMissingReturnTag" value="true"/>
<property name="minLineCount" value="2"/>
<property name="allowedAnnotations" value="Override, Test"/>
<property name="allowThrowsTagsForSubclasses" value="true"/>
</module>
<module name="MethodName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
38 changes: 9 additions & 29 deletions java-logging-appinsights/README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,30 @@
# Azure Application Insights

Logging module to auto configure necessary components for Azure Application Insights app. It uses [azure-application-insights-spring-boot-starter](https://github.com/Microsoft/ApplicationInsights-Java/tree/v2.3.1/azure-application-insights-spring-boot-starter) and adds some specific initializers as Spring beans. Module also tracks logback INFO events for `uk.gov.hmcts` loggers
Logging module to auto configure necessary components for Azure Application Insights app.
It uses [azure-application-insights-spring-boot-starter](https://github.com/Microsoft/ApplicationInsights-Java/tree/v2.3.1/azure-application-insights-spring-boot-starter) and adds some specific initializers as Spring beans.
Module also tracks logback INFO events for `uk.gov.hmcts` loggers

## User guide

The module provides all Telemetry modules and initializers available from web artifact.

### Basic usage

For now you need to add the HMCTS maven repository:

Maven:

```xml
<repositories>
<repository>
<id>hmcts-maven</id>
<name>HMCTS Maven</name>
<url>https://dl.bintray.com/hmcts/hmcts-maven</url>
</repository>
</repositories>

<dependency>
<groupId>uk.gov.hmcts.reform</groupId>
<artifactId>java-logging-appinsights</artifactId>
<version>5.1.1</version>
</dependency>
```

Gradle:

```groovy
repositories {
maven {
url "https://dl.bintray.com/hmcts/hmcts-maven"
}
maven { url 'https://jitpack.io' }
}

dependencies {
compile group: 'uk.gov.hmcts.reform', name: 'logging-appinsights', version: '5.1.1'
implementation group: 'com.github.hmcts.java-logging', name: 'logging-appinsights', version: '5.1.9'
}
```

It will automatically include Request Name interceptor and Request Tracking Filter configurations into spring boot web application.

Request Tracking Filter needs agent to be configured. By default agent uses built in configuration but you can provide your own.
Request Tracking Filter needs agent to be configured. By default agent uses built in configuration but you can provide your own.

Sample of `AI-Agent.xml`:

Expand All @@ -69,7 +49,7 @@ Retrieve the jar from github, i.e. https://github.com/Microsoft/ApplicationInsig
TelemetryClient can be `autowired` to implement custom telemetry metrics.

#### Provide Instrumentation Key

Set the environment variable: AZURE_APPLICATIONINSIGHTS_INSTRUMENTATIONKEY. If you are deploying using the CNP pipeline this will be automatically added for you.

You can also set it using a spring property (useful for tests):
Expand Down Expand Up @@ -132,7 +112,7 @@ Along with custom Source name there are more optional headers to be applied at w

[SyntheticHeaders](java-logging-appinsights/src/main/java/uk/gov/hmcts/reform/logging/appinsights/SyntheticHeaders) might be deprecated in future based on Microsoft making the constants public.

#### To disable Application insights completely
#### To disable Application insights completely

Refer [Spring Starter disabling App Insights](https://github.com/Microsoft/ApplicationInsights-Java/tree/v2.3.1/azure-application-insights-spring-boot-starter#completely-disable-application-insights-using-applicationproperties)

Expand Down Expand Up @@ -174,7 +154,7 @@ This configuration entry is also used by [`SpringBootTelemetryInitializer`](http

For Spring starter configurations , Refer [configure-more-parameters-using-applicationproperties](https://github.com/Microsoft/ApplicationInsights-Java/tree/v2.3.1/azure-application-insights-spring-boot-starter#configure-more-parameters-using-applicationproperties)

Additional properties :
Additional properties :
```properties
application-insights.custom.modules.ContextInitializer.enabled=true
application-insights.default.modules.TimestampPropertyInitializer.enabled=true
Expand Down
17 changes: 0 additions & 17 deletions java-logging-appinsights/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,6 @@ publishing {
}
}

bintray {
user = System.getenv('BINTRAY_USER')
key = System.getenv('BINTRAY_KEY')
publications = ['Insights']
publish = true
pkg {
repo = 'hmcts-maven'
name = 'logging-appinsights'
userOrg = 'hmcts'
licenses = ['MIT']
vcsUrl = 'https://github.com/hmcts/java-logging'
version {
name = project.version
}
}
}

repositories {
flatDir {
dirs "$projectDir/lib"
Expand Down
Loading