Class Log

All Implemented Interfaces:
AutoCloseable

public class Log extends ChilkatObject
<section class="log-summary">

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 Details

    • Log

      public Log()
      Creates a new Log object.
  • Method Details

    • clear

      public void clear​(String initialTag)
      Clears all existing log entries and starts a new log whose top-level context is named initialTag.

      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 as LastErrorText.

      Parameters:
      initialTag - the initialTag argument (not null)
    • enterContext

      public void enterContext​(String tag)
      Begins a nested logging context named tag. Entries written after this call are grouped inside the new context until a matching LeaveContext is called.

      Balanced contexts: Pair each EnterContext with LeaveContext. Contexts may be nested to reflect operation hierarchy.

      Parameters:
      tag - the tag argument (not null)
    • 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

      public void logData​(String tag, String message)
      Adds a tagged text value to the current context. The output associates tag with message, 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 - the tag argument (not null)
      message - the message argument (not null)
    • logDataMax

      public void logDataMax​(String tag, String message, int maxNumChars)
      Adds a tagged text value to the current context, but limits the logged value to at most the first maxNumChars characters of message.

      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 - the tag argument (not null)
      message - the message argument (not null)
      maxNumChars - the maxNumChars argument
    • logDateTime

      public void logDateTime​(String tag, boolean gmt)
      Logs the current date and time under tag using an RFC 822-style date/time representation. If gmt is true, the logged time is GMT/UTC; otherwise local system time is used.

      Date/time vs. timestamp: Use LogDateTime for a calendar date with timezone context. Use LogTimestamp for a time-of-day marker.

      Parameters:
      tag - the tag argument (not null)
      gmt - the gmt argument
    • logError

      public void logError​(String message)
      Adds message as an error entry in the current logging context.

      Application diagnostics: This is application-defined logging. It is separate from LastErrorText produced by other Chilkat objects when their operations fail.

      Parameters:
      message - the message argument (not null)
    • logInfo

      public void logInfo​(String message)
      Adds message as an informational entry in the current logging context.

      Structured tracing: Use informational entries for significant steps and decisions. Use LogData when the entry is better represented as a named value.

      Parameters:
      message - the message argument (not null)
    • logInt

      public void logInt​(String tag, int value)
      Adds the integer value to the current log under tag.
      Parameters:
      tag - the tag argument (not null)
      value - the value argument
    • logInt64

      public void logInt64​(String tag, long value)
      Adds the signed 64-bit integer value to the current log under tag.

      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 - the tag argument (not null)
      value - the value argument
    • logTimestamp

      public void logTimestamp​(String tag)
      Logs the current time-of-day under tag in HH:MM:SS:mmm form, where mmm represents milliseconds.

      Timing note: This is a time-of-day marker, not a monotonic elapsed-time measurement.

      Parameters:
      tag - the tag argument (not null)