Skip to content

Commit 46e32d1

Browse files
Use SLF4J to allow easily routing logs to multiple logging frameworks (#33)
Use SLF4J to allow easily routing logs to multiple logging frameworks Co-authored-by: Andre Brait <[email protected]>
1 parent 328ad43 commit 46e32d1

File tree

10 files changed

+59
-598
lines changed

10 files changed

+59
-598
lines changed

pom.xml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ JUG supports all 3 official UUID generation methods.
4343
</prerequisites>
4444
<properties>
4545
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
46-
<log4j.version>1.2.17</log4j.version>
46+
<slf4j.version>1.7.29</slf4j.version>
4747
</properties>
4848
<licenses>
4949
<license>
@@ -60,13 +60,19 @@ JUG supports all 3 official UUID generation methods.
6060
<!-- Dependency information -->
6161

6262
<dependencies>
63-
<dependency> <!-- log4j is optional, but needed for compilation -->
64-
<groupId>log4j</groupId>
65-
<artifactId>log4j</artifactId>
66-
<version>${log4j.version}</version>
67-
<scope>provided</scope>
63+
<dependency>
64+
<groupId>org.slf4j</groupId>
65+
<artifactId>slf4j-api</artifactId>
66+
<version>${slf4j.version}</version>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.slf4j</groupId>
70+
<artifactId>slf4j-simple</artifactId>
71+
<version>${slf4j.version}</version>
72+
<scope>runtime</scope>
73+
<optional>true</optional>
6874
</dependency>
69-
<!-- and for testing, JUnit is needed -->
75+
<!-- For testing, JUnit is needed -->
7076
<dependency>
7177
<groupId>junit</groupId>
7278
<artifactId>junit</artifactId>
@@ -90,6 +96,7 @@ JUG supports all 3 official UUID generation methods.
9096
<plugin><!-- plug-in to attach source bundle in repo -->
9197
<groupId>org.apache.maven.plugins</groupId>
9298
<artifactId>maven-source-plugin</artifactId>
99+
<version>${version.plugin.source}</version>
93100
<executions>
94101
<execution>
95102
<id>attach-sources</id>
@@ -135,12 +142,10 @@ JUG supports all 3 official UUID generation methods.
135142
<Import-Package>
136143
com.fasterxml.uuid;version="[${project.version},${project.version}]",
137144
com.fasterxml.uuid.ext;version="[${project.version},${project.version}]",
138-
com.fasterxml.uuid.impl;version="[${project.version},${project.version}]"
145+
com.fasterxml.uuid.impl;version="[${project.version},${project.version}]",
146+
org.slf4j;version="[${slf4j.version},)"
139147
</Import-Package>
140148
<Private-Package />
141-
<DynamicImport-Package>
142-
org.apache.log4j;version="[${log4j.version},1.3)"
143-
</DynamicImport-Package>
144149
</instructions>
145150
</configuration>
146151
</plugin>

src/main/java/com/fasterxml/uuid/Logger.java

Lines changed: 0 additions & 290 deletions
This file was deleted.

src/main/java/com/fasterxml/uuid/UUIDTimer.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
import com.fasterxml.uuid.impl.UUIDUtil;
2222

23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
25+
2326
/**
2427
* UUIDTimer produces the time stamps required for time-based UUIDs.
2528
* It works as outlined in the UUID specification, with following
@@ -72,6 +75,9 @@
7275
*/
7376
public class UUIDTimer
7477
{
78+
79+
private static final Logger logger = LoggerFactory.getLogger(UUIDTimer.class);
80+
7581
// // // Constants
7682

7783
/**
@@ -241,7 +247,7 @@ public synchronized long getTimestamp()
241247
* independent of whether we can use it:
242248
*/
243249
if (systime < _lastSystemTimestamp) {
244-
Logger.logWarning("System time going backwards! (got value "+systime+", last "+_lastSystemTimestamp);
250+
logger.warn("System time going backwards! (got value {}, last {}", systime, _lastSystemTimestamp);
245251
// Let's write it down, still
246252
_lastSystemTimestamp = systime;
247253
}
@@ -261,7 +267,7 @@ public synchronized long getTimestamp()
261267
long origTime = systime;
262268
systime = _lastUsedTimestamp + 1L;
263269

264-
Logger.logWarning("Timestamp over-run: need to reinitialize random sequence");
270+
logger.warn("Timestamp over-run: need to reinitialize random sequence");
265271

266272
/* Clock counter is now at exactly the multiplier; no use
267273
* just anding its value. So, we better get some random
@@ -382,7 +388,7 @@ protected static void slowDown(long startTime, long actDiff)
382388
} else {
383389
delay = 5L;
384390
}
385-
Logger.logWarning("Need to wait for "+delay+" milliseconds; virtual clock advanced too far in the future");
391+
logger.warn("Need to wait for {} milliseconds; virtual clock advanced too far in the future", delay);
386392
long waitUntil = startTime + delay;
387393
int counter = 0;
388394
do {

0 commit comments

Comments
 (0)