drupal / govnl_cms_logging
Enables Logging functionality for GovNL CMS projects.
Package info
git.drupalcode.org/project/govnl_cms_logging.git
Type:drupal-recipe
pkg:composer/drupal/govnl_cms_logging
Requires
- drupal/admin_audit_trail: ^1.0
- drupal/core: ^11.1
- drupal/govnl_logging: ^1.0
- drupal/monolog: ^3.0
- drupal/raven: ^7.5
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
This recipe enables the Logging settings used in GovNL CMS projects.
Read the documentation of the GovNL recipes setup carefully before installing this recipe.
Submit bug reports and feature suggestions, or track changes in the issue queue.
Requirements
This module requires the following modules:
Installation
Install as you would normally install a contributed Drupal recipe. For further information, see How to Download and Apply Drupal Recipes.
Configuration
The GovNL Logging module provides Monolog processors, a JSON formatter, and a Sentry event subscriber. To use these services, configure your monolog.services.yml file.
- Open or create
sites/default/monolog.services.yml. - Register the custom processors (
request_id,app_context) underparameters.monolog.processorsor per handler. - Assign the
toplevel_jsonformatter to your log handlers (e.g. stdout). - Make sure the
monolog.services.ymlis included insettings.phpusing$settings['container_yamls'][] = 'sites/default/monolog.services.yml';
Example monolog.services.yml configuration:
parameters:
monolog.channel_handlers:
default:
handlers:
- name: 'drupal.dblog'
- name: 'drupal.raven'
processors: ['current_user', 'request_uri', 'ip', 'referer']
- name: 'stdout_debug'
formatter: 'toplevel_json'
system:
handlers:
- name: 'drupal.dblog'
- name: 'drupal.raven'
processors: ['current_user', 'request_uri', 'ip', 'referer']
- name: 'stdout_warning'
formatter: 'toplevel_json'
monolog.processors:
- 'message_placeholder'
- 'current_user'
- 'request_uri'
- 'ip'
- 'referer'
- 'request_id'
- 'app_context'
services:
monolog.handler.stdout_debug:
class: Monolog\Handler\StreamHandler
arguments: ['php://stdout', 'DEBUG']
monolog.handler.stdout_warning:
class: Monolog\Handler\StreamHandler
arguments: ['php://stdout', 'WARNING']
Environment variables
The app_context processor automatically reads the following environment
variables to enrich log entries:
ENVIRONMENT: Deployment environment name (for example:production,staging,test,review).RELEASE_SERVICE: Service name (for example:gwp-frontend).HOSTNAME: Container hostname or Kubernetes pod name.RELEASE_HOSTNAME: Hostname used as a fallback to detect the environment when theENVIRONMENTvariable is not set.
Request correlation
The request_id processor correlates log records during an HTTP request:
- If an incoming
X-Request-IDHTTP header is present, its value is used. - If no header is present, a 32-character hexadecimal ID is generated.
- The request ID is cached in the request attribute
_request_idthroughout the request lifecycle.