global scoping

15 views
Skip to first unread message

Tony Zakula

unread,
Oct 12, 2010, 5:26:31 PM10/12/10
to mynajs-general
If you have the following in application.sjs

    onApplicationStart:function(){ // run if application cache has expired
      $application.set("appEngine",Myna.include($application.directory+"appEngine/appEngine.sjs",{}));
      $application.set("appLog",Myna.include($application.directory+"appEngine/appLogging.sjs",{}));
    },
    onRequestStart:function(){ // run directly before requested file
      var appEngine = $application.get("appEngine");
      var log = $application.get("appLog");
      $req.handled = appEngine.handleRequest();
    },

Should you be able to call log.mymethod() from inside an appEngine function?  I keep getting an undefined error.

Thanks,

Tony

Mark Porter

unread,
Oct 12, 2010, 8:29:05 PM10/12/10
to mynajs-...@googlegroups.com

The problem is using "var" inside of onRequestStart. That binds to the function scope. You want to either leave it un-var'd or explicitly bind it to the global scope: $server.globalScope.log = $application...

On an unrelated note, why are you not using Myna.log() for logging?

> --
> You received this message because you are subscribed to the Google Groups "MynaJS-General" group.
> To post to this group, send email to mynajs-...@googlegroups.com.
> To unsubscribe from this group, send email to mynajs-genera...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mynajs-general?hl=en.
>

Tony Zakula

unread,
Oct 12, 2010, 8:52:49 PM10/12/10
to mynajs-...@googlegroups.com
Ha,  Thanks.  I will get the hang of JavaScript pretty soon I promise!  :-)

I am using Myna.log inside of my logging function.  I basically wanted to wrap some functions around Myna logging to make it a little more like apache logger.  

For example, you can use if(log.isInfoEnabled()) log.log("myMessage");

Then inside of log.log, I am using Myna.Log.  

I have info, debug, none right now.  If you wrap your logging with those statements, then you can control the logging level app wide with a setting.  Just seems more efficient and makes for easier trouble shooting down the road.

Tony Z 
Reply all
Reply to author
Forward
0 new messages