Представление Watchdog

Опубликовал Максим Баев, 28 сентября 2016, 12:27

Для тех кому не нравится стандартный вывод журнала (watchdog) в Drupal 8, представляю вьюху Watchdog. Она похожа на то, что по умолчанию предоставляет стандартный журнал, а также дополнительные плюшки:

  • Поле IP
  • Дата со временем (в стандартном только дата, времени нет)
  • Возможность сортировки по всем полям

Также осталась возможность фильтрации в том же виде. Главное преимущество заключается в том, что представление легко изменить: добавить поля, критерии фильтрации, изменить порядок отображения столбцов в таблице и остальные настройки предоставляемые модулем Views.

Есть и минусы:

  • Нет кнопки "Очистить журнал";
  • Нет столбца "Пользователь"
  • Уровень опасности выглядит менее красиво.

По этой причине представление Watchdog не заменяет текущее представление, а находится рядом с ним.

Инастляция

  • Убеждаемся в том, что включен модуль Views UI
  • Переходим на страницу Импорта (admin/config/development/configuration/single/import)
  • Выбираем Тип конфигурации - Представление (Configuration type - View)
    drupal-8-import.jpg
  • В текстовое поле вставляем следующую конфигурацию:
    uuid: 27575626-4813-4a75-840b-765e24fd466d
    langcode: ru
    status: true
    dependencies:
      config:
       - system.menu.admin
      module:
       - dblog
        - user
    id: watchdog
    label: Watchdog
    module: views
    description: 'Provide list of logs'
    tag: ''
    base_table: watchdog
    base_field: wid
    core: 8.x
    display:
      default:
        display_plugin: default
        id: default
        display_title: Master
        position: 0
        display_options:
          access:
            type: perm
            options:
              perm: 'access site reports'
          cache:
            type: tag
            options: {  }
          query:
            type: views_query
            options:
              disable_sql_rewrite: false
              distinct: false
              replica: false
              query_comment: ''
              query_tags: {  }
          exposed_form:
            type: basic
            options:
              submit_button: Apply
              reset_button: true
              reset_button_label: Reset
              exposed_sorts_label: 'Sort by'
              expose_sort_order: false
              sort_asc_label: Asc
              sort_desc_label: Desc
          pager:
            type: full
            options:
              items_per_page: 50
              offset: 0
              id: 0
              total_pages: null
              tags:
                previous: ‹‹
                next: ››
                first:  First'
                last: 'Last »'
              expose:
                items_per_page: false
                items_per_page_label: 'Items per page'
                items_per_page_options: '5, 10, 25, 50'
                items_per_page_options_all: false
                items_per_page_options_all_label: '- All -'
                offset: false
                offset_label: Offset
              quantity: 9
          style:
            type: table
            options:
              grouping: {  }
              row_class: '{{ severity }} dblog-{{type}}'
              default_row_class: true
              override: true
              sticky: false
              caption: ''
              summary: ''
              description: ''
              columns:
                wid: wid
                severity: severity
                type: type
                timestamp: timestamp
                message: message
                hostname: hostname
                referer: referer
                link: link
              info:
                wid:
                  sortable: true
                  default_sort_order: asc
                  align: ''
                  separator: ''
                  empty_column: false
                  responsive: ''
                severity:
                  sortable: true
                  default_sort_order: asc
                  align: ''
                  separator: ''
                  empty_column: false
                  responsive: ''
                type:
                  sortable: true
                  default_sort_order: asc
                  align: ''
                  separator: ''
                  empty_column: false
                  responsive: ''
                timestamp:
                  sortable: true
                  default_sort_order: desc
                  align: ''
                  separator: ''
                  empty_column: false
                  responsive: ''
                message:
                  sortable: true
                  default_sort_order: asc
                  align: ''
                  separator: ''
                  empty_column: false
                  responsive: ''
                hostname:
                  sortable: true
                  default_sort_order: asc
                  align: ''
                  separator: ''
                  empty_column: false
                  responsive: ''
                referer:
                  sortable: true
                  default_sort_order: asc
                  align: ''
                  separator: ''
                  empty_column: false
                  responsive: ''
                link:
                  align: ''
                  separator: ''
                  empty_column: false
                  responsive: ''
              default: timestamp
              empty_table: false
          row:
            type: fields
          fields:
            wid:
              id: wid
              table: watchdog
              field: wid
              relationship: none
              group_type: group
              admin_label: ''
              label: ''
              exclude: true
              alter:
                alter_text: false
                text: ''
                make_link: false
                path: ''
                absolute: false
                external: false
                replace_spaces: false
                path_case: none
                trim_whitespace: false
                alt: ''
                rel: ''
                link_class: ''
                prefix: ''
                suffix: ''
                target: ''
                nl2br: false
                max_length: 0
                word_boundary: true
                ellipsis: true
                more_link: false
                more_link_text: ''
                more_link_path: ''
                strip_tags: false
                trim: false
                preserve_tags: ''
                html: false
              element_type: ''
              element_class: ''
              element_label_type: ''
              element_label_class: ''
              element_label_colon: false
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: true
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
              set_precision: false
              precision: 0
              decimal: .
              separator: ''
              format_plural: false
              format_plural_string: "1\x03@count\x03"
              prefix: ''
              suffix: ''
              plugin_id: numeric
            severity:
              id: severity
              table: watchdog
              field: severity
              relationship: none
              group_type: group
              admin_label: ''
              label: Уровень
              exclude: false
              alter:
                alter_text: false
                text: ''
                make_link: false
                path: ''
                absolute: false
                external: false
                replace_spaces: false
                path_case: none
                trim_whitespace: false
                alt: ''
                rel: ''
                link_class: ''
                prefix: ''
                suffix: ''
                target: ''
                nl2br: false
                max_length: 0
                word_boundary: true
                ellipsis: true
                more_link: false
                more_link_text: ''
                more_link_path: ''
                strip_tags: false
                trim: false
                preserve_tags: ''
                html: false
              element_type: ''
              element_class: icon
              element_label_type: ''
              element_label_class: ''
              element_label_colon: false
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: false
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
              machine_name: false
              plugin_id: machine_name
            type:
              id: type
              table: watchdog
              field: type
              relationship: none
              group_type: group
              admin_label: ''
              label: Type
              exclude: false
              alter:
                alter_text: false
                text: ''
                make_link: false
                path: ''
                absolute: false
                external: false
                replace_spaces: false
                path_case: none
                trim_whitespace: false
                alt: ''
                rel: ''
                link_class: ''
                prefix: ''
                suffix: ''
                target: ''
                nl2br: false
                max_length: 0
                word_boundary: true
                ellipsis: true
                more_link: false
                more_link_text: ''
                more_link_path: ''
                strip_tags: false
                trim: false
                preserve_tags: ''
                html: false
              element_type: ''
              element_class: ''
              element_label_type: ''
              element_label_class: ''
              element_label_colon: true
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: true
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
              plugin_id: standard
            timestamp:
              id: timestamp
              table: watchdog
              field: timestamp
              relationship: none
              group_type: group
              admin_label: ''
              label: Время
              exclude: false
              alter:
                alter_text: false
                text: ''
                make_link: false
                path: ''
                absolute: false
                external: false
                replace_spaces: false
                path_case: none
                trim_whitespace: false
                alt: ''
                rel: ''
                link_class: ''
                prefix: ''
                suffix: ''
                target: ''
                nl2br: false
                max_length: 0
                word_boundary: true
                ellipsis: true
                more_link: false
                more_link_text: ''
                more_link_path: ''
                strip_tags: false
                trim: false
                preserve_tags: ''
                html: false
              element_type: ''
              element_class: ''
              element_label_type: ''
              element_label_class: ''
              element_label_colon: true
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: true
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
              date_format: fallback
              custom_date_format: ''
              timezone: ''
              plugin_id: date
            message:
              id: message
              table: watchdog
              field: message
              relationship: none
              group_type: group
              admin_label: ''
              label: Сообщение
              exclude: false
              alter:
                alter_text: false
                text: ''
                make_link: true
                path: '/admin/reports/dblog/event/{{ wid }}'
                absolute: false
                external: false
                replace_spaces: false
                path_case: none
                trim_whitespace: false
                alt: ''
                rel: ''
                link_class: ''
                prefix: ''
                suffix: ''
                target: ''
                nl2br: false
                max_length: 100
                word_boundary: true
                ellipsis: true
                more_link: false
                more_link_text: ''
                more_link_path: ''
                strip_tags: false
                trim: true
                preserve_tags: ''
                html: true
              element_type: ''
              element_class: ''
              element_label_type: ''
              element_label_class: ''
              element_label_colon: true
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: true
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
              replace_variables: true
              plugin_id: dblog_message
            hostname:
              id: hostname
              table: watchdog
              field: hostname
              relationship: none
              group_type: group
              admin_label: ''
              label: 'Имя хоста'
              exclude: false
              alter:
                alter_text: false
                text: ''
                make_link: false
                path: ''
                absolute: false
                external: false
                replace_spaces: false
                path_case: none
                trim_whitespace: false
                alt: ''
                rel: ''
                link_class: ''
                prefix: ''
                suffix: ''
                target: ''
                nl2br: false
                max_length: 0
                word_boundary: true
                ellipsis: true
                more_link: false
                more_link_text: ''
                more_link_path: ''
                strip_tags: false
                trim: false
                preserve_tags: ''
                html: false
              element_type: ''
              element_class: ''
              element_label_type: ''
              element_label_class: ''
              element_label_colon: true
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: true
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
              plugin_id: standard
            referer:
              id: referer
              table: watchdog
              field: referer
              relationship: none
              group_type: group
              admin_label: ''
              label: Источник
              exclude: false
              alter:
                alter_text: false
                text: ''
                make_link: false
                path: ''
                absolute: false
                external: false
                replace_spaces: false
                path_case: none
                trim_whitespace: false
                alt: ''
                rel: ''
                link_class: ''
                prefix: ''
                suffix: ''
                target: ''
                nl2br: false
                max_length: 0
                word_boundary: true
                ellipsis: true
                more_link: false
                more_link_text: ''
                more_link_path: ''
                strip_tags: false
                trim: false
                preserve_tags: ''
                html: false
              element_type: ''
              element_class: ''
              element_label_type: ''
              element_label_class: ''
              element_label_colon: true
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: true
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
              plugin_id: standard
            link:
              id: link
              table: watchdog
              field: link
              relationship: none
              group_type: group
              admin_label: ''
              label: Operations
              exclude: false
              alter:
                alter_text: false
                text: ''
                make_link: false
                path: ''
                absolute: false
                external: false
                replace_spaces: false
                path_case: none
                trim_whitespace: false
                alt: ''
                rel: ''
                link_class: ''
                prefix: ''
                suffix: ''
                target: ''
                nl2br: false
                max_length: 0
                word_boundary: true
                ellipsis: true
                more_link: false
                more_link_text: ''
                more_link_path: ''
                strip_tags: false
                trim: false
                preserve_tags: ''
                html: false
              element_type: ''
              element_class: ''
              element_label_type: ''
              element_label_class: ''
              element_label_colon: true
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: true
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
              plugin_id: dblog_operations
          filters:
            type:
              id: type
              table: watchdog
              field: type
              relationship: none
              group_type: group
              admin_label: ''
              operator: in
              value: {  }
              group: 1
              exposed: true
              expose:
                operator_id: type_op
                label: Type
                description: ''
                use_operator: false
                operator: type_op
                identifier: type
                required: false
                remember: true
                multiple: true
                remember_roles:
                  authenticated: authenticated
                  anonymous: '0'
                  administrator: '0'
                reduce: false
              is_grouped: false
              group_info:
                label: Type
                description: null
                identifier: type
                optional: true
                widget: select
                multiple: false
                remember: false
                default_group: All
                default_group_multiple: {  }
                group_items:
                  1: {  }
                  2: {  }
                  3: {  }
              plugin_id: in_operator
            severity:
              id: severity
              table: watchdog
              field: severity
              relationship: none
              group_type: group
              admin_label: ''
              operator: in
              value: {  }
              group: 1
              exposed: true
              expose:
                operator_id: severity_op
                label: 'Уровень опасности'
                description: ''
                use_operator: false
                operator: severity_op
                identifier: severity
                required: false
                remember: true
                multiple: true
                remember_roles:
                  authenticated: authenticated
                  anonymous: '0'
                  administrator: '0'
                reduce: false
              is_grouped: false
              group_info:
                label: ''
                description: ''
                identifier: ''
                optional: true
                widget: select
                multiple: false
                remember: false
                default_group: All
                default_group_multiple: {  }
                group_items: {  }
              plugin_id: in_operator
          sorts:
            timestamp:
              id: timestamp
              table: watchdog
              field: timestamp
              order: DESC
              entity_type: null
              entity_field: null
              plugin_id: date
              relationship: none
              group_type: group
              admin_label: ''
              exposed: false
              expose:
                label: ''
              granularity: second
          title: Watchdog
          header: {  }
          footer: {  }
          empty: {  }
          relationships: {  }
          arguments:
            uid:
              id: uid
              table: watchdog
              field: uid
              plugin_id: numeric
          display_extenders: {  }
          use_ajax: true
          css_class: admin-dblog
          link_url: ''
          link_display: page_1
        cache_metadata:
          max-age: 0
          contexts:
           - 'languages:language_interface'
            - url
            - url.query_args
            - user.permissions
          tags: {  }
      page_1:
        display_plugin: page
        id: page_1
        display_title: Page
        position: 1
        display_options:
          display_extenders: {  }
          path: admin/reports/watchdog
          menu:
            type: normal
            title: Watchdog
            menu_name: admin
            description: ''
            parent: system.admin_reports
            weight: 0
            expanded: false
            enabled: true
        cache_metadata:
          max-age: 0
          contexts:
           - 'languages:language_interface'
            - url
            - url.query_args
            - user.permissions
          tags: {  }
  • В Расширенном оставляем все как есть
  • Жмем Импортировать
  • Пьем кофе

После проделанных манипуляций, возможно, понадобится очистка кэша и можно пользоваться.

watchdog-view-drupal-8

Другие посты