commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nestor Urquiza <nest...@yahoo.com>
Subject Re: [SCXML] enabling/disabling logging for var assignments
Date Thu, 16 Nov 2006 21:39:08 GMT
Since it took me a while to learn about the
commons-logging wrapper and current log engines I will
post here my results just in case someone has a
similar problem in the future:

problem:
-------
You are using SCXML which in turns uses
commons-logging but your code cannot use
commons-logging.

solution:
--------
You need to initialize one of the supported by
commons-logging engines like Log4J.

implementation:
----------------
I did not want to include a new resource into my
project (you can use properties file or xml file for
Log4J configuration), so I opted to configure
programmatically:

<code>
                logger =
LogManager.exists("scxml.app.log");
                if (logger == null)
                {
                    Logger logger =
Logger.getLogger("scxml.app.log");

                    // Prepare log engine for
commons-scxml
                    // We need to provide
commons-scxml package with a standard
		    //By default do not log anything that uses
commons-logging
                    Logger rootLogger =
Logger.getRootLogger();
                    SimpleLayout rootLayout = new
SimpleLayout();
                    Appender rootAppender = new
ConsoleAppender();
                   
rootLogger.addAppender(rootAppender);
                    rootLogger.setLevel(Level.OFF);

		    //Specific layout pattern for custom application
                    String pattern = "%d{yyyy/MM/dd
HH:mm:ss.SSS} @ "
                            + Constants.LOG_HINT + " @
SCXML Engine @ %m%n";
                    PatternLayout layout = new
PatternLayout(pattern);
                    boolean append = true;
                    boolean bufferedIO = false;
                    int bufferSize = 10;
                    String filename =
"completePathOfYourFileNameAddingTimestampToNameForExample.log";
                    if
(logger.getAppender("scxml.app.appdr") == null)
                    {
                        // WriterAppender appdr =
null;
                        FileAppender appdr = null;

                        try
                        {
                            appdr = new
FileAppender(layout, filename, append,
                                    bufferedIO,
bufferSize);
                           
appdr.setImmediateFlush(true);
                           
appdr.setName("scxml.app.appdr");
                        }
                        catch (IOException e)
                        {
                            //deal with it.
                        }
                        logger.addAppender(appdr);
                        logger.setLevel(Level.INFO);
                        logger.setAdditivity(false);
                    }
                }
</code>

With the code above I was able to obtain then the
infor messages from Var and Assign needed to debug my
project (Using last version of commons-logging -1.1-
and Log4J -1.2.14- the TRACE comes up like a DEBUG
message so I decided to use INFO intead):

For Var:
<code>
String msg = "Var." + name + "=" + varStr;
        if( appLog.isInfoEnabled() )
           appLog.info( msg );
</code>

still some problems:
-------------------
If I log into the same file as my main System layer I
get some flushing problems resulting in trace lines
that are not in the output. There are several posts
related to this issue but I simply could not get rid
of the problem so I decided to log in a separate file.

questions/ideas:
---------------
Wouldn't be better to include in both the tracert that
implements SCXMLListener and the SCXMLListener itself
a notification mechanism? We already have
SCXMLListener#warning(), what about having
SCXMLListener#trace()? That way we could trace what is
happenning with most of the classes member of
org.apache.commons.scxml.model which means we are able
to track down what is happenning with the data model
part.

Maybe PathResolverHolder is the place to specify a
method trace() that could be generically implemented
by an abstract class from where finally the data model
bits would inherit. maybe the best way is just to
separately define the trace() method for those bits we
are interested in.

Bottom line the idea of having a trace of what is
going on and my failure to make the whole system log
into a unique file made me think about this
alternative which maybe is even better than just
logging.

Thanks,

-Nestor

--- Rahul Akolkar <rahul.akolkar@gmail.com> wrote:

> On 11/12/06, Nestor Urquiza <nestoru@yahoo.com>
> wrote:
> > Hi Rahul,
> > Sorry to come back that late. My code is again
> working
> > so I could follow step by step thru the code in
> the
> > SVN and finally I could follow your suggestions,
> so in
> > Var#execute() and Assign#execute()after:
> > ctx.setLocal(name, varObj);
> >
> > I added:
> > String varStr =
> varObj==null?"null":varObj.toString();
> > appLog.trace( "Var." + name + "=" + varStr );
> >
> > The question I have now is about how to configure
> > logging in SCXML. Is it done using a property
> file?
> > Just a constant? Of course I could dig into the
> code
> > but I guess I'll find out faster with some of your
> > help.
> >
> <snip/>
> 
> Commons SCXML uses Commons Logging so the best place
> to start is the
> Commons Logging 1.0.4 user guide [1], if you haven't
> looked at it
> before.
> 
> The default logical name for 'appLog' is the
> arbitrarily chosen 'scxml.app.log'.
> 
> -Rahul
> 
> [1]
>
http://jakarta.apache.org/commons/logging/commons-logging-1.0.4/docs/guide.html
> 
> 
> > Thanks,
> >
> > -Nestor
> >
> >
> >
> >
> >
> >
> > --- Rahul Akolkar <rahul.akolkar@gmail.com> wrote:
> >
> > > On 11/1/06, Nestor Urquiza <nestoru@yahoo.com>
> > > wrote:
> > > > Hi guys,
> > > >
> > > > I am using a custom log library for my Bridge
> and
> > > > System layers.
> > > >
> > > > When I want to log transitions and
> onentry/onexit
> > > > events I can do it thru the SCXMLListener
> > > > implementation.
> > > >
> > > > However for var assignments and evaluations I
> > > would
> > > > like to know the easier way to log them.
> > > >
> > > > Right now with more than 2000 lines of scxml I
> > > really
> > > > need to trace every single assignment within
> the
> > > code.
> > > >
> > > > Also does anyone know about a plan to build an
> > > SCXML
> > > > debugger? Now that I have all the Controller
> logic
> > > > written in SCXML I really need that and before
> > > > writting any code I would like to hear some
> > > advice.
> > > >
> > > <snip/>
> > >
> > > The easiest way would be to add logging
> statements
> > > in
> > >
> > > org.apache.commons.scxml.model.Var#execute(...)
> > >
> > > and
> > >
> > >
> org.apache.commons.scxml.model.Assign#execute(...)
> > >
> > > right at the point where any Context operation
> --
> > > such as
> > > Context#set(...) -- is called. That way, it
> could
> > > simply be turned
> > > on/off with the JCL configuration. Should be
> useful
> > > as long as the log
> > > level is correct (probably, trace would be
> > > appropriate).
> > >
> > > If you do this for yourself, can you please
> submit a
> > > patch (svn diff)?
> > >
> > > -Rahul
> > >
> > >
> > > > Thanks,
> > > >
> > > > -Nestor
> > > >
> > > >
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> commons-user-help@jakarta.apache.org
> 
> 



 
____________________________________________________________________________________
Sponsored Link

Online degrees - find the right program to advance your career.
Www.nextag.com

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message