LOG_MESSAGE configurability for GM internal message output

kjoneskjones Global Mapper UserPosts: 5
edited June 2015 in GM Script Language
I have been successful using LOG_MESSAGE to add my debugging messages while a script is executing. What I would like to do is control logging of the messages that Global Mapper automatically generates when it runs commands. For example, on a script where I import, sort, export, and then unload cells, I get a message logged for all four activities. This makes for a large log file with a lot to parse when executing for hundreds/thousands of files. I would like to be able to turn on or off some of those messages and maybe even modify what the message actually says for the activities. Is there a current capability to configure LOG_MESSAGE to do this? Thank you.

Comments

  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,235
    edited June 2015
    Hello,

    I suggest starting with the SET_OPT command: specifically using the MISC_OPT called LOG_LEVEL

    MISC_OPT - specifies an advanced option to set the value of. There are a number of named options listed below. Use the MISC_OPT_VALUE parameter to set the value for the option.


    LOG_LEVEL - specifies what level of messages are logged to the log file. Values range from 0 for only critical errors to 4 to log everything, including debug messages. The default is 1 which logs errors and critical errors.


    LOG_FILENAME - specifies the name of the file to log errors and warnings to (based on LOG_LEVEL).
    MISC_OPT_VALUE - specifies the value to set for the MISC_OPT option. For most options this will be 1 to enable or 0 to disable, but some of the options for the GM_MiscOpt_t32 type can take other numbers (i.e. unit settings) or even a string value (i.e. filenames for timing or log filename).


    MISC_OPT_OLD_VALUE_VAR - specifies the name of a variable to store the previous MISC_OPT value in. This is useful to later restore a changed value in a script. See example below.


    Cheers,

    Bob
  • kjoneskjones Global Mapper User Posts: 5
    edited June 2015
    Hi Bob,Thank you for the suggestion. I implemented the SET_OPT command at the beginning of the script as such:
    SET_OPT MISC_OPT="LOG_LEVEL" MISC_OPT_VALUE="0" MISC_OPT_OLD_VALUE_VAR="PREV_LOG_LEVEL"

    I also set the value back at the end of the script:
    SET_OPT MISC_OPT="LOG_LEVEL" MISC_OPT_VALUE="%PREV_LOG_LEVEL%"

    I ran the script 5 times changing MISC_OPT_VALUE with values ranging from 0 to 4.

    In the resultant log files, I see the following output:
    at the beginning of the file
    "Changed MISC_OPT <LOG_LEVEL> value from 1 to <n>"

    at the end of the file
    "Changed MISC_OPT <LOG_LEVEL> value from <n> to 1"

    where n ranges from 0..4 depending on the run

    In my DIR_LOOP_START .. DIR_LOOP_END, I have no LOG_MESSAGE entries,
    but I see the following for all 5 log files
    " Starting loop over all files in directory..."

    (and for each file processed in the loop - which matches the actions occurring)

    "Importing file <..\..\resources\raytheon\dted1\testSubset\<fileN.dt1>...
    Importing OSM Tile data...
    Sorting map layers matching filename filter '*' with group filter of '*' in order LAYER_DESC_ASC
    Exporting elevation data to file <..\output\dted1\testSubset-logTest1\>...
    Removed all loaded overlays."


    ...

    " Loop over files in directory completed."

    Except for time stamps and log level values, the same entries are output in each file, regardless of log level number.Have I incorrectly implemented SET_OPT?

    Thank you,
    Kathy
  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,235
    edited June 2015
    Hi Kathy,

    There are actually two different log files. The one that you set up in your script, and another one that contains debug information, etc. that can be used for trouble-shooting Global Mapper. The SET_OPT value affects the second log file, and not the first, which is the one that you care about. Sorry for the confusion.

    Currently, there is no way to modify the contents of the script log file except for adding your own messages, which you are already doing.
    This makes for a large log file with a lot to parse when executing for hundreds/thousands of files.

    Does this mean that there is a lot of text to look at when you are trying to determine whether or not the script succeeded? If that is the case, Errors and warning messages will have a prefix of ERROR or WARNING, respectively, so you can search on those strings.

    Cheers,

    Bob
  • kjoneskjones Global Mapper User Posts: 5
    edited June 2015
    Good morning, Bob,
    Thank you for the update.

    "Does this mean that there is a lot of text to look at when you are trying to determine whether or not the script succeeded?"

    More so for when we are looking through the log to check out our comments added throughout the run.
    If we could turn off the five auto-generated comments and print out our own one line "processing cell XXX",
    for each item, it might be easier for us to spot something we might or might not be expecting.

    Thanks,
    Kathy


  • monagoosemonagoose Global Mapper User Posts: 7
    edited June 2015
    Hi Kathy,

    I find in my scripts that if you put a log message of ***** before and after a manually entered log can make it easier to scan through the log. Im not sure if this helps though..
  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,235
    edited June 2015
    Hello Kathy,

    I have added feature request #15940 to our task list so that we can evaluate implementation of message filtering in a script. One option is to add a FILENAME parameter to the LOG_MESSAGE command so that you can redirect your messages to a separate log file. Another is to add a category to messages (error, warning, info) and allow filtering by category. Would this be useful to you?

    Cheers,

    Bob
  • bmg_mikebmg_mike Global Mapper Guru Posts: 185Trusted User
    edited June 2015
    I've updated the SET_LOG_FILE script command to support adding a USER_FILENAME parameter specifying the filename for a file to write LOG_MESSAGE text to. If not provided then LOG_MESSAGE text will go to whatever filename automatically generated script messages go to.

    Now a script might look like:

    GLOBAL_MAPPER_SCRIPT VERSION="1.00"

    // Set a custom log file for LOG_MESSAGE
    SET_LOG_FILE USER_FILENAME="log_test.txt"
    LOG_MESSAGE 1st Message to write out

    // Restore the default shared log file
    SET_LOG_FILE USER_FILENAME=""
    LOG_MESSAGE 2nd Message to write out

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation
  • kjoneskjones Global Mapper User Posts: 5
    edited June 2015
    Thanks, Bob and Mike!
    Yes - that will helpful.
    Will Mike's update be in the next release?

    Thanks,
    Kathy
  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,235
    edited June 2015
    Hi Kathy,

    Yes, it will be in the next official release. In the meantime, you can get a daily build with the latest changes (including this one) at Global Mapper Downloads. Simply download the appropriate installer and run it to install the latest build.
    Cheers,

    Bob
Sign In or Register to comment.