Skip to content

feat: add logs to domain services#301

Open
7eliassen wants to merge 9 commits intochore/logs-and-optimizationfrom
domain-logs
Open

feat: add logs to domain services#301
7eliassen wants to merge 9 commits intochore/logs-and-optimizationfrom
domain-logs

Conversation

@7eliassen
Copy link
Copy Markdown

Add request-scoped business event logging to domain services.

  • Added new domain module name
  • Added DomainLoger interface to keep domain layer decoupled from infrastructure logging implementation. That preserve clean architecture.
  • Added PinoDomainLoggerAdapter that implements DomainLogger
  • Added logging for key business events:
    • Auth: Token issuance, expiration, session revocation
    • Notes: CRUD operations, relation changes, parent unlinks
    • Note settings: Creation, updates, cover changes, invitation regeneration
    • Team management: Member joins, role changes, removals
    • Files: Uploads and deletions
    • Editor tools: Tool creation
    • Note visits: User visit tracking
  • Updated DomainError handler to include reqId and domain module name in logs

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 8, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 85.77% (🎯 80%)
⬇️ -0.14%
9254 / 10789
🔵 Statements 85.77% (🎯 80%)
⬇️ -0.14%
9254 / 10789
🔵 Functions 79.55% (🎯 80%)
⬆️ +0.02%
284 / 357
🔵 Branches 84.82% (🎯 80%)
⬆️ +0.25%
464 / 547
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/domain/index.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
src/domain/service/auth.ts 94.28%
⬇️ -2.30%
90.9%
🟰 ±0%
100%
🟰 ±0%
94.28%
⬇️ -2.30%
119-126
src/domain/service/editorTools.ts 97.53%
⬆️ +0.57%
100%
🟰 ±0%
85.71%
🟰 ±0%
97.53%
⬆️ +0.57%
59-60
src/domain/service/fileUploader.service.ts 46.32%
⬇️ -1.04%
100%
🟰 ±0%
22.22%
🟰 ±0%
46.32%
⬇️ -1.04%
68-116, 125-126, 134-161, 168-195, 202-207, 214-215, 222-230
src/domain/service/note.ts 96.21%
⬆️ +0.31%
81.42%
⬇️ -1.18%
100%
🟰 ±0%
96.21%
⬆️ +0.31%
108-109, 141-142, 153-154, 187-188, 220-221, 322-323, 426-427, 443-444, 485-486, 535-536, 577-578
src/domain/service/noteSettings.ts 95.68%
⬇️ -1.50%
88%
🟰 ±0%
100%
🟰 ±0%
95.68%
⬇️ -1.50%
139-140, 146-153, 250-251
src/domain/service/noteVisits.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
src/domain/service/user.ts 71.96%
⬆️ +0.28%
80%
🟰 ±0%
57.14%
🟰 ±0%
71.96%
⬆️ +0.28%
54-55, 62-78, 94-95, 116-131
src/infrastructure/config/index.ts 99%
⬆️ +0.03%
50%
🟰 ±0%
100%
🟰 ±0%
99%
⬆️ +0.03%
191-192
src/infrastructure/logging/domainLoggerInterface.ts 0% 0% 0% 0% 1-28
src/infrastructure/logging/pinoDomainLoggerAdapter.ts 86.84% 100% 80% 86.84% 33-37
src/presentation/http/http-api.ts 96.1%
⬆️ +0.04%
90.32%
🟰 ±0%
93.75%
🟰 ±0%
96.1%
⬆️ +0.04%
103-111, 122-123, 325-326, 350-351
Generated in workflow #918 for commit 1679632 by the Vitest Coverage Report Action

* Implementations are provided by the infrastructure layer
*/

export interface DomainLogger {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

domain server shared space was designed as a place, where you declare methods of actual domain, that could be used by other domains

i think that the DomainLogger should be moved to infrastructure/logging/, since it does not really belongs here

(check readme inside of the domain/service/shared)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +27 to +32
const cachedLogger = loggerCache.get(moduleName);

if (cachedLogger) {
return cachedLogger;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like a part of different PR, should this branch be rebased?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the base branch to chore/logs-and-optimization

Comment thread src/domain/service/auth.ts Outdated
Comment thread src/presentation/http/policies/authRequired.ts
Comment thread src/repository/storage/postgres/orm/sequelize/index.ts
@7eliassen 7eliassen marked this pull request as draft April 10, 2026 06:19
@7eliassen 7eliassen changed the base branch from main to chore/logs-and-optimization April 10, 2026 06:21
@codex-assistant codex-assistant Bot marked this pull request as ready for review April 10, 2026 06:21
@codex-assistant
Copy link
Copy Markdown

Thanks for adding a description — the PR is now marked as Ready for Review.

@neSpecc neSpecc requested a review from e11sy April 22, 2026 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants