Logging
The jetbrains.mps.baselanguage.logging language contains statements for writing arbitrary information into the MPS log as well as to the Messages tool view panel. The LogLowLevelStatement concept (aka "log error ...") is used for logging using the system logger, while MsgStatement (aka "message error...") is used for logging into the Messages tool window.
The Messages tool window is located at the bottom of the screen:
The MPS log file can be quickly navigated to using the menu:
The language supports different severities of log messages:
trace
info
debug
warn
error
fatal
Whenever you want to insert a log statement into code, start by typing either "log" or "message" followed by the desired severity:
Upon completion the log statement with an empty message will be inserted.
The severity level can always be changed:
The log statement also supports exceptions to be specified:
MsgStatement contains an additional parameter to specify the project:
When multiple projects are open in MPS at the same time, each project gets its own MPS window (frame) and thus also its own Messages view. The project parameter is used to output the log message into the Messages window of the right project. If you leave the parameter empty, the message will be logged into Messages tool views of all open projects.
Obtaining the current project object
The object that represents the current project is a bit tricky to obtain. To add insult to injury, there are several Project classes and interfaces available, each being used at different situations:
com.intellij.openapi.project.Project - an interface from the platform
org.jetbrains.mps.openapi.Project - an interface in MPS
jetbrains.mps.project.Project - abstract class in MPS implementing the org.jetbrains.mps.openapi.Project interface
jetbrains.mps.project.MPSProject - one of several concrete subclasses of jetbrains.mps.project.Project
jetbrains.mps.ide.project.ProjectHelper - a handy conversion utility class
The statements of the logging language expect an instance of the org.jetbrains.mps.openapi.Project, which means that the jetbrains.mps.project.Project class or its jetbrains.mps.project.MPSProject subclass are also allowed. The platform com.intellij.openapi.project.Project interface is not allowed, but you can use jetbrains.mps.ide.project.ProjectHelper to convert between the platform and the MPS-specific project objects.
Some elements, such as Actions, for example, obtain project as a parameter. For other places, where either editorContext or genContext is available, jetbrains.mps.ide.project.ProjectHelper can be used to resolve a project from the repository: