|
| 1 | +# logging Specification |
| 2 | + |
| 3 | +## Purpose |
| 4 | +TBD - created by archiving change add-runtime-logging-support. Update Purpose after archive. |
| 5 | +## Requirements |
| 6 | +### Requirement: Logging configuration |
| 7 | +The host SHALL expose a shared logging configuration that controls console and file sinks for runtime and modules. |
| 8 | + |
| 9 | +#### Scenario: Default configuration applied |
| 10 | +- **WHEN** the host starts without custom logging settings |
| 11 | +- **THEN** console logging is enabled at Information level |
| 12 | +- **AND** file logging is enabled at Information level |
| 13 | +- **AND** the log directory defaults to the host-specific logs folder. |
| 14 | + |
| 15 | +#### Scenario: Environment overrides configuration |
| 16 | +- **WHEN** logging settings (levels, enablement, paths) are provided via appsettings or environment variables |
| 17 | +- **THEN** the runtime applies the overridden values without code changes |
| 18 | +- **AND** the settings flow to all runtime and module loggers. |
| 19 | + |
| 20 | +### Requirement: Console logging |
| 21 | +The system SHALL emit console logs for runtime and module events when console logging is enabled. |
| 22 | + |
| 23 | +#### Scenario: Console output on startup |
| 24 | +- **WHEN** the host starts with console logging enabled |
| 25 | +- **THEN** startup events (database init, module discovery, module load begin/end) are written to STDOUT with timestamp and level. |
| 26 | + |
| 27 | +#### Scenario: Console logging can be disabled |
| 28 | +- **WHEN** console logging is disabled via configuration |
| 29 | +- **THEN** runtime and module logs stop writing to the console sink. |
| 30 | + |
| 31 | +### Requirement: File runtime logging |
| 32 | +The system SHALL write runtime and module logs to a rolling file sink with retention using Serilog (MEL provider + Serilog file sink), avoiding custom file writers. |
| 33 | + |
| 34 | +#### Scenario: File log created with defaults |
| 35 | +- **WHEN** the host starts with file logging enabled |
| 36 | +- **THEN** a log file is created under the configured logs directory (default `%AppData%/Modulus/Logs/{Host}/` or `$HOME/.modulus/logs/{host}/`) |
| 37 | +- **AND** runtime/module log entries are appended with timestamps and levels. |
| 38 | + |
| 39 | +#### Scenario: Rolling and retention enforced |
| 40 | +- **WHEN** a log file exceeds the configured size limit or rolling interval |
| 41 | +- **THEN** the file is rolled with an incremented or timestamped suffix |
| 42 | +- **AND** only the configured number of retained log files is kept. |
| 43 | + |
| 44 | +#### Scenario: Serilog file sink in use |
| 45 | +- **WHEN** file logging is enabled |
| 46 | +- **THEN** the logging pipeline uses the Serilog MEL provider with the Serilog file sink |
| 47 | +- **AND** no custom file writer is used for runtime or module logging. |
| 48 | + |
| 49 | +### Requirement: Log context enrichment |
| 50 | +Runtime log entries SHALL include host and module context. |
| 51 | + |
| 52 | +#### Scenario: Host log context |
| 53 | +- **WHEN** the host emits a log entry |
| 54 | +- **THEN** the entry includes the host type identifier (e.g., Avalonia, Blazor). |
| 55 | + |
| 56 | +#### Scenario: Module log context |
| 57 | +- **WHEN** code inside a loaded module emits a log entry |
| 58 | +- **THEN** the entry includes the module id and version when available |
| 59 | +- **AND** the host type context remains present. |
| 60 | + |
| 61 | +### Requirement: Runtime lifecycle logging coverage |
| 62 | +The runtime SHALL log critical lifecycle events for module discovery, validation, load, initialization, and shutdown. |
| 63 | + |
| 64 | +#### Scenario: Module load success |
| 65 | +- **WHEN** a module is loaded successfully |
| 66 | +- **THEN** an info-level log is written with module id, version, and dependency count. |
| 67 | + |
| 68 | +#### Scenario: Module load failure |
| 69 | +- **WHEN** a module fails to load or initialize |
| 70 | +- **THEN** an error-level log is written with module id, path, and exception details |
| 71 | +- **AND** the failure is persisted to the file sink. |
| 72 | + |
| 73 | +### Requirement: Module logging usage |
| 74 | +Modules SHALL use the host-provided logging pipeline without redefining or redirecting logging configuration. |
| 75 | + |
| 76 | +#### Scenario: Module obtains logger |
| 77 | +- **WHEN** a module requests `ILogger<T>` or `ILoggerFactory` from DI |
| 78 | +- **THEN** it receives the host-configured logging pipeline (console/file Serilog) with host and module context enrichment. |
| 79 | + |
| 80 | +#### Scenario: Module cannot reconfigure logging |
| 81 | +- **WHEN** a module attempts to add/replace logging providers or change logging levels/paths |
| 82 | +- **THEN** the attempt is ignored or rejected |
| 83 | +- **AND** the host-owned logging configuration remains active for all runtime and module logs. |
| 84 | + |
0 commit comments