1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

behavior of LOG command

Discussion in 'T&T - Scripting' started by Frank, Jan 7, 2013.

  1. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    Today I played a little bit with LOG.
    I want to achieve that the output of my script is stored in a file without echoing + redirection.
    It seems that I can do it with "LOG /A".
    But I'm not sure if LOG is completely working correct.
    Here is an example (log-test.btm):
    Code:
    @echo off
    ver
    echo.
    log off
    log /e off
    log /a off
     
    log /w tcc.log
    echo hello world
    echoerr hello error
    do makes no sense
    log off
     
    log /a /w tcc_all.log
    echo hello world
    echoerr hello error
    do makes no sense
    log /a off
     
    log /e /w tcc_errors.log
    echo hello world
    echoerr hello error
    do makes no sense
    log /e off
     
    dir tcc*.log
     
    for %log in (tcc*.log) ( echo ^n%log -------------- %+ type /L %log )
     
    
    And this is the output:
    Code:
    (system)  C:\...\TCMD14x64 >log-test.btm
     
    TCC  14.03.52 x64   Windows 7 [Version 6.1.7601]
     
    Deleting C:\Program Files\JPSoft\TCMD14x64\tcc.log
    Deleting C:\Program Files\JPSoft\TCMD14x64\tcc_all.log
         2 files deleted
     
    hello world
    hello error
    C:\Program Files\JPSoft\TCMD14x64\log-test.btm [13]  Usage : DO [n | FOREVER]
    hello world
    hello error
    C:\Program Files\JPSoft\TCMD14x64\log-test.btm [19]  Usage : DO [n | FOREVER]
    hello world
    hello error
    C:\Program Files\JPSoft\TCMD14x64\log-test.btm [25]  Usage : DO [n | FOREVER]
     
     Volume in drive C is system         Serial number is 54b7:f82e
     Directory of  C:\Program Files\JPSoft\TCMD14x64\tcc*.log
     
    07.01.2013  19:26             225  tcc.log
    07.01.2013  19:26             105  tcc_all.log
                   330 bytes in 2 files and 0 dirs    8.192 bytes allocated
         3.499.761.664 bytes free
     
    tcc.log --------------
       1 : [07.01.13 19:26:58][4936] echo hello world
       2 : [07.01.13 19:26:58][4936] echoerr hello error
       3 : [07.01.13 19:26:58][4936] do makes no sense
       4 : [07.01.13 19:26:58][4936] log off
       5 : [07.01.13 19:26:58][4936] Usage : DO [n | FOREVER]
       6 :
     
    tcc_all.log --------------
       1 : hello world
       2 : hello error
       3 : C:\Program Files\JPSoft\TCMD14x64\log-test.btm [19]  Usage : DO [n | FOREVER]
    
    1. No error log is created. Why?
    2. In tcc.log: should it contain line 5 at all?
    3. In tcc_all.log: is it correct that /A doesn't include command logging?
      I would like this because that is what I need in this case ;-)
    Somehow the documentation is not totally clear (to me).
     
  2. forbin

    Joined:
    Dec 29, 2009
    Messages:
    18
    Likes Received:
    0
    Okay, so you've waited only a little less than 4 months for a response. But I thought this would be useful to others as well, so here it is. :)

    1. The error log (probably by design, though it escapes me why this is) only logs errors that could have been suppressed by an /e flag on the command.
    So, for example, del baz.quux will result in a logged error if there is no "baz.quux" present. But del /e baz.quux fails siliently (as expected) but also does not log an error (maybe unexpected).

    2. I conducted some tests and discovered an interesting side effect. (Put some DELAY commands between each batch of 3 test commands, and you will see what happens.) That line 5 error is not from the first run! It is from the third run when you were testing the log /e flag! Apparently, when error logging is turned on, syntax error messages (usage messages) go to the command log, not the error log. This might be a bug.

    3. Yes, the "all" log contains only output, not the commands, as described in the documentation.

    Also...

    The history log contains only the commands you've entered from the command line, not any commands executed from within a batch or alias.

    If you need a list of all commands executed both manually, and from within batches and aliases, without the timestamps (say, to build another batch file), you'll have to use TCC, or an editor, or SED, or another tool to strip off the timestamps.

    If you need a history of all commands and errors, you'll need to write a batch or program that merges the error log with the command log. That will be a little tricky because the entries in the error log come in pairs with a timestamp only on the first line of the pair.

    If you need a complete history of all commands (no matter where they came from), all output, and all errors, I think you are out of luck if you are looking for a single general-purpose solution. It doesn't exist. You can probably reconstruct such a log on an ad hoc basis, if you instrument your batch files and maybe force echoing ON permanently with SETDOS, and save the TCC linebuffer separately -- then merge all 4 logs together manually in an editor. I don't know why you'd want to do such a thing, unless it was for troubleshooting or auditing. Certainly not something you'd want to do frequently or on a continuing basis.
     

Share This Page