To prevent spam users, you can only post on this forum after registration, which is by invitation. If you want to post on the forum, please send me a mail (h DOT m DOT w DOT verbeek AT tue DOT nl) and I'll send you an invitation in return for an account.

logging

Wiebe
edited March 2011 in - Development
Hi,

I have a question about errors, logging and user feedback.

I have looked at the following resource about logging:
https://svn.win.tue.nl/trac/prom/wiki/setup/Contexts/Logging

When I use the following method the message does not appear in the ProM interface and not in the console, regardless of the MessageLevel. (I'm probably missing something here.)

PluginContext.log(message, MessageLevel.ERROR);

To get messages in the console I added the following workaround code, which let's the console explicitly listen to the PluginContext.

final OutputStream out = System.out;
context.getLoggingListeners().add(new Logger() {
    public void log(String message, PluginContextID contextID, MessageLevel messageLevel) {
        try {
            out.write((message + "\n").getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public void log(Throwable t, PluginContextID contextID) {
        try {
            out.write((t.getMessage() + "\n").getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
});

Further in my code I have two logging lines which both get executed. Strangely enough the first one now gets written to the console but the second does not, regardless of the MessageLevel.

Long story short:
Can I get log messages of a high MessageLevel to appear in the user interface somewhere? (similar to ProM 5.2)
What is the proper way to log everything to the console?

Comments

  • Hi Wiebe,

    When you make a plugin, one of the parameters of your method would contain an object named "context" with object type name similar to "PluginContext" (e.g. it can also be UIPluginContext). You can use the object to log things simply using the following line of code (without any message level):

    context.log("your message");

    To show them, go to the "Tasks" panel. To view this panel from the main ProM 6 panel, click the tab button that shows the list of all available plugins and click the "Activity..." button that is shown on the right top side of the screen.

    Cheers,
    Arya
  • Hi Arya,

    Thanks you for your answer.

    Currently I am writing an import plugin and the method derived from AbstractImportPlugin looks like this:

    protected Object importFromStream(PluginContext context, InputStream is, String filename, long fileSizeInBytes) { [...]

    In my method implementation I am doing multiple invocations of:

    context.log("your message");

    After I execute the import plugin and click the Activity... button in the Action view in the Tasks list is empty, where I hoped to see my log messages.

    Is this because the "context" parameter is of type PluginContext and not UIPluginContext?

    What would be the best way to give user feedback about whether the import was successful?
    (I'm hoping to be able to give multiple parser errors and warnings to the user by way context.log messages so adjustments can be made to a faulty import file.)

    And how can I make all context.log("your message") messages appear in the console without the ugly workaround listed my previous post?
    (This workaround does not work completely like I hoped it would.)

    Cheers,
    Wiebe
  • Hi Wiebe,

    Problem is that the import plug-ins are not reflected by the Tasks dialog as mentioned by Arya. If the Tasks dialog would contain an entry for an import plug-in, then context.log() would do the job.

    What I usually do is to create an XLog object while importing the file, and to throw this object into the resource pool if importing has failed for some reason. By looking at the thrown XLog, the user can get some idea what went wrong with the importing. As an example, you could take a look at the Ywl object in the YAWL package, which contains code to create such a log, and some log methods that you might want to copy.

    Cheers,

    Eric.
  • Hi Eric,

    Thank you. I found the example, and will log errors in an XLog object.

    Cheers,
    Wiebe

Sign In or Register to comment.