Thanks Ernest,

No...no... no cloned Rete objects running amok here  :-D ... something much
simpler.  I was calling engine.reset() after having called
engine.store("logger", logger); way up further.  I caught it with this
simple experiment (excuse the ugly hardcoded paths):

-----------------------------------------------------------
package edu.pdx.etm.test;
import jess.*;
import org.apache.log4j.Logger;

public class TestLoggerFromScript {
    private Rete engine;
    private String cmd =
        "(batch \"C:/Program Files/Apache Group/Tomcat 4.1/webapps/emgt/WEB-
INF/classes/edu/pdx/etm/jess/testlog.clp\")";

    private Logger logger = Logger.getLogger(TestLoggerFromScript.class);

    public TestLoggerFromScript(){
        engine = new Rete();
    }

    public static void main(String[] args) {
        TestLoggerFromScript tlfs = new TestLoggerFromScript();
        tlfs.run();
    }

    public void run(){
        try{
            engine.executeCommand(cmd);
            engine.reset();
            engine.store("logger", this.logger);
            engine.run();

        }
        catch (JessException jex){
            jex.printStackTrace(System.err);
        }

    }
}
-------------------------------------------------
The script is a snippet of the aforementioned
three Jess scripts in my main project
-------------------------------------------------

(clear) ;BEGIN MAIN MODULE

(watch all)

(deftemplate MAIN::psu-class
        (slot id)
        (slot dept)
        (slot secMs)
        (slot secPhd)
        (slot suffix)
        (slot instructor)
        (slot title)
        (slot credits)
        (slot type)
        (slot active)
        (slot select)
        (slot quarter)
        (multislot qtrs)
        (multislot prereqs))

;; A few sample facts
(deffacts load-psu-class-factbase
  (MAIN::psu-class (id 1)
  (dept "ACTG")
  (secMs 511)  (secPhd 611)  (suffix nil)
  (instructor "staff")  (title "Financial Accounting")  (credits 4)
  (type "core2")  (active FALSE)  (select FALSE)
  (quarter nil)  (qtrs 0)  (prereqs nil))

  (MAIN::psu-class (id 2)
  (dept "EMGT")
  (secMs 503)  (secPhd 603)  (suffix nil)
  (instructor "Staff")  (title "Thesis")  (credits 8)
  (type "cap")  (active FALSE)  (select FALSE)
  (quarter nil)  (qtrs 30)  (prereqs nil))

  (MAIN::psu-class (id 3)
  (dept "EMGT")
  (secMs 506)  (secPhd 606)  (suffix nil)
  (instructor "Staff")  (title "Special Projects")  (credits 4)
  (type "cap")  (active FALSE)  (select FALSE)
  (quarter nil)  (qtrs 30)  (prereqs nil)))

;; Logging function wraps reference to logger object
(deffunction MAIN::log-info (?message)
  (printout t "MAIN::log-info called..." crlf)
  (bind ?logger (fetch logger))
  (printout t "logger = " ?logger crlf)
  (if (not (eq ?logger nil)) then
  (call ?logger info (str-cat "jess: " ?message))))

;; Just a cheesy test rule...
(defrule MAIN::is-EMGT-503
  (MAIN::psu-class (dept "EMGT") (secMs 503) (secPhd 603))
=>
 (MAIN::log-info "EMGT 503 found in course database."))

-----------------------------------------------------------------------
Which after ...

FIRE 1 MAIN::is-EMGT-503 f-2
MAIN::log-info called...
logger = <External-Address:org.apache.log4j.Logger>
 INFO [main] (?:?) - jess: EMGT 503 found in course database.
 <== Focus MAIN

... produces the beautiful (to me anyway!) output in the log file...

15:22:26,343 INFO        main    NativeMethodAccessorImpl     ? : jess: EMGT 503
found in course database.
-----------------------------------------------------------------------

All in all, I think that this technique is an elegant way to log messages
out of Jess in webapps.  You can really see what the RHS of rules are doing
and whether the logic is working.  Thoughts?
-JM
------------------------

Jason Morris
Morris Technical Solutions
[EMAIL PROTECTED]
www.morristechnicalsolutions.com
fax/phone: 503.692.1088



> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Behalf Of [EMAIL PROTECTED]
> Sent: Tuesday, June 01, 2004 1:15 PM
> To: [EMAIL PROTECTED]
> Subject: Re: JESS: Logging from Jess
>
>
> I think Jason Morris wrote:
> >
> > (deffunction MAIN::log-info (?message)
> >   (bind ?logger (fetch logger))
> >   (if (not (eq ?logger nil)) then
> >   (call ?logger info (str-cat "jess: " ?message))))
> >
>
> This actually should work perfectly. In combination with your other
> message, though, where you mention constructing a Rete object with a
> Defclassed object (or its Class object?) as an argument, I wonder if
> the problem is that you're inadvertently creating multiple Rete
> objects, and then storing the logger in one, while this code is
> running in another.
>
> It's fine to create multiple Rete objects, but each one is
> independent, and you should only create them if you specifically
> intend to use them separately (i.e., for example, you might register
> the logger with every one of them.)
>
> ---------------------------------------------------------
> Ernest Friedman-Hill
> Science and Engineering PSEs        Phone: (925) 294-2154
> Sandia National Labs                FAX:   (925) 294-2234
> PO Box 969, MS 9012                 [EMAIL PROTECTED]
> Livermore, CA 94550         http://herzberg.ca.sandia.gov
>
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
> in the BODY of a message to [EMAIL PROTECTED], NOT to the list
> (use your own address!) List problems? Notify [EMAIL PROTECTED]
> --------------------------------------------------------------------
>

--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------

Reply via email to