Skip to content

Commit

Permalink
Initial logger wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
agentgt committed Sep 14, 2023
0 parents commit 64a30df
Show file tree
Hide file tree
Showing 29 changed files with 4,015 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: maven
directory: "/"
schedule:
interval: "daily"
open-pull-requests-limit: 10
49 changes: 49 additions & 0 deletions .github/workflows/apidoc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages

on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true

jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Pages
uses: actions/configure-pages@v2
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: mvn install
run: ./mvnw --batch-mode --no-transfer-progress -Pdoc clean install -DskipTests=true
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
# Upload entire repository
path: 'target/site/apidocs'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
39 changes: 39 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build with Maven

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest
env:
BUILD_NUMBER: "${{github.run_number}}"
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode --no-transfer-progress"

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Cache local Maven repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build and Test with Maven
run: ./mvnw $MAVEN_CLI_OPTS clean verify
- name: Upload Test Results
uses: actions/upload-artifact@v3
if: always()
with:
name: test-results
path: '**/target/surefire-reports/TEST-*.xml'
16 changes: 16 additions & 0 deletions .github/workflows/test-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: 'Test Report'
on:
workflow_run:
workflows: ['Build with Maven']
types:
- completed
jobs:
report:
runs-on: ubuntu-latest
steps:
- uses: dorny/test-reporter@v1
with:
artifact: test-results
name: Maven Surefire Tests
path: '**/target/surefire-reports/TEST-*.xml'
reporter: java-junit
45 changes: 45 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
*.class

# Package Files #
*.jar
*.war
*.ear
target
.classpath
.project
.settings
.factorypath
dependency-reduced-pom.xml

# OSX
*.DS_Store

# IntelliJ IDE Project Files #
*.iml
*.idea
*.versionsBackup
pom.xml.versionsBackup
jacoco.exec
.*.md.html
node
dump
TODO
.interp
tmp
checkstyle
#javadoc
*.mv.db
versions
out
node
node_modules
build
.gradle

# Emacs

\#*\#
.\#*

#VS code
.vscode
18 changes: 18 additions & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.4/apache-maven-3.9.4-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
17 changes: 17 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.jstach.rainbowgum</groupId>
<artifactId>rainbowgum-maven-parent</artifactId>
<version>0.1.3-SNAPSHOT</version>
</parent>
<artifactId>rainbowgum-core</artifactId>
<dependencies>
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
</dependency>
</dependencies>
</project>
20 changes: 20 additions & 0 deletions core/src/main/java/io/jstach/rainbowgum/LogAppender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.jstach.rainbowgum;

public interface LogAppender {

public void append(
LogEvent event);

public static LogAppender of(LogOutput output, LogFormatter formatter) {
return new DefaultLogAppender(output, formatter);
}
}

record DefaultLogAppender(LogOutput output, LogFormatter formatter) implements LogAppender {
@Override
public void append(
LogEvent event) {
formatter.format(output, event);

}
}
49 changes: 49 additions & 0 deletions core/src/main/java/io/jstach/rainbowgum/LogConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.jstach.rainbowgum;

import java.lang.System.Logger.Level;
import java.util.Map;
import java.util.function.Function;

import org.eclipse.jdt.annotation.Nullable;

public interface LogConfig {

@Nullable
String property(String key);

default LogEncoder defaultOutput() {
return LogEncoder.of(System.out);
}

default String hostName() {
String hostName = property("HOSTNAME");
if (hostName == null) {
return "localhost";
}
return hostName;
}

default Map<String, String> headers() {
return Map.of();
}

default @Nullable Level logLevel(String name) {
String s = property("log." + name);
if (s == null || s.isBlank()) {
return null;
}
return Level.valueOf(s);
}

public static LogConfig of(Function<String, @Nullable String> propertySupplier) {
return new LogConfig() {

@Override
public @Nullable String property(
String key) {
return "rainbowgum." + key;
}
};
}
}

48 changes: 48 additions & 0 deletions core/src/main/java/io/jstach/rainbowgum/LogEncoder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.jstach.rainbowgum;

import java.io.IOException;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;

public interface LogEncoder extends LogOutput {

@Override
default void append(
String s) {
encode(s.getBytes(StandardCharsets.UTF_8));
}

public void encode(byte[] bytes);

public void encode(byte[] bytes, int off, int len);

public static LogEncoder of(OutputStream out) {
return new LogEncoder() {

@Override
public void encode(
byte[] bytes,
int off,
int len) {
try {
out.write(bytes, off, len);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

@Override
public void encode(
byte[] bytes) {
try {
out.write(bytes);
} catch (IOException e) {
throw new UncheckedIOException(e);
}

}
};
}

}
59 changes: 59 additions & 0 deletions core/src/main/java/io/jstach/rainbowgum/LogEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.jstach.rainbowgum;

import java.time.Instant;
import java.util.Map;

import org.eclipse.jdt.annotation.Nullable;

public record LogEvent(
Instant timeStamp,
String threadName,
long threadId,
System.Logger.Level level,
String loggerName,
String loggerShortName,
String formattedMessage,
Map<String, String> keyValues,
@Nullable Throwable throwable) {

public @Nullable Throwable getThrowable() {
return throwable();
}

@SuppressWarnings({ "null", "exports" })
public Map<String, @Nullable String> getKeyValues() {
return keyValues;
}

public static LogEvent of(
System.Logger.Level level,
String loggerName,
String loggerShortName,
String formattedMessage,
Map<String, String> keyValues,
@Nullable Throwable throwable) {
Instant timeStamp = Instant.now();
Thread currentThread = Thread.currentThread();
String threadName = currentThread.getName();
long threadId = currentThread.getId();

return new LogEvent(
timeStamp,
threadName,
threadId,
level,
loggerName,
loggerName,
formattedMessage,
keyValues,
throwable);
}

public static LogEvent of(
System.Logger.Level level,
String loggerName,
String formattedMessage,
@Nullable Throwable throwable) {
return of(level, loggerName, loggerName, formattedMessage, Map.of(), throwable);
}
}
Loading

0 comments on commit 64a30df

Please sign in to comment.