diff --git a/nostr-java-api/src/main/java/nostr/api/NIP04.java b/nostr-java-api/src/main/java/nostr/api/NIP04.java index fb8218622..62a0665df 100644 --- a/nostr-java-api/src/main/java/nostr/api/NIP04.java +++ b/nostr-java-api/src/main/java/nostr/api/NIP04.java @@ -5,7 +5,7 @@ package nostr.api; import lombok.NonNull; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import nostr.api.factory.impl.GenericEventFactory; import nostr.base.PublicKey; import nostr.config.Constants; @@ -24,7 +24,7 @@ /** * @author eric */ -@Log +@Slf4j public class NIP04 extends EventNostr { public NIP04(@NonNull Identity sender, @NonNull PublicKey recipient) { @@ -38,6 +38,7 @@ public NIP04(@NonNull Identity sender, @NonNull PublicKey recipient) { * @param content the DM content in clear-text */ public NIP04 createDirectMessageEvent(@NonNull String content) { + log.debug("Creating direct message event"); var encryptedContent = encrypt(getSender(), content, getRecipient()); List tags = List.of(new PubKeyTag(getRecipient())); @@ -64,6 +65,7 @@ public NIP04 encrypt() { * @return the encrypted message */ public static String encrypt(@NonNull Identity senderId, @NonNull String message, @NonNull PublicKey recipient) { + log.debug("Encrypting message from {} to {}", senderId.getPublicKey(), recipient); MessageCipher cipher = new MessageCipher04(senderId.getPrivateKey().getRawData(), recipient.getRawData()); return cipher.encrypt(message); } @@ -77,6 +79,7 @@ public static String encrypt(@NonNull Identity senderId, @NonNull String message * @return the DM content in clear-text */ public static String decrypt(@NonNull Identity identity, @NonNull String encryptedMessage, @NonNull PublicKey recipient) { + log.debug("Decrypting message for {}", identity.getPublicKey()); MessageCipher cipher = new MessageCipher04(identity.getPrivateKey().getRawData(), recipient.getRawData()); return cipher.decrypt(encryptedMessage); } @@ -124,12 +127,14 @@ public static String decrypt(@NonNull Identity rcptId, @NonNull GenericEvent eve boolean rcptFlag = amITheRecipient(rcptId, event); if (!rcptFlag) { // I am the message sender + log.debug("Decrypting own sent message"); MessageCipher cipher = new MessageCipher04(rcptId.getPrivateKey().getRawData(), pTag.getPublicKey().getRawData()); return cipher.decrypt(event.getContent()); } // I am the message recipient var sender = event.getPubKey(); + log.debug("Decrypting message from {}", sender); MessageCipher cipher = new MessageCipher04(rcptId.getPrivateKey().getRawData(), sender.getRawData()); return cipher.decrypt(event.getContent()); } diff --git a/nostr-java-api/src/main/java/nostr/api/NIP44.java b/nostr-java-api/src/main/java/nostr/api/NIP44.java index 65a9d67fc..cb7a38d07 100644 --- a/nostr-java-api/src/main/java/nostr/api/NIP44.java +++ b/nostr-java-api/src/main/java/nostr/api/NIP44.java @@ -1,7 +1,7 @@ package nostr.api; import lombok.NonNull; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import nostr.base.PublicKey; import nostr.encryption.MessageCipher; import nostr.encryption.MessageCipher44; @@ -13,9 +13,8 @@ import java.util.NoSuchElementException; import java.util.Objects; -import java.util.logging.Level; -@Log +@Slf4j public class NIP44 extends EventNostr { public static String encrypt(@NonNull Identity sender, @NonNull String message, @NonNull PublicKey recipient) { @@ -47,7 +46,7 @@ public static String decrypt(@NonNull Identity recipient, @NonNull GenericEvent // I am the message recipient var sender = event.getPubKey(); - log.log(Level.FINE, "The message is being decrypted for {0}", sender); + log.debug("Decrypting message for {}", sender); MessageCipher cipher = new MessageCipher44(recipient.getPrivateKey().getRawData(), sender.getRawData()); return cipher.decrypt(event.getContent()); } diff --git a/nostr-java-api/src/main/java/nostr/api/NIP46.java b/nostr-java-api/src/main/java/nostr/api/NIP46.java index 9c2620f1d..1425d46d6 100644 --- a/nostr-java-api/src/main/java/nostr/api/NIP46.java +++ b/nostr-java-api/src/main/java/nostr/api/NIP46.java @@ -5,7 +5,7 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import nostr.api.factory.impl.GenericEventFactory; import nostr.base.PublicKey; import nostr.config.Constants; @@ -15,10 +15,10 @@ import java.io.Serializable; import java.util.LinkedHashSet; import java.util.Set; -import java.util.logging.Level; import static nostr.base.IEvent.MAPPER_AFTERBURNER; +@Slf4j public final class NIP46 extends EventNostr { public NIP46(@NonNull Identity sender) { @@ -55,7 +55,7 @@ public NIP46 createResponseEvent(@NonNull NIP46.Response response, @NonNull Publ @Data @AllArgsConstructor @NoArgsConstructor - @Log + @Slf4j public static final class Request implements Serializable { private String id; private String method; @@ -70,8 +70,7 @@ public String toString() { try { return MAPPER_AFTERBURNER.writeValueAsString(this); } catch (JsonProcessingException ex) { - // Handle the exception if needed - log.log(Level.WARNING, "Error converting to JSON: {0}", ex.getMessage()); + log.warn("Error converting request to JSON: {}", ex.getMessage()); return "{}"; // Return an empty JSON object as a fallback } } @@ -88,7 +87,7 @@ public static Request fromString(@NonNull String jsonString) { @Data @AllArgsConstructor @NoArgsConstructor - @Log + @Slf4j public static final class Response implements Serializable { private String id; private String error; @@ -98,8 +97,7 @@ public String toString() { try { return MAPPER_AFTERBURNER.writeValueAsString(this); } catch (JsonProcessingException ex) { - // Handle the exception if needed - log.log(Level.WARNING, "Error converting to JSON: {0}", ex.getMessage()); + log.warn("Error converting response to JSON: {}", ex.getMessage()); return "{}"; // Return an empty JSON object as a fallback } } diff --git a/nostr-java-api/src/test/java/nostr/api/integration/ApiEventIT.java b/nostr-java-api/src/test/java/nostr/api/integration/ApiEventIT.java index 0052983e0..cc711d56e 100644 --- a/nostr-java-api/src/test/java/nostr/api/integration/ApiEventIT.java +++ b/nostr-java-api/src/test/java/nostr/api/integration/ApiEventIT.java @@ -1,7 +1,7 @@ package nostr.api.integration; import com.fasterxml.jackson.core.JsonProcessingException; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import nostr.api.EventNostr; import nostr.api.NIP01; import nostr.api.NIP04; @@ -54,7 +54,6 @@ import java.util.Map; import java.util.Optional; import java.util.UUID; -import java.util.logging.Level; import static nostr.base.IEvent.MAPPER_AFTERBURNER; import static org.awaitility.Awaitility.await; @@ -66,8 +65,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; @SpringJUnitConfig(RelayConfig.class) -@ActiveProfiles("test") -@Log +@Slf4j @Disabled("Requires running relay at ws://localhost:5555") public class ApiEventIT { @Autowired diff --git a/nostr-java-api/src/test/java/nostr/api/unit/JsonParseTest.java b/nostr-java-api/src/test/java/nostr/api/unit/JsonParseTest.java index 5615dcfa8..385820929 100644 --- a/nostr-java-api/src/test/java/nostr/api/unit/JsonParseTest.java +++ b/nostr-java-api/src/test/java/nostr/api/unit/JsonParseTest.java @@ -1,7 +1,7 @@ package nostr.api.unit; import com.fasterxml.jackson.core.JsonProcessingException; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import nostr.api.NIP01; import nostr.api.util.JsonComparator; import nostr.base.Command; @@ -61,7 +61,7 @@ /** * @author eric */ -@Log +@Slf4j public class JsonParseTest { @Test public void testBaseMessageDecoderEventFilter() throws JsonProcessingException { diff --git a/nostr-java-api/src/test/java/nostr/api/unit/NIP57ImplTest.java b/nostr-java-api/src/test/java/nostr/api/unit/NIP57ImplTest.java index af7d05325..cfd3d601e 100644 --- a/nostr-java-api/src/test/java/nostr/api/unit/NIP57ImplTest.java +++ b/nostr-java-api/src/test/java/nostr/api/unit/NIP57ImplTest.java @@ -1,6 +1,6 @@ package nostr.api.unit; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import nostr.api.NIP57; import nostr.base.ElementAttribute; import nostr.base.PublicKey; @@ -18,7 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; -@Log +@Slf4j public class NIP57ImplTest { @Test diff --git a/nostr-java-base/src/main/java/nostr/base/Relay.java b/nostr-java-base/src/main/java/nostr/base/Relay.java index 525f6fb60..8b3e6d61b 100644 --- a/nostr-java-base/src/main/java/nostr/base/Relay.java +++ b/nostr-java-base/src/main/java/nostr/base/Relay.java @@ -9,7 +9,7 @@ import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.ToString; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import java.util.ArrayList; import java.util.List; @@ -22,7 +22,7 @@ @ToString(onlyExplicitlyIncluded = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true) @AllArgsConstructor -@Log +@Slf4j public class Relay { @EqualsAndHashCode.Include @@ -47,6 +47,7 @@ public Relay(@NonNull String uri, RelayInformationDocument doc) { } this.scheme = s[0]; this.host = s[1]; + log.debug("Created relay with scheme {} and host {}", this.scheme, this.host); } // Helper method diff --git a/nostr-java-crypto/src/main/java/nostr/crypto/nip44/EncryptedPayloads.java b/nostr-java-crypto/src/main/java/nostr/crypto/nip44/EncryptedPayloads.java index 3547a8033..00db8068c 100644 --- a/nostr-java-crypto/src/main/java/nostr/crypto/nip44/EncryptedPayloads.java +++ b/nostr-java-crypto/src/main/java/nostr/crypto/nip44/EncryptedPayloads.java @@ -1,7 +1,7 @@ package nostr.crypto.nip44; import lombok.NonNull; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import org.bouncycastle.crypto.digests.SHA256Digest; import org.bouncycastle.crypto.generators.HKDFBytesGenerator; import org.bouncycastle.crypto.params.ECDomainParameters; @@ -28,9 +28,8 @@ import java.security.spec.KeySpec; import java.util.Arrays; import java.util.Base64; -import java.util.logging.Level; -@Log +@Slf4j public class EncryptedPayloads { public static String encrypt(String plaintext, byte[] conversationKey, byte[] nonce) throws Exception { @@ -78,7 +77,7 @@ public static String decrypt(String payload, byte[] conversationKey) throws Exce byte[] calculatedMac = hmac.doFinal(); if (!MessageDigest.isEqual(calculatedMac, mac)) { - log.log(Level.FINE, "Calculated MAC = {0} --- Mac = {1}", new Object[]{Arrays.toString(calculatedMac), Arrays.toString(mac)}); + log.debug("Calculated MAC {} does not match expected {}", Arrays.toString(calculatedMac), Arrays.toString(mac)); throw new Exception("Invalid MAC"); } diff --git a/nostr-java-event/src/main/java/nostr/event/entities/UserProfile.java b/nostr-java-event/src/main/java/nostr/event/entities/UserProfile.java index 79cac752c..fb23fc4aa 100644 --- a/nostr-java-event/src/main/java/nostr/event/entities/UserProfile.java +++ b/nostr-java-event/src/main/java/nostr/event/entities/UserProfile.java @@ -1,7 +1,6 @@ package nostr.event.entities; import java.net.URL; -import java.util.logging.Level; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.core.JsonProcessingException; @@ -10,7 +9,7 @@ import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.experimental.SuperBuilder; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import nostr.base.IBech32Encodable; import nostr.base.PublicKey; import nostr.crypto.bech32.Bech32; @@ -26,7 +25,7 @@ @EqualsAndHashCode @SuperBuilder @NoArgsConstructor -@Log +@Slf4j public final class UserProfile extends Profile implements IBech32Encodable { @JsonIgnore @@ -45,7 +44,7 @@ public String toBech32() { try { return Bech32.encode(Bech32.Encoding.BECH32, Bech32Prefix.NPROFILE.getCode(), this.publicKey.getRawData()); } catch (Exception ex) { - log.log(Level.SEVERE, null, ex); + log.error("", ex); throw new RuntimeException(ex); } } diff --git a/nostr-java-event/src/main/java/nostr/event/impl/GenericEvent.java b/nostr-java-event/src/main/java/nostr/event/impl/GenericEvent.java index 1fd37ed0a..ac4a094fc 100644 --- a/nostr-java-event/src/main/java/nostr/event/impl/GenericEvent.java +++ b/nostr-java-event/src/main/java/nostr/event/impl/GenericEvent.java @@ -8,7 +8,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import nostr.base.ElementAttribute; import nostr.base.IGenericElement; import nostr.base.ISignable; @@ -39,14 +39,13 @@ import java.util.Optional; import java.util.function.Consumer; import java.util.function.Supplier; -import java.util.logging.Level; import static nostr.base.Encoder.ENCODER_MAPPED_AFTERBURNER; /** * @author squirrel */ -@Log +@Slf4j @Data @EqualsAndHashCode(callSuper = false) public class GenericEvent extends BaseEvent implements ISignable, IGenericElement, Deleteable { @@ -204,7 +203,7 @@ public void update() { } catch (NostrException | NoSuchAlgorithmException ex) { throw new RuntimeException(ex); } catch (AssertionError ex) { - log.log(Level.WARNING, ex.getMessage()); + log.warn(ex.getMessage()); throw new RuntimeException(ex); } } @@ -295,7 +294,7 @@ public Consumer getSignatureConsumer() { @Override public Supplier getByeArraySupplier() { this.update(); - log.log(Level.FINER, "Serialized event: {0}", new String(this.get_serializedEvent())); + log.debug("Serialized event: {}", new String(this.get_serializedEvent())); return () -> ByteBuffer.wrap(this.get_serializedEvent()); } diff --git a/nostr-java-event/src/main/java/nostr/event/json/codec/GenericTagDecoder.java b/nostr-java-event/src/main/java/nostr/event/json/codec/GenericTagDecoder.java index 43a38782c..cc9429dcc 100644 --- a/nostr-java-event/src/main/java/nostr/event/json/codec/GenericTagDecoder.java +++ b/nostr-java-event/src/main/java/nostr/event/json/codec/GenericTagDecoder.java @@ -3,17 +3,16 @@ import com.fasterxml.jackson.core.JsonProcessingException; import lombok.Data; import lombok.NonNull; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import nostr.base.ElementAttribute; import nostr.base.IDecoder; import nostr.event.tag.GenericTag; import java.util.ArrayList; -import java.util.logging.Level; import java.util.stream.IntStream; @Data -@Log +@Slf4j public class GenericTagDecoder implements IDecoder { private final Class clazz; @@ -56,7 +55,7 @@ public T decode(@NonNull String json) { .toList()); */ - log.log(Level.INFO, ">>> Decoded GenericTag: {0}", genericTag); + log.info("Decoded GenericTag: {}", genericTag); return (T) genericTag; } catch (JsonProcessingException ex) { diff --git a/nostr-java-event/src/main/java/nostr/event/json/serializer/TagSerializer.java b/nostr-java-event/src/main/java/nostr/event/json/serializer/TagSerializer.java index 020214aec..00082382a 100644 --- a/nostr-java-event/src/main/java/nostr/event/json/serializer/TagSerializer.java +++ b/nostr-java-event/src/main/java/nostr/event/json/serializer/TagSerializer.java @@ -5,7 +5,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.std.StdSerializer; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import nostr.base.ElementAttribute; import nostr.event.BaseTag; import nostr.event.tag.GenericTag; @@ -14,14 +14,13 @@ import java.io.Serial; import java.lang.reflect.Field; import java.util.List; -import java.util.logging.Level; import static nostr.event.json.codec.BaseTagEncoder.BASETAG_ENCODER_MAPPED_AFTERBURNER; /** * @author guilhermegps */ -@Log +@Slf4j public class TagSerializer extends StdSerializer { @Serial diff --git a/nostr-java-event/src/main/java/nostr/event/message/EventMessage.java b/nostr-java-event/src/main/java/nostr/event/message/EventMessage.java index bf2aa2747..eb0ebe15c 100644 --- a/nostr-java-event/src/main/java/nostr/event/message/EventMessage.java +++ b/nostr-java-event/src/main/java/nostr/event/message/EventMessage.java @@ -7,7 +7,7 @@ import lombok.Getter; import lombok.NonNull; import lombok.Setter; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import nostr.base.Command; import nostr.base.IEvent; import nostr.event.BaseEvent; @@ -19,14 +19,13 @@ import java.util.Objects; import java.util.Optional; import java.util.function.Function; -import java.util.logging.Level; import static nostr.base.Encoder.ENCODER_MAPPED_AFTERBURNER; import static nostr.base.IDecoder.I_DECODER_MAPPER_AFTERBURNER; @Setter @Getter -@Log +@Slf4j public class EventMessage extends BaseMessage { private static final int SIZE_JSON_EVENT_wo_SIG_ID = 2; private static final Function isEventWoSig = (objArr) -> @@ -76,7 +75,7 @@ private static T processEvent(Object[] msgArr) { } private static GenericEvent convertValue(Map map) { - log.log(Level.INFO, "Converting map to GenericEvent: {0}", map); + log.info("Converting map to GenericEvent: {}", map); return I_DECODER_MAPPER_AFTERBURNER.convertValue(map, new TypeReference<>() {}); } } diff --git a/nostr-java-event/src/test/java/nostr/event/unit/BaseMessageCommandMapperTest.java b/nostr-java-event/src/test/java/nostr/event/unit/BaseMessageCommandMapperTest.java index b2c2621f5..f0a96c848 100644 --- a/nostr-java-event/src/test/java/nostr/event/unit/BaseMessageCommandMapperTest.java +++ b/nostr-java-event/src/test/java/nostr/event/unit/BaseMessageCommandMapperTest.java @@ -1,7 +1,7 @@ package nostr.event.unit; import com.fasterxml.jackson.core.JsonProcessingException; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import nostr.event.BaseMessage; import nostr.event.json.codec.BaseMessageDecoder; import nostr.event.message.EoseMessage; @@ -12,7 +12,7 @@ import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertThrows; -@Log +@Slf4j public class BaseMessageCommandMapperTest { // TODO: flesh out remaining commands public final static String REQ_JSON = diff --git a/nostr-java-event/src/test/java/nostr/event/unit/BaseMessageDecoderTest.java b/nostr-java-event/src/test/java/nostr/event/unit/BaseMessageDecoderTest.java index f12bc2f35..6a9849b3f 100644 --- a/nostr-java-event/src/test/java/nostr/event/unit/BaseMessageDecoderTest.java +++ b/nostr-java-event/src/test/java/nostr/event/unit/BaseMessageDecoderTest.java @@ -1,7 +1,7 @@ package nostr.event.unit; import com.fasterxml.jackson.core.JsonProcessingException; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import nostr.event.BaseMessage; import nostr.event.json.codec.BaseMessageDecoder; import nostr.event.message.EoseMessage; @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; -@Log +@Slf4j public class BaseMessageDecoderTest { // TODO: flesh out remaining commands public final static String REQ_JSON = diff --git a/nostr-java-event/src/test/java/nostr/event/unit/FiltersDecoderTest.java b/nostr-java-event/src/test/java/nostr/event/unit/FiltersDecoderTest.java index ce57fec24..e8762c17b 100644 --- a/nostr-java-event/src/test/java/nostr/event/unit/FiltersDecoderTest.java +++ b/nostr-java-event/src/test/java/nostr/event/unit/FiltersDecoderTest.java @@ -1,6 +1,6 @@ package nostr.event.unit; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import nostr.base.GenericTagQuery; import nostr.base.Kind; import nostr.base.PublicKey; @@ -32,7 +32,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -@Log +@Slf4j public class FiltersDecoderTest { @Test diff --git a/nostr-java-event/src/test/java/nostr/event/unit/FiltersEncoderTest.java b/nostr-java-event/src/test/java/nostr/event/unit/FiltersEncoderTest.java index 4802ff8ef..0945527a3 100644 --- a/nostr-java-event/src/test/java/nostr/event/unit/FiltersEncoderTest.java +++ b/nostr-java-event/src/test/java/nostr/event/unit/FiltersEncoderTest.java @@ -1,6 +1,6 @@ package nostr.event.unit; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import nostr.base.GenericTagQuery; import nostr.base.Kind; import nostr.base.PublicKey; @@ -36,7 +36,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -@Log +@Slf4j public class FiltersEncoderTest { @Test diff --git a/nostr-java-examples/src/main/java/nostr/examples/FilterRelays.java b/nostr-java-examples/src/main/java/nostr/examples/FilterRelays.java index 1a32b5c24..92b8e6291 100644 --- a/nostr-java-examples/src/main/java/nostr/examples/FilterRelays.java +++ b/nostr-java-examples/src/main/java/nostr/examples/FilterRelays.java @@ -1,6 +1,6 @@ package nostr.examples; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import nostr.base.Relay; import java.util.HashSet; @@ -13,7 +13,7 @@ * @author guilhermegps * */ -@Log +@Slf4j public class FilterRelays { private final static Map relaysURLs = Stream.of(new String[][] { @@ -145,7 +145,7 @@ private static Relay updateRelayMetadata(@NonNull Relay relay) { var connection = new Connection(relay, context, new ArrayList<>()); //connection.updateRelayMetadata(relay); } catch (Exception ex) { - log.log(Level.WARNING, "Error updating relay metadata: " + relay.getHostname()); + log.warn("Error updating relay metadata: {}", relay.getHostname()); } return relay; diff --git a/nostr-java-examples/src/main/java/nostr/examples/NostrApiExamples.java b/nostr-java-examples/src/main/java/nostr/examples/NostrApiExamples.java index 275a77ab9..34d9425ab 100644 --- a/nostr-java-examples/src/main/java/nostr/examples/NostrApiExamples.java +++ b/nostr-java-examples/src/main/java/nostr/examples/NostrApiExamples.java @@ -1,6 +1,6 @@ package nostr.examples; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import nostr.api.NIP01; import nostr.api.NIP04; import nostr.api.NIP05; @@ -31,7 +31,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import java.io.IOException; -import java.io.InputStream; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; @@ -42,14 +41,13 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.LogManager; +import lombok.extern.slf4j.Slf4j; /** * * @author eric */ -@Log +@Slf4j @SpringBootApplication public class NostrApiExamples implements ApplicationRunner { @@ -60,14 +58,6 @@ public class NostrApiExamples implements ApplicationRunner { private final static Map RELAYS = Map.of("local", "localhost:5555"); static { - final LogManager logManager = LogManager.getLogManager(); - try (final InputStream is = NostrApiExamples.class - .getResourceAsStream("/logging.properties")) { - logManager.readConfiguration(is); - } catch (IOException ex) { - System.exit(-1000); - } - try { PROFILE.setPicture(new URI("https://images.unsplash.com/photo-1462888210965-cdf193fb74de").toURL()); } catch (MalformedURLException | URISyntaxException e) { @@ -78,7 +68,7 @@ public class NostrApiExamples implements ApplicationRunner { @Override public void run(ApplicationArguments args) throws Exception { try { - log.log(Level.FINE, "================= The Beginning"); + log.debug("================= The Beginning"); logAccountsData(); ExecutorService executor = Executors.newFixedThreadPool(10); @@ -92,7 +82,7 @@ public void run(ApplicationArguments args) throws Exception { executor.submit(() -> { try { sendTextNoteEvent(); - } catch(Throwable t) { log.log(Level.SEVERE, t.getMessage(), t); } + } catch(Throwable t) { log.error(t.getMessage(), t); } }); // executor.submit(() -> { @@ -171,11 +161,11 @@ public void run(ApplicationArguments args) throws Exception { stop(executor); if (executor.isTerminated()) { - log.log(Level.FINE, "================== The End"); + log.debug("================== The End"); } } catch (IllegalArgumentException ex) { - log.log(Level.SEVERE, null, ex); + log.error("", ex); throw new NostrException(ex); } } @@ -385,7 +375,7 @@ private static void logAccountsData() { '\n' + "* PublicKey HEX: " + SENDER.getPublicKey().toString() + '\n' + '\n' + "################################ ACCOUNTS END ################################"; - log.log(Level.INFO, msg); + log.info(msg); } private static void logHeader(String header) { @@ -405,10 +395,10 @@ private static void stop(ExecutorService executor) { executor.shutdown(); executor.awaitTermination(60, TimeUnit.SECONDS); } catch (InterruptedException e) { - log.log(Level.SEVERE, "termination interrupted"); + log.error("termination interrupted"); } finally { if (!executor.isTerminated()) { - log.log(Level.SEVERE, "killing non-finished tasks"); + log.error("killing non-finished tasks"); } executor.shutdownNow(); } diff --git a/nostr-java-id/src/main/java/nostr/id/Identity.java b/nostr-java-id/src/main/java/nostr/id/Identity.java index aa29f0911..db069bb16 100644 --- a/nostr-java-id/src/main/java/nostr/id/Identity.java +++ b/nostr-java-id/src/main/java/nostr/id/Identity.java @@ -5,7 +5,7 @@ import lombok.NonNull; import lombok.SneakyThrows; import lombok.ToString; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import nostr.base.ISignable; import nostr.base.PrivateKey; import nostr.base.PublicKey; @@ -18,7 +18,7 @@ */ @EqualsAndHashCode @Data -@Log +@Slf4j public class Identity { @ToString.Exclude diff --git a/nostr-java-id/src/test/java/nostr/id/EntityFactory.java b/nostr-java-id/src/test/java/nostr/id/EntityFactory.java index 41784b8bd..1ac689570 100644 --- a/nostr-java-id/src/test/java/nostr/id/EntityFactory.java +++ b/nostr-java-id/src/test/java/nostr/id/EntityFactory.java @@ -1,6 +1,6 @@ package nostr.id; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import nostr.base.ElementAttribute; import nostr.base.GenericTagQuery; import nostr.base.IEvent; @@ -31,11 +31,11 @@ * * @author squirrel */ -@Log +@Slf4j //TODO - Add the sender PK to all createEvents. public class EntityFactory { - @Log + @Slf4j public static class Events { /* diff --git a/nostr-java-id/src/test/java/nostr/id/EventTest.java b/nostr-java-id/src/test/java/nostr/id/EventTest.java index c5a975499..61e2433a3 100644 --- a/nostr-java-id/src/test/java/nostr/id/EventTest.java +++ b/nostr-java-id/src/test/java/nostr/id/EventTest.java @@ -1,6 +1,6 @@ package nostr.id; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import nostr.base.ElementAttribute; import nostr.base.PublicKey; import nostr.crypto.bech32.Bech32; @@ -28,7 +28,7 @@ * * @author squirrel */ -@Log +@Slf4j public class EventTest { public EventTest() { diff --git a/nostr-java-id/src/test/java/nostr/id/ZapReceiptEventTest.java b/nostr-java-id/src/test/java/nostr/id/ZapReceiptEventTest.java index 657854d89..7d86c33c4 100644 --- a/nostr-java-id/src/test/java/nostr/id/ZapReceiptEventTest.java +++ b/nostr-java-id/src/test/java/nostr/id/ZapReceiptEventTest.java @@ -1,8 +1,8 @@ package nostr.id; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; -@Log +@Slf4j class ZapReceiptEventTest { /* diff --git a/nostr-java-util/src/main/java/nostr/util/validator/Nip05Validator.java b/nostr-java-util/src/main/java/nostr/util/validator/Nip05Validator.java index dbe1408ae..b7085c087 100644 --- a/nostr-java-util/src/main/java/nostr/util/validator/Nip05Validator.java +++ b/nostr-java-util/src/main/java/nostr/util/validator/Nip05Validator.java @@ -8,7 +8,7 @@ import lombok.Data; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import nostr.util.NostrException; import java.io.BufferedReader; @@ -19,7 +19,6 @@ import java.net.URISyntaxException; import java.net.URL; import java.util.Map; -import java.util.logging.Level; /** * @@ -28,7 +27,7 @@ @Builder @RequiredArgsConstructor @Data -@Log +@Slf4j public class Nip05Validator { private final String nip05; @@ -49,10 +48,10 @@ public void validate() throws NostrException { // Verify the public key try { - log.log(Level.FINE, "Validating {0}@{1}", new Object[]{localPart, domain}); + log.debug("Validating {}@{}", localPart, domain); validatePublicKey(domain, localPart); } catch (IOException | URISyntaxException ex) { - log.log(Level.SEVERE, ex.getMessage()); + log.error("Validation error", ex); throw new NostrException(ex); } } @@ -78,7 +77,7 @@ private void validatePublicKey(String domain, String localPart) throws NostrExce // (2) String pubKey = getPublicKey(content, localPart); - log.log(Level.FINE, "Public key for {0} returned by the server: [{1}]", new Object[]{localPart, pubKey}); + log.debug("Public key for {} returned by the server: [{}]", localPart, pubKey); if (pubKey != null && !pubKey.equals(publicKey)) { throw new NostrException(String.format("Public key mismatch. Expected %s - Received: %s", publicKey, pubKey)); diff --git a/nostr-java-util/src/test/java/nostr/util/NostrUtilTest.java b/nostr-java-util/src/test/java/nostr/util/NostrUtilTest.java index 01c7bb85d..40242f19a 100644 --- a/nostr-java-util/src/test/java/nostr/util/NostrUtilTest.java +++ b/nostr-java-util/src/test/java/nostr/util/NostrUtilTest.java @@ -1,6 +1,6 @@ package nostr.util; -import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -8,7 +8,7 @@ /** * @author squirrel */ -@Log +@Slf4j public class NostrUtilTest { /** * test intended to confirm conversion routines: