Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
LogMsg in macros?
#1
Dean, can you log to the logfile in a macro? Mine are getting pretty complex, and I need to know what's going on in there, even when I'm not home.
Reply
#2
Just import the CQCLogger class and you are good to go. You could do like Wuench and create a logger class. I use this method as my logger for macros as needed. I inlcuded the literals I use for the token replacements.

Code:
//
//  LITERALS
//

Literals=

    // Logger
    Card4   kMsg0(0);
    Card4   kMsg1(1);
    Card4   kMsg2(2);
    Card4   kMsg3(3);

EndLiterals;

...

//
//  MSGLOGGER  
//

    Method MsgLogger
    (
        [In] Card4          MsgType
       ,[InOut] String      Msg
       ,[In] Formattable    Token1
       ,[In] Formattable    Token2
       ,[In] Formattable    Token3
    )
    Begin

    Locals=
        CQCLogger   Logger;
    EndLocals;  
    
        Try
            Switch(MsgType)
                Case kMsg1 :
                    Msg.ReplaceToken('1',Token1);
                    EndCase;
                Case kMsg2 :
                    Msg.ReplaceToken('1',Token1);
                    Msg.ReplaceToken('2',Token2);
                    EndCase;
                Case kMsg3 :
                    Msg.ReplaceToken('1',Token1);
                    Msg.ReplaceToken('2',Token2);
                    Msg.ReplaceToken('3',Token3);
                    EndCase;
                Default :
                    EndCase;
            EndSwitch;

            // Used for debugging
            #BeginDebug
            m_ConsOut.FmtStr(Msg);
            m_ConsOut.NewLn();
            m_ConsOut.Flush();
            #EndDebug

            Logger.LogMsg(Msg);

        EndTry;
        Catch
            Logger.LogMsg("Error writing to log: " + $Exception.GetErrorText());
        EndCatch;

    EndMethod;
...
..
Example
msg := "This is a message for %(1)";
MsgLogger(kMsg1,msg,Token1,"","");
It's the early bird that catches the worm, but it's the second mouse that gets the cheese...
Reply
#3
Great, thanks!
Reply
#4
Um...kinda unrelated to this, but...can you not define literals in a macro? I'd REALLY like to be able to, as it gives the thing some cleanliness and the ability to change things out a little easier.

I'm getting a compile error on the Literals tag.
Reply
#5
Shouldn't be a problem. What is the compile error you are getting?
It's the early bird that catches the worm, but it's the second mouse that gets the cheese...
Reply
#6
That probably means the blocks are out of order. It probably says it's expecting something else there, right?
Dean Roddey
Explorans limites defectum
Reply
#7
Ya, it said it was expecting "Method" or "Methods" or one of those.

I probably did put them in the wrong order. :roll: I'll check tonight. I'm glad they're allowed!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  CML Macros - Replacing Quotes gReatAutomation 2 264 02-13-2021, 11:59 AM
Last Post: Dean Roddey
  CML LogMsg zra 2 510 04-08-2020, 12:04 PM
Last Post: zra
  Calling global actions from macros dlmorgan999 1 1,445 07-12-2015, 08:07 AM
Last Post: Dean Roddey
  Macros won't load in editor - service restart required bbrendon 6 3,235 05-03-2014, 12:47 PM
Last Post: Dean Roddey
  CML/Driver - Async Macros bph 5 2,059 08-02-2008, 11:30 PM
Last Post: Dean Roddey
  2.4 Exception in Driver Harness When Loading Macros wuench 2 1,480 07-02-2008, 11:11 AM
Last Post: Dean Roddey
  CQCLogger vs Deprecated LogMsg methods of CQCDriverBase jrlewis 11 4,447 11-01-2007, 10:08 AM
Last Post: Dean Roddey
  Actions, Macros, and Parameters noworries 6 2,044 01-20-2007, 05:24 PM
Last Post: Dean Roddey

Forum Jump:


Users browsing this thread: 1 Guest(s)