Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
89b19aa
docs: add comprehensive PR for all changes from 0.2.2 to 0.5.1
Oct 5, 2025
76bd6cb
style: fix Qodana findings (javadoc order, regex, redundant cast, com…
Oct 6, 2025
d69c0c5
refactor: address additional Qodana issues (duplicate expressions, re…
Oct 6, 2025
c22e564
style: suppress unchecked warnings and remove redundant casts across …
Oct 6, 2025
edac1fd
chore: restore workflow, qodana config, and docs removed inadvertently
Oct 6, 2025
cc1a5d3
refactor: use typed tag helpers across API and events; add code-aware…
Oct 6, 2025
520d866
Merge remote-tracking branch 'origin/develop' into develop
Oct 6, 2025
bed8994
Merge remote-tracking branch 'origin/develop' into chore/qodana-fixes
Oct 6, 2025
68114ed
chore(bom): bump to 1.1.1 and remove local JUnit overrides; test: qua…
Oct 6, 2025
e198b6e
chore(version): bump project version to 0.6.0 across poms and docs
Oct 6, 2025
6146268
Merge pull request #453 from tcheeric/chore/qodana-fixes
tcheeric Oct 6, 2025
98df86e
Merge remote-tracking branch 'origin/develop' into develop
Oct 6, 2025
6e1ee6a
fix(logging): improve error messages and log levels per Clean Code gu…
Oct 6, 2025
911ab87
refactor(logging): remove constructor logging from low-level key classes
Oct 6, 2025
33270a7
refactor(test): remove test method name logging per Clean Code guidel…
Oct 6, 2025
337bce4
refactor(logging): extract duplicated recovery logging in SpringWebSo…
Oct 6, 2025
90a4c8b
chore: bump version to 0.6.1
Oct 6, 2025
1feba9f
Merge pull request #454 from tcheeric/chore/bump-version-0.6.1
tcheeric Oct 6, 2025
a988d62
fix(logging): improve error messages and log levels per Clean Code gu…
Oct 6, 2025
5ffd3e7
refactor(logging): remove constructor logging from low-level key classes
Oct 6, 2025
37ea04b
refactor(test): remove test method name logging per Clean Code guidel…
Oct 6, 2025
6326f23
refactor(logging): extract duplicated recovery logging in SpringWebSo…
Oct 6, 2025
e813346
Merge remote-tracking branch 'origin/develop' into develop
Oct 6, 2025
c0e6509
docs(javadoc): fix plain-text NIP links to anchors; fully-qualify Jav…
Oct 6, 2025
7dc0019
docs(javadoc): address Qodana javadoc items (anchor NIP links, fully-…
Oct 6, 2025
f5ce0ad
chore: bump version to 0.6.2 and tighten fields per Qodana (FieldMayB…
Oct 6, 2025
93c5c2c
test: configure Mockito to use subclass mock-maker via SPI and surefi…
Oct 6, 2025
529b849
Merge pull request #455 from tcheeric/chore/qodana-final-and-bump-0.6.2
tcheeric Oct 6, 2025
7e9c139
fix: replace generic exception handling
tcheeric Oct 6, 2025
ec39a51
Merge pull request #456 from tcheeric/codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
9995e9f
fix: replace sneaky throws with explicit handling
tcheeric Oct 6, 2025
1a86ffb
Merge pull request #457 from tcheeric/codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
176020d
refactor: unify nostr exception hierarchy
tcheeric Oct 6, 2025
a555d0a
Merge branch 'develop' into codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
7816173
Merge pull request #458 from tcheeric/codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
981c57d
refactor: modularize nip helpers and client orchestration
tcheeric Oct 6, 2025
f11f80a
Merge branch 'develop' into codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
8ce884d
Merge pull request #459 from tcheeric/codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
241cbe2
refactor: streamline subscriptions and zap parameters
tcheeric Oct 6, 2025
5a52f53
Merge branch 'develop' into codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
e9a3248
Merge pull request #460 from tcheeric/codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
9397543
docs: clarify api documentation
tcheeric Oct 6, 2025
028d724
Merge branch 'develop' into codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
1c4ddf0
Merge pull request #461 from tcheeric/codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
b2abab2
refactor: normalize event cache naming and mapper access
tcheeric Oct 6, 2025
7ca269c
Merge branch 'develop' into codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
6c89350
Merge pull request #462 from tcheeric/codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
67a565a
fix(api): allow optional sender when constructing websocket client
tcheeric Oct 6, 2025
398fc69
Merge pull request #463 from tcheeric/codex/fix-ci-error
tcheeric Oct 6, 2025
e2c80fc
refactor: abstract relay clients and codify nip ranges
tcheeric Oct 6, 2025
d3499a1
Merge branch 'develop' into codex/create-tasks-for-milestone-1-ylzf9j
tcheeric Oct 6, 2025
9ee96ee
Merge pull request #464 from tcheeric/codex/create-tasks-for-mileston…
tcheeric Oct 6, 2025
6b2a597
feat: finalize calendar decoding and generic event builder
tcheeric Oct 6, 2025
175b159
Merge branch 'develop' into codex/create-tasks-for-milestone-1-mt6702
tcheeric Oct 6, 2025
afdb80a
Merge pull request #465 from tcheeric/codex/create-tasks-for-mileston…
tcheeric Oct 6, 2025
69fefe1
build(pom): restore BOM version to 1.1.1 and re-add internal module o…
Oct 6, 2025
00c2ab5
chore(deps): bump org.sonatype.central:central-publishing-maven-plugin
dependabot[bot] Oct 6, 2025
7b71243
docs: complete Phase 2 documentation enhancement
Oct 6, 2025
223d911
Merge pull request #467 from tcheeric/docs/phase-2-documentation-enha…
tcheeric Oct 6, 2025
8216182
Merge pull request #466 from tcheeric/dependabot/maven/develop/org.so…
tcheeric Oct 6, 2025
0925bbd
docs: complete Phase 2 Task 5 - extended JavaDoc for NIPs and exceptions
Oct 6, 2025
2844e5e
chore: organize project management files into .project-management folder
Oct 6, 2025
6635cc4
chore: rename logging review and improvements markdown files
Oct 6, 2025
cfac008
Merge pull request #468 from tcheeric/docs/phase-2-extended-javadoc
tcheeric Oct 6, 2025
4ed2daf
docs: add MIGRATION.md for 1.0.0 upgrade path - Phase 2 Task 6 complete
Oct 8, 2025
89c05b0
test: add comprehensive tests for NIP-04, NIP-44, and NIP-57
Oct 8, 2025
afb5ffa
docs: add Phase 3 & 4 testing analysis and progress tracking
Oct 8, 2025
482fff9
chore: bump version to 0.6.4
Oct 8, 2025
e215449
docs: add PR document for critical tests and Phase 3 & 4
Oct 8, 2025
b963138
fix: remove unsupported eventId test from NIP57ImplTest
Oct 8, 2025
d191718
fix: adjust NIP-44 tests to respect NIP-44 plaintext constraints
Oct 8, 2025
cf5fc5b
Merge pull request #470 from tcheeric/test/critical-nip-tests-impleme…
tcheeric Oct 8, 2025
4bcc23b
chore(tests): strengthen client/handler tests and increase coverage; …
Oct 9, 2025
d5a3c60
Merge pull request #471 from tcheeric/chore/tests-coverage-enhancements
tcheeric Oct 9, 2025
a199549
build(api): add slf4j-test version (2.4.0) for test logging assertions
Oct 9, 2025
e98c4ce
chore: automate roadmap project setup
tcheeric Oct 11, 2025
6d653b0
Merge pull request #472 from tcheeric/codex/establish-remaining-tasks…
tcheeric Oct 11, 2025
e2f0382
Merge remote-tracking branch 'origin/develop' into develop
Oct 11, 2025
31ce804
fix(api): close WebSocket clients when subscription handles close; bu…
Oct 11, 2025
471c290
Merge pull request #473 from tcheeric/fix/websocket-handler-close-client
tcheeric Oct 11, 2025
fa6a8ba
chore: bump project version to 1.0.0-SNAPSHOT
Oct 11, 2025
5cd2a91
docs(migration): update migration steps for nostr-java BOM usage
Oct 11, 2025
85985de
docs(troubleshooting): update dependency version references for clarity
Oct 11, 2025
4243e5a
fix: parse BOLT11 separator correctly
tcheeric Oct 11, 2025
4d63f19
test: fix bolt11 whole btc fixture
tcheeric Oct 11, 2025
6fd28ca
Merge pull request #475 from tcheeric/codex/address-review-comment-in…
tcheeric Oct 11, 2025
7679bf2
fix(bolt11): correct HRP separator parsing in BOLT11 invoices
Oct 11, 2025
d4ddb67
fix(nip01): handle null uuid in identifier tag parsing
Oct 11, 2025
9861b76
feat: enhance task management in roadmap project script
Oct 11, 2025
de0f48a
Merge pull request #474 from tcheeric/chore/bump-version-1.0.0-SNAPSHOT
tcheeric Oct 11, 2025
199764f
chore(version): bump to 1.0.1-SNAPSHOT across all modules
Oct 12, 2025
4274095
fix: restore GenericTag fallback for DM decrypt
tcheeric Oct 12, 2025
b85dd49
Merge pull request #476 from tcheeric/chore/bump-version-1.0.1-SNAPSHOT
tcheeric Oct 12, 2025
8d04481
refactor(tags): reorganize imports for clarity
Oct 12, 2025
2d3cbd4
docs: rename relay references to 398ja
tcheeric Oct 12, 2025
8857498
Merge pull request #477 from tcheeric/codex/update-relay-name-from-da…
tcheeric Oct 12, 2025
41cdc37
fix: enforce string nip metadata
tcheeric Oct 12, 2025
4df2582
Merge pull request #478 from tcheeric/codex/update-event-kind-type-to…
tcheeric Oct 12, 2025
98d4df3
chore(deps): bump actions/checkout from 4 to 5
dependabot[bot] Oct 13, 2025
7c3458f
chore(deps): bump actions/setup-java from 4 to 5
dependabot[bot] Oct 13, 2025
ac61230
chore(deps): bump org.jacoco:jacoco-maven-plugin from 0.8.13 to 0.8.14
dependabot[bot] Oct 13, 2025
364452b
Merge pull request #481 from tcheeric/dependabot/maven/develop/org.ja…
tcheeric Oct 13, 2025
c8518be
Merge pull request #479 from tcheeric/dependabot/github_actions/devel…
tcheeric Oct 13, 2025
5834f52
Merge pull request #480 from tcheeric/dependabot/github_actions/devel…
tcheeric Oct 13, 2025
4a340ab
chore(version): bump to 1.0.2-SNAPSHOT across all modules
Oct 13, 2025
796773c
chore: release version 1.0.0
Oct 13, 2025
993b342
refactor(api): remove deprecated Identity parameter methods from NIP01
Oct 13, 2025
21c704a
Merge pull request #482 from tcheeric/chore/bump-version-1.0.2-SNAPSHOT
tcheeric Oct 13, 2025
d35c334
docs(readme): update troubleshooting section and remove outdated content
Oct 13, 2025
5af42bd
docs(readme): fix formatting of features list for consistency
Oct 13, 2025
0dcd0dc
chore: update changelog for version 1.0.0 release
Oct 13, 2025
8fbbb71
refactor(api)!: clean up and remove deprecated APIs in v1.0.0
Oct 13, 2025
9726c58
refactor(release): enhance Maven command options handling
Oct 13, 2025
baa075b
chore(settings): add Maven settings for repository configuration
Oct 13, 2025
7e273ec
chore(settings): update Maven repository URL for consistency
Oct 14, 2025
6cefd8f
fix(api): handle generic p-tags during DM decrypt
tcheeric Oct 14, 2025
54109ad
Merge pull request #484 from tcheeric/codex/add-unit-test-for-nip04.java
tcheeric Oct 14, 2025
c966937
fix: restore sender overrides in NIP-01 builder
tcheeric Oct 14, 2025
00870ac
style: use diamond operator in NIP01 builder
tcheeric Oct 14, 2025
b0b8d60
Merge pull request #485 from tcheeric/codex/address-code-comment-in-n…
tcheeric Oct 14, 2025
38b1639
Merge branch 'chore/bump-version-1.0.2-SNAPSHOT' into codex/address-c…
tcheeric Oct 14, 2025
042d019
Merge pull request #486 from tcheeric/codex/address-code-comment-in-n…
tcheeric Oct 14, 2025
c652345
Merge pull request #487 from tcheeric/chore/bump-version-1.0.2-SNAPSHOT
tcheeric Oct 14, 2025
58bceed
refactor(api)!: simplify event building methods by removing sender pa…
Oct 14, 2025
3a16764
refactor(api): update default sender handling in NIP01 event builder
Oct 14, 2025
7c90fec
ci: update Maven command to use custom settings file
Oct 14, 2025
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
Prev Previous commit
Next Next commit
fix(logging): improve error messages and log levels per Clean Code gu…
…idelines

High-priority logging fixes based on comprehensive code review:

1. Fixed empty error message in UserProfile.java
   - Added descriptive error message and context to exception
   - Now properly describes Bech32 conversion failure

2. Improved generic warning in GenericEvent.java
   - Changed from log.warn(ex.getMessage()) to include full context
   - Added exception stacktrace for better debugging
   - Message now explains serialization failure context

3. Optimized expensive debug logging in GenericEvent.java
   - Changed serialized event logging from DEBUG to TRACE level
   - Added guard with log.isTraceEnabled() to prevent unnecessary String creation
   - Reduces performance overhead when TRACE is disabled

4. Fixed inappropriate INFO level in GenericTagDecoder.java
   - Changed log.info to log.debug for routine decoding operation
   - INFO should be for noteworthy events, not expected operations

5. Added comprehensive LOGGING_REVIEW.md
   - Documents all logging practices against Clean Code principles
   - Identifies 8 priority levels of improvements
   - Overall grade: B+ (will be A- after all high-priority fixes)

Compliance with Clean Code chapters 2, 3, 4, 7, 10, 17:
- Meaningful error messages (Ch 2: Meaningful Names)
- Proper context in logs (Ch 4: Comments)
- Better error handling (Ch 7: Error Handling)
- Reduced code smells (Ch 17: Smells and Heuristics)

Ref: LOGGING_REVIEW.md for complete analysis and remaining action items

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
  • Loading branch information
erict875 and claude committed Oct 6, 2025
commit a988d62a22245ba5c8074cc196ca7201d3af092c
377 changes: 377 additions & 0 deletions LOGGING_REVIEW.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,377 @@
# Logging Review - Clean Code Compliance

**Date**: 2025-10-06
**Reviewer**: Claude Code
**Guidelines**: Clean Code principles (Chapters 2, 3, 4, 7, 10, 17)

## Executive Summary

The nostr-java codebase uses SLF4J logging with Lombok's `@Slf4j` annotation consistently across the project. The logging implementation is generally good, with proper log levels and meaningful messages. However, there are several areas where the logging does not fully comply with Clean Code principles.

**Overall Grade**: B+

**Key Findings**:
- ✅ Consistent use of SLF4J with Lombok `@Slf4j`
- ✅ No sensitive data (private keys, passwords) logged in plain text
- ✅ Appropriate log levels used in most cases
- ⚠️ Some empty or non-descriptive error messages
- ⚠️ Excessive debug logging in low-level classes (PrivateKey, PublicKey)
- ⚠️ Test methods using log.info for test names (should use JUnit display names)
- ⚠️ Some log messages lack context

## Detailed Findings

### 1. Clean Code Chapter 2: Meaningful Names

**Principle**: Use intention-revealing, searchable names in log messages.

#### Issues Found

**❌ Empty error message** (`nostr-java-event/src/main/java/nostr/event/entities/UserProfile.java:46`)
```java
log.error("", ex);
```

**Problem**: Empty string provides no context about what failed.
**Fix**: Add meaningful error message
```java
log.error("Failed to encode UserProfile to Bech32 format", ex);
```

**❌ Generic warning** (`nostr-java-event/src/main/java/nostr/event/impl/GenericEvent.java:196`)
```java
log.warn(ex.getMessage());
```

**Problem**: Only logs exception message without context about what operation failed.
**Fix**: Add context
```java
log.warn("Failed to update event during serialization: {}", ex.getMessage(), ex);
```

### 2. Clean Code Chapter 3: Functions

**Principle**: Functions should do one thing. Logging should not be the primary purpose.

#### Issues Found

**⚠️ Excessive constructor logging** (`nostr-java-base/src/main/java/nostr/base/PrivateKey.java:16,21,29`)
```java
public PrivateKey(byte[] rawData) {
super(KeyType.PRIVATE, rawData, Bech32Prefix.NSEC);
log.debug("Created private key from byte array");
}

public PrivateKey(String hexPrivKey) {
super(KeyType.PRIVATE, NostrUtil.hexToBytes(hexPrivKey), Bech32Prefix.NSEC);
log.debug("Created private key from hex string");
}

public static PrivateKey generateRandomPrivKey() {
PrivateKey key = new PrivateKey(Schnorr.generatePrivateKey());
log.debug("Generated new random private key");
return key;
}
```

**Problem**: Low-level constructors should not log. This creates noise and violates single responsibility. These classes are used frequently, and logging every creation adds overhead.

**Recommendation**: Remove these debug logs. If tracking object creation is needed, use a profiler or instrumentation.

**Same issue in** `PublicKey.java:17,22` and `BaseKey.java:32,48`

### 3. Clean Code Chapter 4: Comments

**Principle**: Code should be self-documenting. Logs should not explain what code does, but provide runtime context.

#### Good Examples

**✅ Context-rich logging** (`SpringWebSocketClient.java:38-42`)
```java
log.debug(
"Sending {} to relay {} (size={} bytes)",
eventMessage.getCommand(),
relayUrl,
json.length());
```

**Good**: Provides runtime context (command, relay, size) without explaining code logic.

**✅ Error recovery logging** (`SpringWebSocketClient.java:112-116`)
```java
log.error(
"Failed to send message to relay {} after retries (size={} bytes)",
relayUrl,
json.length(),
ex);
```

**Good**: Logs failure with context and includes exception for debugging.

#### Issues Found

**⚠️ Verbose serialization logging** (`GenericEvent.java:277`)
```java
log.debug("Serialized event: {}", new String(this.get_serializedEvent()));
```

**Problem**: Logs entire serialized event at debug level. This could be very verbose and is called frequently. Consider:
1. Using TRACE level instead of DEBUG
2. Truncating output
3. Removing this log entirely (serialization is expected behavior)

**Recommendation**: Remove or change to TRACE level with size limit.

### 4. Clean Code Chapter 7: Error Handling

**Principle**: Error handling should be complete. Don't pass null or empty messages to logging.

#### Issues Found

**❌ Empty error log** (`UserProfile.java:46`)
```java
catch (Exception ex) {
log.error("", ex); // Empty message
throw new RuntimeException(ex);
}
```

**Fix**:
```java
catch (Exception ex) {
log.error("Failed to convert UserProfile to Bech32 format", ex);
throw new RuntimeException("Failed to convert UserProfile to Bech32 format", ex);
}
```

**⚠️ Generic RuntimeException wrapping** (multiple locations)
```java
catch (Exception ex) {
log.error("Error converting key to Bech32", ex);
throw new RuntimeException(ex);
}
```

**Better approach**: Create specific exception types or include original message:
```java
catch (Exception ex) {
log.error("Error converting {} key to Bech32 format with prefix {}", type, prefix, ex);
throw new RuntimeException("Failed to convert key to Bech32: " + ex.getMessage(), ex);
}
```

### 5. Clean Code Chapter 10: Classes

**Principle**: Classes should have a single responsibility. Excessive logging can indicate unclear responsibilities.

#### Good Examples

**✅ Client handler logging** (`SpringWebSocketClient.java`)
- Logs connection lifecycle events
- Logs retry failures
- Logs subscription events
- All appropriate for a client handler class

**✅ Validator logging** (`Nip05Validator.java:110,123,133`)
- Logs validation errors with context
- Logs HTTP request failures
- Logs public key lookup results
- All appropriate for a validator class

#### Issues Found

**⚠️ Low-level utility logging** (`PrivateKey.java`, `PublicKey.java`, `BaseKey.java`)

These classes are data containers with minimal behavior. Logging in constructors and conversion methods adds noise without value.

**Recommendation**: Remove all debug logging from these low-level classes. If needed, add logging at the application layer where these objects are used.

### 6. Clean Code Chapter 17: Smells and Heuristics

**Principle**: Avoid code smells that indicate poor design.

#### Code Smells Found

**G5: Duplication**

**⚠️ Duplicated recovery logging** (`SpringWebSocketClient.java:112-116, 129-133, 145-151, 166-171`)

Four nearly identical recovery methods with duplicated logging logic.

**Recommendation**: Extract common recovery logging:
```java
private void logRecoveryFailure(String operation, String relayUrl, int size, IOException ex) {
log.error("Failed to {} to relay {} after retries (size={} bytes)",
operation, relayUrl, size, ex);
}
```

**G15: Selector Arguments**

Test classes use `log.info()` to log test names:
```java
@Test
void testEventFilterEncoder() {
log.info("testEventFilterEncoder"); // Unnecessary
// test code
}
```

**Recommendation**: Remove these. Use JUnit's `@DisplayName` instead:
```java
@Test
@DisplayName("Event filter encoder should serialize filters correctly")
void testEventFilterEncoder() {
// test code
}
```

**G31: Hidden Temporal Couplings**

**⚠️ Potential issue** (`GenericTagDecoder.java:56`)
```java
log.info("Decoded GenericTag: {}", genericTag);
```

**Problem**: Using INFO level for routine decoding operation. This should be DEBUG or removed entirely. INFO level implies something noteworthy, but decoding is expected behavior.

**Recommendation**: Change to DEBUG or remove.

### 7. Security Concerns

**✅ No Sensitive Data Logged**

Analysis of all logging statements confirms:
- Private keys are NOT logged (only existence is logged: "Created private key")
- Passwords/secrets are NOT logged
- Public keys are logged only at DEBUG level (appropriate since they're public)

**Good security practice observed**.

### 8. Performance Concerns

**⚠️ Expensive Operations at DEBUG Level**

Several locations log expensive operations:

1. **Full event serialization** (`GenericEvent.java:277`)
```java
log.debug("Serialized event: {}", new String(this.get_serializedEvent()));
```

2. **GenericTag decoding** (`GenericTagDecoder.java:56`)
```java
log.info("Decoded GenericTag: {}", genericTag);
```

**Problem**: Even if DEBUG is disabled, `toString()` is still called on objects passed to log methods.

**Recommendation**: Use lazy evaluation:
```java
if (log.isDebugEnabled()) {
log.debug("Serialized event: {}", new String(this.get_serializedEvent()));
}
```

Or better, remove entirely.

## Recommendations by Priority

### High Priority (Fix Immediately)

1. **Fix empty error message** in `UserProfile.java:46`
```java
// Before
log.error("", ex);

// After
log.error("Failed to convert UserProfile to Bech32 format", ex);
```

2. **Fix generic warning** in `GenericEvent.java:196`
```java
// Before
log.warn(ex.getMessage());

// After
log.warn("Failed to update event during serialization: {}", ex.getMessage(), ex);
```

3. **Change INFO to DEBUG** in `GenericTagDecoder.java:56`
```java
// Before
log.info("Decoded GenericTag: {}", genericTag);

// After
log.debug("Decoded GenericTag: {}", genericTag);
// Or remove entirely
```

### Medium Priority (Should Fix)

4. **Remove constructor logging** from `PrivateKey.java`, `PublicKey.java`, `BaseKey.java`
- Lines: `PrivateKey.java:16,21,29`
- Lines: `PublicKey.java:17,22`
- Lines: `BaseKey.java:32,48`

5. **Remove or optimize expensive debug logging**
- `GenericEvent.java:277` - Full event serialization
- Add `if (log.isDebugEnabled())` guard or remove

6. **Remove test method name logging**
- All files in `nostr-java-event/src/test/java/`
- Replace with `@DisplayName` annotations

### Low Priority (Nice to Have)

7. **Extract duplicated recovery logging** in `SpringWebSocketClient.java`
- Create helper method to reduce duplication

8. **Add more context to error messages**
- Include variable values that help debugging
- Use structured logging where appropriate

## Compliance Summary

| Clean Code Chapter | Compliance | Issues |
|-------------------|------------|---------|
| Ch 2: Meaningful Names | 🟡 Partial | Empty error messages, generic warnings |
| Ch 3: Functions | 🟡 Partial | Constructor logging, excessive debug logs |
| Ch 4: Comments | ✅ Good | Most logs provide runtime context, not code explanation |
| Ch 7: Error Handling | 🟡 Partial | Empty error messages, generic exceptions |
| Ch 10: Classes | ✅ Good | Logging appropriate for class responsibilities (except low-level utils) |
| Ch 17: Smells | 🟡 Partial | Duplication, test name logging, INFO for routine operations |

**Legend**: ✅ Good | 🟡 Partial | ❌ Poor

## Positive Observations

1. **Consistent framework usage**: SLF4J with Lombok `@Slf4j` throughout
2. **Proper log levels**: DEBUG for detailed info, ERROR for failures, WARN for issues
3. **Parameterized logging**: Uses `{}` placeholders (avoids string concatenation)
4. **Security**: No sensitive data logged
5. **Context-rich messages**: Most logs include relay URLs, subscription IDs, sizes
6. **Exception logging**: Properly includes exception objects in error logs

## Action Items

Create issues or tasks for:
- [ ] Fix empty error message in UserProfile.java
- [ ] Fix generic warning in GenericEvent.java
- [ ] Change INFO to DEBUG in GenericTagDecoder.java
- [ ] Remove constructor logging from key classes
- [ ] Optimize or remove expensive debug logging
- [ ] Replace test log.info with @DisplayName
- [ ] Extract duplicated recovery logging
- [ ] Review and enhance error message context

## Conclusion

The logging implementation in nostr-java is solid overall, with proper use of SLF4J and good security practices. The main areas for improvement are:

1. **Meaningful error messages** (avoid empty strings)
2. **Reduce noise** (remove constructor logging in low-level classes)
3. **Optimize performance** (guard expensive debug operations)
4. **Improve tests** (use JUnit features instead of logging)

Implementing the high-priority fixes will bring the codebase to an **A-** grade for logging practices.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public String toBech32() {
return Bech32.encode(
Bech32.Encoding.BECH32, Bech32Prefix.NPROFILE.getCode(), this.publicKey.getRawData());
} catch (Exception ex) {
log.error("", ex);
throw new RuntimeException(ex);
log.error("Failed to convert UserProfile to Bech32 format", ex);
throw new RuntimeException("Failed to convert UserProfile to Bech32 format", ex);
}
}

Expand Down
Loading