Recipe Name:
SLF4J Logging: Replace java.util.logging with SLF4J (Log Object Debug)
Description:
Standardise on SLF4J by replacing this call
Level:
marked_information
Language:
  • java
Tags:
  • SLF4J
  • framework specific
  • logging
  • quality
Recipe
id: scw:logging:slf4j-jul-object-3rd-debug
version: 10
metadata:
  name: 'SLF4J Logging: Replace java.util.logging with SLF4J (Log Object Debug)'
  shortDescription: Standardise on SLF4J by replacing this call
  level: marked_information
  language: java
  scwCategory: insufficient_logging:generic
  cweCategory: 778
  enabled: true
  tags: SLF4J;framework specific;logging;quality
search:
  methodcall:
    args:
      1:
        referenceTo:
          name:
            matches: java\.util\.logging\.Level\.(FINE|CONFIG)
      3:
        type: java.lang.Object
    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
    argCount: 3
    name: log
    type: java.util.logging.Logger
availableFixes:
- name: ' [RECOMMENDED] Replace with SLF4J debug function'
  actions:
  - rewrite:
      to: logger.debug({{{arguments.1}}}, {{{arguments.2}}})
      target: self
  - addField:
      field: private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger({{{ containingClass.containingClass.name }}}.class);
      target: parentClass
- name: '[OPTIONAL] Replace with SLF4J error function'
  actions:
  - rewrite:
      to: logger.error({{{arguments.1}}}, {{{arguments.2}}})
      target: self
  - addField:
      field: private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger({{{ containingClass.containingClass.name }}}.class);
      target: parentClass
- name: '[OPTIONAL] Replace with SLF4J info function'
  actions:
  - rewrite:
      to: logger.info({{{arguments.1}}}, {{{arguments.2}}})
      target: self
  - addField:
      field: private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger({{{ containingClass.containingClass.name }}}.class);
      target: parentClass
- name: '[OPTIONAL] Replace with SLF4J warn function'
  actions:
  - rewrite:
      to: logger.warn({{{arguments.1}}}, {{{arguments.2}}})
      target: self
  - addField:
      field: private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger({{{ containingClass.containingClass.name }}}.class);
      target: parentClass
- name: '[OPTIONAL] Replace with SLF4J trace function'
  actions:
  - rewrite:
      to: logger.trace({{{arguments.1}}}, {{{arguments.2}}})
      target: self
  - addField:
      field: private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger({{{ containingClass.containingClass.name }}}.class);
      target: parentClass