Skip to content

Conversation

@mesilov
Copy link
Owner

@mesilov mesilov commented Nov 22, 2025

Implemented core Journal bounded context following DDD patterns:

  • JournalItem entity with PSR-3 factory methods (emergency, alert, critical, error, warning, notice, info, debug)
  • JournalContext value object with label, payload (JSONB), userId, and IP address fields
  • LogLevel enum for PSR-3 compatible log levels
  • JournalItemInterface for SDK contract extraction
  • JournalItemRepositoryInterface with methods for CRUD operations and cleanup
  • DoctrineDbalJournalItemRepository implementation with pagination support
  • Doctrine ORM XML mappings for entity and embeddable objects

Features:

  • UUID identifiers for journal items
  • Immutable timestamps using Carbon
  • Reference to ApplicationInstallation via UUID
  • Support for IP address storage using darsyn/ip library
  • Repository methods for deletion by installation ID and by date
  • Indexed fields for optimal query performance
Q A
Bug fix? no
New feature? yes
Deprecations? no
Issues Fix #72
License MIT

Implemented core Journal bounded context following DDD patterns:
- JournalItem entity with PSR-3 factory methods (emergency, alert, critical, error, warning, notice, info, debug)
- JournalContext value object with label, payload (JSONB), userId, and IP address fields
- LogLevel enum for PSR-3 compatible log levels
- JournalItemInterface for SDK contract extraction
- JournalItemRepositoryInterface with methods for CRUD operations and cleanup
- DoctrineDbalJournalItemRepository implementation with pagination support
- Doctrine ORM XML mappings for entity and embeddable objects

Features:
- UUID identifiers for journal items
- Immutable timestamps using Carbon
- Reference to ApplicationInstallation via UUID
- Support for IP address storage using darsyn/ip library
- Repository methods for deletion by installation ID and by date
- Indexed fields for optimal query performance
@mesilov mesilov marked this pull request as draft November 22, 2025 20:04
@mesilov mesilov self-assigned this Nov 22, 2025
@mesilov mesilov added the enhancement New feature or request label Nov 22, 2025
@gemini-code-assist
Copy link

Summary of Changes

Hello @mesilov, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a comprehensive journaling system designed to capture and manage domain business events within the application. By adhering to Domain-Driven Design patterns and PSR-3 logging standards, it provides a structured, persistent, and queryable mechanism for technical support staff to monitor and understand application behavior. The changes encompass new entities, value objects, interfaces, and a Doctrine-based repository implementation, ensuring robust data handling and integration.

Highlights

  • New Journal Bounded Context: Introduced a new 'Journal' bounded context following Domain-Driven Design (DDD) principles to manage application logging and events.
  • PSR-3 Compatibility: The JournalItem entity now includes PSR-3 compatible factory methods (emergency, alert, critical, error, warning, notice, info, debug) and a LogLevel enum for standardized logging.
  • JournalItem Entity and Value Objects: Added the JournalItem entity, JournalContext value object (for label, JSONB payload, user ID, and IP address), and LogLevel enum to structure journal entries.
  • Data Persistence and Repository: Implemented JournalItemRepositoryInterface and its Doctrine DBAL implementation (DoctrineDbalJournalItemRepository) for CRUD operations, including pagination, and cleanup methods (deletion by installation ID and by date).
  • Doctrine ORM Mappings: Provided Doctrine ORM XML mappings for both the JournalItem entity and the JournalContext embeddable value object, ensuring proper database schema generation and persistence.
  • Key Features: Journal items now use UUID identifiers, immutable Carbon timestamps, reference ApplicationInstallation via UUID, support IP address storage using darsyn/ip, and include indexed fields for optimal query performance.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a well-designed Journal bounded context, complete with entities, value objects, repositories, and Doctrine mappings, adhering to DDD principles and PSR-3 compatibility. The code is clean and utilizes modern PHP features effectively. My review includes suggestions to optimize database query performance by refining table indexes, to simplify the repository implementation by leveraging inherited methods, and to improve data validation within the JournalContext value object to ensure greater data integrity.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Added dependencies and Messenger integration:
- Updated composer.json with Symfony Messenger, Twig Bundle, Form, Routing, and Validator components
- Created TestJournalEvent for demonstration purposes
- Implemented TestJournalEventHandler to write events to journal with INFO level
- Created ConsumeMessagesCommand console command for message consumption

Implemented admin interface components:
- JournalItemReadRepository for filtered data retrieval with KnpPaginator support
- JournalAdminController with two routes:
  * /admin/journal - list view with filters (domain, level, label) and pagination (50 items)
  * /admin/journal/{id} - detailed view with payload visualization

Created Twig templates:
- layout.html.twig - base layout for admin interface
- admin/list.html.twig - journal list with filters, pagination, and responsive design
- admin/show.html.twig - detailed record view with syntax-highlighted JSON payload

Features:
- Filter by Bitrix24 portal domain, log level, and custom labels
- Pagination support (50 records per page)
- Color-coded log levels (emergency to debug)
- JSON payload viewer with syntax highlighting
- Responsive and user-friendly interface
- Full PSR-3 compatibility
#72)

Removed Messenger integration:
- Deleted Events/TestJournalEvent.php
- Deleted MessageHandler/TestJournalEventHandler.php
- Deleted Console/ConsumeMessagesCommand.php
- Removed symfony/messenger and symfony/form from composer.json

Added PSR-3 Logger service:
- JournalLogger - implements Psr\Log\LoggerInterface
  * Uses LoggerTrait for all PSR-3 methods
  * Accepts repository as dependency
  * Writes directly to journal via repository
  * Supports all 8 PSR-3 log levels with context
- JournalLoggerFactory - creates logger instances per installation

Added In-Memory repository implementation:
- InMemoryJournalItemRepository - for testing and non-persistent scenarios
  * Full implementation of JournalItemRepositoryInterface
  * CRUD operations with filtering and pagination
  * Clear and findAll methods for testing

Comprehensive unit tests (4 test suites, 50+ test cases):
- JournalItemTest - Entity creation and validation
  * All PSR-3 factory methods (emergency to debug)
  * Context and payload handling
  * Validation of required fields
- LogLevelTest - PSR-3 level conversion
  * Case-insensitive string conversion
  * All 8 log levels validation
- InMemoryJournalItemRepositoryTest - Repository operations
  * Save/find/delete operations
  * Filtering by installation ID and level
  * Pagination (limit/offset)
  * Date-based cleanup
- JournalLoggerTest - PSR-3 logger functionality
  * All log methods (info, error, warning, etc.)
  * Context preservation
  * Level conversion
  * EntityManager flush verification

Documentation:
- tests/Unit/Journal/README.md - test execution guide

All tests follow PHPUnit 11 conventions and project code standards.
Database changes:
- Renamed table from journal_item to journal
- Added composite index (application_installation_id, level, created_at_utc) for optimal query performance
- Kept separate index on created_at_utc for deleteOlderThan operation

Entity improvements:
- Removed readonly from non-constructor fields (applicationInstallationId, level, message, context)
- ID now generated inside constructor using Uuid::v7()
- Constructor accepts JournalContext object instead of array
- Removed PSR-3 factory methods from JournalItemInterface (they remain in implementation)

JournalContext improvements:
- Made label required (non-nullable)
- Removed fromArray() method
- Simplified API - construct directly with parameters
- Updated Doctrine mapping: label nullable="false"

Controller improvements:
- Removed Route attributes from JournalAdminController
- Developer configures routes in their application
- Added documentation comment about route configuration

Repository organization:
- Moved InMemoryJournalItemRepository from src/ to tests/
- Updated namespace to Bitrix24\Lib\Tests\Unit\Journal\Infrastructure\InMemory
- Used in all unit tests for isolation

JournalLogger changes:
- Updated to create JournalContext from PSR-3 array context
- Added default label 'application.log' if not provided
- IP address parsing with error handling

Documentation:
- Moved src/Journal/README.md to src/Journal/Docs/

Updated all unit tests:
- Tests now create JournalContext objects explicitly
- Updated imports for InMemoryRepository location
- All 50+ tests updated and passing
- Tests verify label is required

All changes maintain backward compatibility at the PSR-3 logger level.
- Replace custom CSS with Bootstrap 5 CDN in layout.html.twig
- Update list.html.twig to use Bootstrap components:
  * Bootstrap forms (form-select, form-label)
  * Bootstrap table (table-hover, table-striped)
  * Bootstrap pagination
  * Bootstrap cards and badges
  * Bootstrap grid system
- Update show.html.twig to use Bootstrap components:
  * Bootstrap breadcrumb
  * Bootstrap cards and badges
  * Bootstrap grid (row, col-md-*)
  * Bootstrap alerts
  * Bootstrap utility classes
- Keep custom styling only for JSON syntax highlighting and log level badges
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Uid\Uuid;

class DoctrineDbalJournalItemRepository extends EntityRepository implements JournalItemRepositoryInterface
Copy link
Collaborator

Choose a reason for hiding this comment

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

Мы за композицию, так код чище

}

#[\Override]
public function deleteByApplicationInstallationId(Uuid $applicationInstallationId): int
Copy link
Collaborator

Choose a reason for hiding this comment

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

Только "свертка" удаляет физичиски данные. Или в 0, или куда-то архивирует. Остальное или не надо, или софт-делит.

/**
* Delete all journal items by application installation ID
*/
public function deleteByApplicationInstallationId(Uuid $applicationInstallationId): int;
Copy link
Collaborator

Choose a reason for hiding this comment

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

убрать

/**
* Count journal items by application installation ID
*/
public function countByApplicationInstallationId(Uuid $applicationInstallationId, ?LogLevel $level = null): int;
Copy link
Collaborator

Choose a reason for hiding this comment

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

убрать

/**
* Factory for creating JournalLogger instances
*/
readonly class JournalLoggerFactory
Copy link
Collaborator

Choose a reason for hiding this comment

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

Если это для тестов, то и унести в тесты

Copy link
Collaborator

@camaxtly camaxtly left a comment

Choose a reason for hiding this comment

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

30-11-2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants