smartinspectpython.simemoryprotocol
Used for writing log data to memory and saving it to a stream or another protocol object on request. To initiate such a request, use the InternalDispatch method.
SITextProtocol is used for writing plain text log files. The SIMemoryProtocol class is used when the 'mem' protocol is specified in the SmartInspect.Connections. See the IsValidOption method for a list of available protocol options.
For a list of available protocol options, please refer to the IsValidOption method.
Threadsafety:
The public members of this class are thread-safe.
Overridden. Fills a SIConnectionsBuilder instance with the options currently used by this protocol.
Arguments:
- builder (SIConnectionsBuilder): The SIConnectionsBuilder object to fill with the current options of this protocol.
Overridden. Creates and initializes the packet queue.
This method creates and initializes a new packet queue with a maximum size as specified by the Initialize method. For other valid options which might affect the behavior of this method and protocol, please see the IsValidOption method.
Overridden. Clears the internal queue of packets.
This method does nothing more than to clear the internal queue of packets. After this method has been called, the InternalDispatch method writes an empty log unless new packets are queued in the meantime.
Overridden. Implements a custom action for saving the current queue of packets of this memory protocol to a stream or protocol object.
Arguments:
- command (SIProtocolCommand): The protocol command which is expected to provide the stream or protocol object.
Raises:
- Exception: Writing the internal queue of packets to the supplied stream or protocol failed.
Depending on the supplied command argument, this method does the following.
If the supplied State object of the protocol command is of type Stream, then this method uses this stream to write the entire content of the internal queue of packets. The necessary header is written first and then the actual packets are appended.
The header and packet output format can be influenced with the "astext" protocol option (see IsValidOption). If the "astext" option is true, the header is a UTF8 Byte Order Mark and the packets are written in plain text format. If the "astext" option is false, the header is the standard header for SmartInspect log files and the packets are written in the default binary mode. In the latter case, the resulting log files can be loaded by the SmartInspect Console.
If the supplied State object of the protocol command is of type Protocol instead, then this method uses this protocol object to call its WritePacket method for each packet in the internal packet queue.
The Action property of the command argument should currently always be set to 0. If the State object is not a stream or protocol command or if the command argument is null, then this method does nothing.
Overridden. Writes a packet to the packet queue.
Arguments:
- packet (SIPacket): The packet to write.
This method writes the supplied packet to the internal queue of packets. If the size of the queue exceeds the maximum size as specified by the Options property, the queue is automatically resized and older packets are discarded.
Overridden. Validates if a protocol option is supported.
Arguments:
- name (str): The option name to validate.
Returns:
True if the option is supported and false otherwise.
The following table lists all valid options, their default values and descriptions for the TEXT protocol.
Valid Options (default value) | Description |
---|---|
astext (false) | Specifies if logging data should be written as text instead of binary. |
indent (false) | Indicates if the logging output should automatically be indented like in the Console if 'astext' is set to true. |
maxsize (2048) | Specifies the maximum size of the packet queue of this protocol in kilobytes. Specify size units like this: "1 MB". Supported units are "KB", "MB" and "GB". |
pattern ("[%timestamp%] %level%: %title%") | Specifies the pattern used to create a text representation of a packet. |
If the "astext" option is used for creating a textual output instead of the default binary, the "pattern" string specifies the textual representation of a log packet. For detailed information of how a pattern string can look like, please have a look at the documentation of the PatternParser class, especially the PatternParser.Pattern property.
Please note that this protocol DOES NOT support log data encryption.
For further options which affect the behavior of this protocol, please have a look at the documentation of the SIProtocol.IsValidOption method of the parent class.
Sample Code
# package imports.
from smartinspectpython.siauto import *
# the following are sample SI Connections options for this protocol.
# log messages using all default options (binary log, no indent).
SIAuto.Si.Connections = "mem()"
# log messages using max packet queue size of 8 MB.
SIAuto.Si.Connections = "mem(maxsize=\"8MB\")"
# log messages using text instead of binary.
SIAuto.Si.Connections = "mem(astext=true)"
# log messages using indented text and a custom pattern.
SIAuto.Si.Connections = "mem(astext=true, indent=true, pattern=\"%level% [%timestamp%]: %title%\")"