Macro Language Reference > Macros > Debug > logopen
  
logopen
Description
Opens a new log to a specified location, ready to receive data. If the log is already open, it will be closed first before reopening it to the new location. Any existing content in the log will be deleted
 
Example 40. Log messages and display log content to the windows system
This example, using inline PIs, will write the words `hello' and 'world" to the log number 7 (LOG7), then display the content of LOG7 to a windows system pop up box:
The quick <?logwrite LOG7 hello> brown fox <?logwrite LOG7
world> jumps over a <?logopen LOG7 SYSTEM> lazy dog.
Putting an <?logclose> at the end of the line would close the log, thus preventing any more writing to it.
Syntax
logopen logspec:n path:s?
logspec
The log number: There are 10 logs that can be used.
LOG0
Log number 0 (Alias of BFOUT (0))
LOG1
Log number 1 (Alias of BFERR (1))
LOG2
Log number 2 (Alias of BFDBG (2))
LOG3
Log number 3 (Alias of BFODS (3))
LOG4
Log number 4 (Alias of BFLOG (4))
LOG5
User Log number 5
LOG6
User Log number 6
LOG7
User Log number 7
LOG8
User Log number 8
LOG9
User Log number 9
SYSTEM
Write the contents of log to a predetermined SYSTEM pop up box.
ODS
Use Windows specific Output Display System messages.
path
The path or location of the log
Feature Summary
This set of commands is typically used to trace what’s happening in a template; a developer would subsequently use tools such as boxit for writing scripts, setting temporary variables or writing messages to a stream. Each of these has its own method, but they all require either writing and removing the debug code or tests for whether in debug mode each time a message was required. The log system allows a consistent method for logging events and passing messages to locations, which can be turned on or off with a simple macro call which also tells PTC ALD where to write the message.
Log Locations
There are five possible places to which logs can be written:
File
Stream
Variable
SYSTEM
ODS (output delivery system)
By default, the logopen command takes a filename as a parameter. This can be any standard PTC ALD path, including any special areas as required. In addition to this, it is possible to create a log with a destination of a stream or Perl channel using the standard {0}, {1} or {2} style prefixes, or to a variable where the name is prefixed with a ^ character. Note that the stream locations will not be available if no document is open in PTC ALD . If multiple documents are open, the stream will be created in whichever document is currently active.
Specifying the SYSTEM and ODS log locations will write the log messages to pre-determined locations. These are keywords that should be passed to the logopen command instead of a file or stream name. On Windows, SYSTEM will output to a Windows Message Box, whereas on Linux or Unix it will output to stdout. The ODS location is a Windows specific location that writes the message to the Windows System Debugger. It is not used on Linux or Unix.
Filenames, stream names or variables should be enclosed in quotes, the SYSTEM and ODS keywords should not. Examples of how to use these locations are provided in section 3.4, below.
There are 10 logs available for use: five are pre-opened by PTC ALD and default to system log locations, the remaining five are left unopened for use in templates. Note that PTC ALD may write system error messages (e.g. pointer errors) to the BFERR (LOG1). Whilst it is possible to redirect BFERR to a stream or variable, or write to it, either of these could cause cause system instability in the event of an error and are not recommended. Also note that the logs are global to PTC ALD and are not document specific, so it is possible to have multiple documents trying to access the same log locations at the same time.
Log No. Alias
Default Log Location
0
BFOUT LOG0 SYSTEM
1
BFERR LOG1 {@}serrlog.3at
2
BFDBG LOG2 debug file, or BFERR if no debug file specified.
3
BFODS LOG3 ODS
4
BFLOG LOG4 None
5
LOG5 None
6
LOG6 None
7
LOG7 None
8
LOG8 None
9
LOG9 None
Sample macros
 
The log parameter can either be the number of the log or the log alias.
logopen LOG5 "{@}log.txt" : open up log 5, ready for writing to log.txt in the PTC ALD program directory.
logopen BFLOG "^test": open up log 4 and write any log messages into the PTC ALD system variable ^test.
logopen BFDBG "{0}debug_strm" : open up log 2 and write any messages to the PTC ALD stream debug_strm.
logopen LOG7 SYSTEM : open log 7 and display any log messages in a Windows Message Box (or stdout on the Unix version of PTC ALD ).
Sample Use Case
This use case describes a slightly more complex usage than might be typical, but is useful because it demonstrates the benefits of using the LogWriter over traditional methods.
A user requires log information showing the current progress in the formatting operation, any errors or warnings that may occur and (optionally) any extra state information to assist with the debugging of the template.
User creates log #1 to point to a stream, which will contain the current state of the formatting process. This log is activated as the first step of the format.
User creates log #2 to point to a file, which will contain the contents of significant variables at the start of each page to assist debugging the template. This log is not activated.
When the format is finished, the stream containing log #1 can be displayed in a dialog box to the user.
During testing, the user can issue a macro to turn on log #2 before starting the format operation and inspect the resulting file to see if it worked correctly.
* 
Take care when opening a log pointing to a stream then switching documents and trying to write to the log again: the handle no longer exists. In this instance it is usual to experience an application crash.
Additional Information
The logopen macro is identical in function to its processing instruction equivalent. Its purpose is to allow logs to be controlled through a script instead of within a formatting operation. The use of the macro is completely interchangeable with the PI so, for example, it is possible to open a log using the <?logopen> PI, and write to it via the logopen macro detailed here.
Related Links