-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add com.io7m.anethum.slf4j module for convenient logging.
- Loading branch information
Showing
8 changed files
with
314 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<artifactId>com.io7m.anethum</artifactId> | ||
<groupId>com.io7m.anethum</groupId> | ||
<version>1.1.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>com.io7m.anethum.slf4j</artifactId> | ||
|
||
<packaging>jar</packaging> | ||
<name>com.io7m.anethum.slf4j</name> | ||
<description>Generic parser API (SLF4J)</description> | ||
<url>https://www.io7m.com/software/anethum</url> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>com.io7m.anethum.api</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.io7m.jlexing</groupId> | ||
<artifactId>com.io7m.jlexing.core</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.osgi</groupId> | ||
<artifactId>org.osgi.annotation.bundle</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.osgi</groupId> | ||
<artifactId>org.osgi.annotation.versioning</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
114 changes: 114 additions & 0 deletions
114
com.io7m.anethum.slf4j/src/main/java/com/io7m/anethum/slf4j/ParseStatusLogging.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright © 2023 Mark Raynsford <code@io7m.com> https://www.io7m.com | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR | ||
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
|
||
|
||
package com.io7m.anethum.slf4j; | ||
|
||
import com.io7m.anethum.api.ParseStatus; | ||
import org.slf4j.Logger; | ||
|
||
/** | ||
* Functions to log parse status messages. | ||
*/ | ||
|
||
public final class ParseStatusLogging | ||
{ | ||
private ParseStatusLogging() | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* Log a status message. | ||
* | ||
* @param logger The logger | ||
* @param status The status | ||
*/ | ||
|
||
public static void logMinimal( | ||
final Logger logger, | ||
final ParseStatus status) | ||
{ | ||
switch (status.severity()) { | ||
case PARSE_INFO -> { | ||
logger.info( | ||
"{}:{}: {}", | ||
Integer.valueOf(status.lexical().line()), | ||
Integer.valueOf(status.lexical().column()), | ||
status.message() | ||
); | ||
} | ||
case PARSE_WARNING -> { | ||
logger.warn( | ||
"{}:{}: {}", | ||
Integer.valueOf(status.lexical().line()), | ||
Integer.valueOf(status.lexical().column()), | ||
status.message() | ||
); | ||
} | ||
case PARSE_ERROR -> { | ||
logger.error( | ||
"{}:{}: {}", | ||
Integer.valueOf(status.lexical().line()), | ||
Integer.valueOf(status.lexical().column()), | ||
status.message() | ||
); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Log a status message. | ||
* | ||
* @param logger The logger | ||
* @param status The status | ||
*/ | ||
|
||
public static void logWithErrorCode( | ||
final Logger logger, | ||
final ParseStatus status) | ||
{ | ||
switch (status.severity()) { | ||
case PARSE_INFO -> { | ||
logger.info( | ||
"{}:{}: {}: {}", | ||
Integer.valueOf(status.lexical().line()), | ||
Integer.valueOf(status.lexical().column()), | ||
status.errorCode(), | ||
status.message() | ||
); | ||
} | ||
case PARSE_WARNING -> { | ||
logger.warn( | ||
"{}:{}: {}: {}", | ||
Integer.valueOf(status.lexical().line()), | ||
Integer.valueOf(status.lexical().column()), | ||
status.errorCode(), | ||
status.message() | ||
); | ||
} | ||
case PARSE_ERROR -> { | ||
logger.error( | ||
"{}:{}: {}: {}", | ||
Integer.valueOf(status.lexical().line()), | ||
Integer.valueOf(status.lexical().column()), | ||
status.errorCode(), | ||
status.message() | ||
); | ||
} | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
com.io7m.anethum.slf4j/src/main/java/com/io7m/anethum/slf4j/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright © 2023 Mark Raynsford <code@io7m.com> http://io7m.com | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR | ||
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
|
||
/** | ||
* Generic parser API (SLF4J Functions) | ||
*/ | ||
|
||
@Export | ||
@Version("1.0.0") | ||
package com.io7m.anethum.slf4j; | ||
|
||
import org.osgi.annotation.bundle.Export; | ||
import org.osgi.annotation.versioning.Version; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright © 2023 Mark Raynsford <code@io7m.com> https://www.io7m.com | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR | ||
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
|
||
/** | ||
* Generic parser API (SLF4J Functions) | ||
*/ | ||
|
||
module com.io7m.anethum.slf4j | ||
{ | ||
requires static org.osgi.annotation.bundle; | ||
requires static org.osgi.annotation.versioning; | ||
|
||
requires com.io7m.anethum.api; | ||
|
||
requires com.io7m.jlexing.core; | ||
requires org.slf4j; | ||
|
||
exports com.io7m.anethum.slf4j; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters