Sensei Logo Sensei Hub

Recipe - SLF4J Logging: Naming convention: Standardise logger name

Description:
The SLF4J logger instance should be named "logger". Use Refactor Rename (Shift+F6) to rename this variable.
Level:
marked_information
Language:
  • java
Tags:
  • SLF4J
  • framework specific
  • logging
  • quality
Recipe
id: scw:logging:logger-name
version: 10
metadata:
  name: 'SLF4J Logging: Naming convention: Standardise logger name'
  shortDescription: The SLF4J logger instance should be named "logger". Use Refactor Rename (Shift+F6) to rename this variable.
  level: marked_information
  language: java
  scwCategory: insufficient_logging:generic
  cweCategory: 778
  enabled: true
  tags: SLF4J;framework specific;logging;quality
search:
  field:
    in:
      typeDeclaration:
        anyOf:
        - with:
            child:
              field:
                name: logger
                type: org.slf4j.Logger
        - without:
            child:
              field:
                name: logger
                type:
                  reference:
                    not: org.slf4j.Logger
                  checkInheritance: true
    name:
      not: logger
    type: org.slf4j.Logger
availableFixes:
- name: Rename this instance to logger
  actions:
  - rewrite:
      to: '{{{modifierList}}} {{{typeElement}}} logger = {{{assignedExpression}}};'
      target: self
- name: Refactor rename the variable using Shift+F6
  actions: []