Logger initialized with foreign class
Reports Logger instances that are initialized with a class literal from a different class than the Logger is contained in. This can easily happen when copy-pasting some code from another class and may result in logging events under an unexpected category and cause filters to be applied incorrectly.
A quick-fix is provided to replace the foreign class literal with one from the surrounding class.
Example:
After the quick-fix is applied:
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
LoggerInitializedWithForeignClass- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
Configure the inspection:
Use the table to specify the logger factory classes and logger factory methods recognized by this inspection.
Use the Ignore loggers initialized with a superclass option to ignore loggers that are initialized with a superclass of the class containing the logger.
Use the Ignore loggers in non-public classes to only warn on loggers in
publicclasses.Use the Ignore loggers not initialized in a final field to only report loggers initialized in a final field, other cases will be ignored.
Inspection ID: LoggerInitializedWithForeignClass
Inspection options
Here you can find the description of settings available for the Logger initialized with foreign class inspection, and the reference of their default values.
- Ignore loggers initialized with a superclass
Option ID:
ignoreSuperClassDefault value:
Not selected- Ignore loggers in non-public classes
Option ID:
ignoreNonPublicClassesDefault value:
Not selected- Ignore loggers not initialized in a final field
Option ID:
ignoreNotFinalFieldDefault value:
Selected
Suppressing Inspection
You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:
More detailed instructions as well as other ways and options that you have can be found in the product documentation:
Inspection Details | |
|---|---|
By default bundled with: |