Class Log
- All Implemented Interfaces:
AutoCloseable
Build readable structured diagnostic logs with nested context and tagged values.
Chilkat.Log is a lightweight structured logging helper for
creating readable diagnostic logs from application code. It can record nested
operation contexts, informational messages, error messages, timestamps,
integers, 64-bit integers, tagged values, binary data, Base64 data, hex data,
shortened data previews, and computed hashes. It is useful when code needs a
clear step-by-step record of operations, inputs, outputs, and diagnostic
values for troubleshooting.
Nested operation context
Use EnterContext and LeaveContext to group log
entries under readable operation names.
Messages and errors
Add informational messages, error messages, and tagged text values to explain what the application is doing.
Numbers and timestamps
Log integers, 64-bit integers, timestamps, and date/time values when tracing state changes or timing-sensitive workflows.
Binary diagnostics
Record binary data as Base64, hex, or shortened previews so byte-level values can be inspected safely in text logs.
Hash logging
Compute and log hashes of data when comparing content, verifying transformations, or avoiding full data dumps.
Clear and reuse
Clear the log and continue building new diagnostic output during repeated operations or test runs.
Common pattern:
Create a Log object, enter a named context for the operation,
log the important values and decisions as the code runs, leave the context,
and inspect the resulting text if troubleshooting is needed. Use
Chilkat.Log for application-level diagnostic output; use
LastErrorText on Chilkat objects for detailed diagnostics from
Chilkat method calls.
For an extended overview, see Log Class Overview.
</section>
Instances hold a native Chilkat object: close them with ChilkatObject.close() (try-with-resources) when
done; an unclosed instance is freed when it becomes unreachable.
- See Also:
- Online reference
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidClears all existing log entries and starts a new log whose top-level context is namedinitialTag.voidenterContext(String tag)Begins a nested logging context namedtag.voidEnds the current nested logging context and returns logging to its parent context.voidAdds a tagged text value to the current context.voidlogDataMax(String tag, String message, int maxNumChars)Adds a tagged text value to the current context, but limits the logged value to at most the firstmaxNumCharscharacters ofmessage.voidlogDateTime(String tag, boolean gmt)Logs the current date and time undertagusing an RFC 822-style date/time representation.voidAddsmessageas an error entry in the current logging context.voidAddsmessageas an informational entry in the current logging context.voidAdds the integervalueto the current log undertag.voidAdds the signed 64-bit integervalueto the current log undertag.voidlogTimestamp(String tag)Logs the current time-of-day undertaginHH:MM:SS:mmmform, wheremmmrepresents milliseconds.Methods inherited from class com.chilkatsoft.chilkat2.ChilkatObject
close, getDebugLogFilePath, getLastErrorHtml, getLastErrorText, getLastErrorXml, getLastMethodSuccess, getVerboseLogging, getVersion, isClosed, setDebugLogFilePath, setLastMethodSuccess, setVerboseLogging, toString
-
Constructor Details
-
Log
public Log()Creates a newLogobject.
-
-
Method Details
-
clear
Clears all existing log entries and starts a new log whose top-level context is namedinitialTag.Typical use: Call this at the beginning of an operation or test run, then add entries with the other
Log*methods. The completed structured log can be inspected through the Log object's diagnostic text, such asLastErrorText.- Parameters:
initialTag- theinitialTagargument (notnull)
-
enterContext
Begins a nested logging context namedtag. Entries written after this call are grouped inside the new context until a matchingLeaveContextis called.Balanced contexts: Pair each
EnterContextwithLeaveContext. Contexts may be nested to reflect operation hierarchy.- Parameters:
tag- thetagargument (notnull)
-
leaveContext
public void leaveContext()Ends the current nested logging context and returns logging to its parent context.Empty contexts are omitted: If nothing was logged after entering the current context, Chilkat automatically removes that empty context when it is left.
-
logData
Adds a tagged text value to the current context. The output associatestagwithmessage, making this useful for named values such as filenames, paths, IDs, states, or protocol fields.Sensitive data: Avoid logging passwords, private keys, access tokens, session secrets, or other sensitive values unless disclosure is intentional.
- Parameters:
tag- thetagargument (notnull)message- themessageargument (notnull)
-
logDataMax
Adds a tagged text value to the current context, but limits the logged value to at most the firstmaxNumCharscharacters ofmessage.Diagnostic previews: Use this when a value may be very large and only a leading preview is needed. The original input string is not modified.
- Parameters:
tag- thetagargument (notnull)message- themessageargument (notnull)maxNumChars- themaxNumCharsargument
-
logDateTime
Logs the current date and time undertagusing an RFC 822-style date/time representation. Ifgmtistrue, the logged time is GMT/UTC; otherwise local system time is used.Date/time vs. timestamp: Use
LogDateTimefor a calendar date with timezone context. UseLogTimestampfor a time-of-day marker.- Parameters:
tag- thetagargument (notnull)gmt- thegmtargument
-
logError
Addsmessageas an error entry in the current logging context.Application diagnostics: This is application-defined logging. It is separate from
LastErrorTextproduced by other Chilkat objects when their operations fail.- Parameters:
message- themessageargument (notnull)
-
logInfo
Addsmessageas an informational entry in the current logging context.Structured tracing: Use informational entries for significant steps and decisions. Use
LogDatawhen the entry is better represented as a named value.- Parameters:
message- themessageargument (notnull)
-
logInt
Adds the integervalueto the current log undertag.- Parameters:
tag- thetagargument (notnull)value- thevalueargument
-
logInt64
Adds the signed 64-bit integervalueto the current log undertag.64-bit values: Useful for values such as large byte counts, file sizes, sequence numbers, or timestamps that can exceed ordinary integer ranges.
- Parameters:
tag- thetagargument (notnull)value- thevalueargument
-
logTimestamp
Logs the current time-of-day undertaginHH:MM:SS:mmmform, wheremmmrepresents milliseconds.Timing note: This is a time-of-day marker, not a monotonic elapsed-time measurement.
- Parameters:
tag- thetagargument (notnull)
-