RobotLegs should support logging

borekb's Avatar


15 Jul, 2010 01:14 PM

It would be useful if some kind of logging could be enabled for RL without manually subscribing to various events.

  1. Support Staff 1 Posted by Shaun Smith on 15 Jul, 2010 01:34 PM

    Shaun Smith's Avatar

    Internal logging was removed from Robotlegs v0.9 due to size and performance issues (we wanted it to be as small and fast as possible, with minimal external dependencies). What kind of things would you like to see logged?

  2. 2 Posted by Stray on 15 Jul, 2010 01:39 PM

    Stray's Avatar

    Hi Borek,

    There isn't one that I know of, but it's not going to be hard for you to implement using the src package.

    The base/mvcs package classes are a concrete implementation of robotlegs - like trousers that the robotlegs wear. Don't feel too afraid of poking around in them, they're pretty easy to follow.

    If you wanted to log all events then I'd recommend adding this to the EventMap/CommandMap classes in the base package. Initially you could just hack it directly in there - essentially you'd just be adding to the callback function with some sort of logging action - whether that's just triggering an additional LogEvent on that map (be careful of infinite recursion possibilities there) or maybe doing something clever with signals (seems like a good use case for that).

    Once you've got it working how you'd like it to, you can break this out into utility classes instead:




    for example.

    In the mvcs package, you'll see that Mediator creates its own event map, and Context creates a command map.

    Simple extend those: LoggingMediator and LoggingContext so that they also contain / provide a loggingEventMap / loggingCommandMap

    When you're done, post your code on github and it can be a useful utility (usually requires unit tests along side code to allow others to refactor / extend).

    Personally I think actual logging of all events is overkill but I'm building big apps - so I have a LogEvent wrapper that logs the event and then fires the event itself. When I just need to follow what's going on I just hack traces into the EventMap / CommandMap. This is more useful than tracing in the constructor of the event itself because when robotlegs clones the events the multiple traces can be hard to follow.

  3. 3 Posted by borekb on 15 Jul, 2010 01:52 PM

    borekb's Avatar

    Shaun, I'm starting with RL so I'd sometimes appreciate insight into the general flow of my program.

    Stray, thanks for the tips. I'll keep them in mind for the future.

  4. Support Staff 4 Posted by Shaun Smith on 15 Jul, 2010 01:57 PM

    Shaun Smith's Avatar

    Perhaps we could think about using conditional compilation to include logging for "debug" builds.

  5. 5 Posted by borekb on 15 Jul, 2010 02:02 PM

    borekb's Avatar

    That would be great!

  6. 6 Posted by Stray on 15 Jul, 2010 02:16 PM

    Stray's Avatar

    That's a really nice idea.

    I've always found that conditional compilation throws a wobbly if I don't include the variable in my compiler vars, so would this require an extra compiler var whether you're using it or not?

    What do people want the mechanism to be? I'm guessing plain events... how did you do it before? (I can go back through the archives to 0.9 I guess).

  7. Support Staff 7 Posted by Shaun Smith on 15 Jul, 2010 02:22 PM

    Shaun Smith's Avatar

    Oh no, I'd don't like the sound of wobblies! To be honest, I haven't played with conditional compilation in AS3 yet, so will have to see how that pans out.

    We used to do the logging through the as3commons logger:

  8. 8 Posted by Aaron Hardy on 15 Jul, 2010 02:51 PM

    Aaron Hardy's Avatar

    I think this is great use for conditional compilation and I'd definitely support this feature (though not a big priority). For those who directly use the swc it shouldn't throw wobblies. For those who use the source code, I don't think it'll be too big of a challenge. Conditional compilation is becoming more mainstream and more and more developers have run into the wobbly and are comfortable with it. For example, TLF uses multiple conditionals ("debug" and "release")--not saying we should use TLF as our model.

  9. 9 Posted by mike.cann on 15 Jul, 2010 06:24 PM

    mike.cann's Avatar

    I have been playing with conditional compilation the last couple of days actually.

    It works great however the IDE has a big part in making it easy to use. For example we use Flash Builder at work and you can easily add additional command line params in your project properties. The problem is when you want to do a release build you have to remember to disable your "debug" command line as there is no separate setting for release mode command line args.

    Also conditional name spaces arent picked up by the type hinting. So type "CONFIG::" then cmd + space and you get nothing.

    This is all just fluff tho and if you use another IDE such as Flash Develop there are plugins to assist you.

  10. 10 Posted by Stray on 15 Jul, 2010 06:33 PM

    Stray's Avatar

    It's easy in project sprouts ;)

    The only reservation I have is that you can't set this in the swc (as you wouldn't be able to switch it back and forth), so it would mean people having to add another command line param (as far as I'm concerned nothing is easy in Flash Builder!).

    The Flash IDE allows conditional compiling params, so that's not a problem - existing workarounds would continue to work.

    It's just *another* step in getting going with RL though. If you have CONFIG::UseLogging or whatever, it's not possible to get going without this variable set.

    So - the balance is whether the extra step to get going at all is worth it for an extra feature once you do get going... or whether this should be outside of the basic set up, but easy to implement with a how-to or even a utility?

  11. 11 Posted by Aaron Hardy on 15 Jul, 2010 07:31 PM

    Aaron Hardy's Avatar

    Stray, if I understand your statement, I don't think it's accurate. You set the conditional compilation argument on the library project and the swc gets compiled with that conditional compilation. Once the swc is built, the app that uses the swc need not define the argument. At that point, the conditional argument can't be switched back and forth.

    In other words, we'd leave the debug argument to false for the swc and it would require no configuration on the part of the developer using the swc. If they want to enable debugging, they'd check out the source and switch the argument value on the RL library.

  12. 12 Posted by Aaron Hardy on 15 Jul, 2010 07:35 PM

    Aaron Hardy's Avatar

    I might clarify that, yes, that would be an extra step for anyone wanting to use the RL source (not swc).

  13. 13 Posted by mike.cann on 15 Jul, 2010 07:36 PM

    mike.cann's Avatar

    Or have two SWCs one with debug in one without...

  14. 14 Posted by Stray on 15 Jul, 2010 07:42 PM

    Stray's Avatar

    Hi Aaron - that's exactly what I was saying. (Or intending to).

    The swc argument is fixed. So - if you want to use logging you'd have to use source and set the CONFIG parameter yourself in the compiler vars.

    So - unlike the usefulness of putting the keep_as3_metadata config params in the swc - because they never change - you'd be stuck with an argument which might not meet your requirements.

    On the other hand, if we don't include it in the swc then you can't compile at all until you've set it one way or the other (that's my experience of forgetting to set a compiler var anyway).

    Not sure where I was unclear but obviously I was.

    My thought is that if it's not going to work out-of-the-box then it's as well being a utility perhaps?

  15. 15 Posted by Stray on 15 Jul, 2010 07:44 PM

    Stray's Avatar

    What do people feel about that?

    On instinct I don't like having 2 libraries with the same code / name etc, 2 assets to keep track of etc, but then I don't use swc unless there's no src available.

    So - swc lovers, is having 2 swc files ok?

  16. 16 Posted by Aaron Hardy on 15 Jul, 2010 07:50 PM

    Aaron Hardy's Avatar

    Sorry about that then. We're on the same page.

    Personally I'm not keen on the idea of two swcs. I'd be up for having a conditional arg on the library that's default debug=false and if people want to use debug they check out the code and set the arg to true. Or, if all the necessary hooks are available, I think a debug add-on is probably the best option.

  17. 17 Posted by borekb on 16 Jul, 2010 09:36 AM

    borekb's Avatar

    Before we focus on conditional compilation too much, is really having a couple of method calls causing performance issues? It may be slow to log to some targets like file system log files but having these method calls in the source code and not using them in production can't harm performance too much can it?

  18. Support Staff 18 Posted by Shaun Smith on 16 Jul, 2010 02:15 PM

    Shaun Smith's Avatar

    It's not just a matter of speed - filesize and external dependencies play a part too.

  19. 19 Posted by borekb on 19 Jul, 2010 07:07 AM

    borekb's Avatar

    Logging API is part of the Flex framework and would require no external dependencies (I understand that there could have been issues with some 3rd party logging library but I don't see many reasons to avoid native Flex logging in this case).

  20. 20 Posted by Tim Oxley on 19 Jul, 2010 07:22 AM

    Tim Oxley's Avatar

    No external dependencies other than the Flex framework. Robotlegs isn't
    dependent on Flex.

  21. 21 Posted by borekb on 19 Jul, 2010 07:29 AM

    borekb's Avatar

    True, I forgot about that... It would be a big dependency then :)

  22. Stray closed this discussion on 18 Feb, 2011 07:05 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac