Skip to content
Snippets Groups Projects
  • totten's avatar
    c213eb51
    community/feature-request#12 - Allow named logging channels · c213eb51
    totten authored
    Overview
    ----------------------------------------
    
    Make it easier to route log messages based on their topic (e.g. CiviContribute-related logs vs CiviMail-related logs).
    
    Before
    ------
    
    `Civi::log()` always returns the same instance of `LoggerInterface`, with no
    clear way to differentiate logs of different business subsystems.
    
    After
    -----
    
    `Civi::log(...)` allows you to optionally request a `LoggerInterface` for a specific theme, e.g.
    
    ```php
    Civi::log('mail')->error('Failed to connect to SMTP server');
    Civi::log('ipn')->warning('Transaction rejected by payment processor');
    ```
    
    Technical Details
    -----------------
    
    A few things going on here:
    
    * Extensions may start using their own logs (`Civi::log('myext')`) without any special effort.
    * It is possible to replace or customize specific logs by defining a service `log.CHANNEL_NAME`.
    * The `psr_log_manager` is a service. An extension like https://lab.civicrm.org/extensions/monolog/
      can replace the `psr_log_manager` and use the channel-name in its own way.
    
    There is a limitation here in that the list of channels is open-ended.  It
    will be impossible to (eg) detect that a log-user has made a typo in the
    channel-name.  However, this seems like the better trade-off if the
    alternative is that extensions face races during
    installation/uninstallation.
    c213eb51
    History
    community/feature-request#12 - Allow named logging channels
    totten authored
    Overview
    ----------------------------------------
    
    Make it easier to route log messages based on their topic (e.g. CiviContribute-related logs vs CiviMail-related logs).
    
    Before
    ------
    
    `Civi::log()` always returns the same instance of `LoggerInterface`, with no
    clear way to differentiate logs of different business subsystems.
    
    After
    -----
    
    `Civi::log(...)` allows you to optionally request a `LoggerInterface` for a specific theme, e.g.
    
    ```php
    Civi::log('mail')->error('Failed to connect to SMTP server');
    Civi::log('ipn')->warning('Transaction rejected by payment processor');
    ```
    
    Technical Details
    -----------------
    
    A few things going on here:
    
    * Extensions may start using their own logs (`Civi::log('myext')`) without any special effort.
    * It is possible to replace or customize specific logs by defining a service `log.CHANNEL_NAME`.
    * The `psr_log_manager` is a service. An extension like https://lab.civicrm.org/extensions/monolog/
      can replace the `psr_log_manager` and use the channel-name in its own way.
    
    There is a limitation here in that the list of channels is open-ended.  It
    will be impossible to (eg) detect that a log-user has made a typo in the
    channel-name.  However, this seems like the better trade-off if the
    alternative is that extensions face races during
    installation/uninstallation.