Skip to content

IntelliJ Logging Management

Amir Sagiv edited this page Jul 1, 2017 · 1 revision

Our Logging System

Our current logging system supports:

  • Only one log file for the whole plugin.
  • Single line log entries.

Important notes:

  • There is no need to put logs in tests.
  • It is very important that exceptions thrown during the plugin's run appear in the log file, therefore you should add a log entry in catch clauses.

Logging System Classes

The logging system consists of these three classes:Logger, LogFileUtils and BasicLogEntry.

Logger

The main class of our logging system is Logger. There are currently four levels of logging (from high to low):

  • Debug - includes debugging information, infos, warnings and errors.
  • Info - includes infos, warnings and errors.
  • Warn - includes warnings and errors.
  • Error - includes only errors.

Currently the default level is Info.

This class saves the wanted logging level and logs only events of lower or equal level, for example if the logger's level is Info then events of level Debug will be ignored.

Utils

The LogFileUtils class supplies utils for editing, probing, and creating our log files at low level. This class's main purpose is to actually perform the action of writing into the log file.

Log Entry

The BasicLogEntry class represents a log entry. This is the smallest unit the logger uses and it is what will be printed to the log file.

Logging System Usage

It is very easy to use the logging system in your class, in order to do that you should follow the next steps:

  • There should be a static member of type Logger in your class. This member will be initialized with your class's Class object.
  • In order to change the level of logging (as explained above) use the method setLogLevel.
  • To add a log entry you will need to use the appropriate method for the type of the entry: debug, info, warn, error. You can check the full API of the Logger class here. Notice that entries of higher level than the one set to the logger will be ignored.

An example of usage can be found here.

Links

Clone this wiki locally