Proper way to log in Idea plugins
I see there's an API to log errors:
PluginManager.getLogger().error("test");
- the result is saved into the Idea "error log" and can be accessed by clicking on red blinking icon at the bottom.
now, I also want to log warnings or some debug info and I'm trying to use:
PluginManager.getLogger().warn("test");
This is not added to the errors list, so I guess I can't see these messages in Idea itself (?)
Does Idea have something similar to Eclipse "Error log" view, where plugins could log messages to in a standard way?
Please sign in to leave a comment.
I use the class: import com.intellij.openapi.diagnostic.Logger
Then:
private static final Logger log = Logger.getInstance();
I had never heard of PluginManager.getLogger until just now.
I just use log4j (actually, I use slf4j bridged to log4j, but same thing) to write trace and debug statements - it seems to write to the normal idea log just fine.
You can even add additional config to the the <idea home>/bin/log.xml file to get some custom log config going - writing all log statements from your plugin to a separate file, for example.
But it would be interesting to see some feedback from Jetbrains on the "right" way to deal with logging, since there seems to be a few different mechanisms.
Hello Shorn,
The right way is to use the IDEA logger class (com.intellij.openapi.diagnostic.Logger)
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Is there a way to view the logged info in the IDEA itself? Similar to Eclipse "Error Log"
Hello Alexey,
The current version doesn't have any log view. It's possible that IDEA 11
will have something like that.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
But you can show idea.log of the instance which runs your plugin in the instance in which you develop your plugin if you start the plugin-running instance from your development instance. Just check the checkbox "Show idea.log" or how it is called in the the plugin run configuration. If you want to see it for an installed version of your plugin, you can use "tail -f" or any other log viewer to view idea.log.
the "IDEA LOG" View is great, that's what we need. Unfortunately, it will only be shown in the development IDEA and not in the one I start from it.
Yes, as I said.
For the log of the IntelliJ you start the plugin with if you don't have a development IntelliJ or additionally to it as I said you would have to use some log viewer like
- "tail -f" from the command line
or
- http://plugins.intellij.net/plugin/?idea&id=1119
or
- http://plugins.intellij.net/plugin/?idea&id=46
But I don't know whether those plugins still work, they are quite old.
You can aloso trick the IntelliJ you are running your plugin with by making a run configuration that runs something that just sits there and waits and configure the idea.log as logfile for that run configuration.
Hello Alexey,
IDEA 11 will be out by the end of this year. We don't have any date for the
start of the EAP yet.
Note that you can build the latest Community Edition sources as often as
you want - all of its development is completely public.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Hi!,
I use the IntelliJ logger:
but when I try:
I don´t see the trace in the log file. I've tried with debug mode too but the result is the same Whit the others levels (info, warn or error) it works OK. Does anyone know why?
Thanks!
This will print your message to Event Log ( at the right bottom of th IDE)
If you want to disable the balloon, you have to add :
AFTER Nofifications.Bus.nofity(noitification);
Or you will get a NullPointerExcetion =)
The balloon and log could be also disabled/configed in Event Log if you group your notifications properly.
Hope this could be heplful to all of you.
If you just want to debug it locally, I found a way.
The path is /xxxxxxxxxxx/build/idea-sandbox/system/log/idea.log
Where xxx is the path of the current project.
Now you can use it this way
You can use either of the two. The log will be printed on console, and of course it will only be used for debugging in a sandbox environment.
I don't know if this is the right thing to do, but I am using it this way to debug my plug-in.