8.18.1.56. Log capture

ImGui’s logging API captures the rendered text of every widget submitted inside a log scope to a target (TTY, file, clipboard, or an in-memory buffer). Dear ImGui 1.92 renamed the target enum from ImGuiLogType to ImGuiLogFlags and gave the values an Output prefix (OutputTTY / OutputFile / OutputClipboard / OutputBuffer). The boost with_log wrapper takes the renamed enum:

with_log(ImGuiLogFlags.OutputClipboard, -1) {
    text("=== Daslang Widget Report ===")
    text("Section: Fruits")
    LogRenderedText("(this line is captured but never drawn)")
}
let captured = GetClipboardText()

The second argument is the tree depth to auto-expand (-1 = default). LogBegin asserts that logging is not already active, so with_log must not nest.

Source: modules/dasImgui/examples/tutorial/log_capture.das.

8.18.1.56.1. Walkthrough

  1options gen2
  2options _comment_hygiene = true
  3
  4require imgui
  5require imgui_app
  6require opengl/opengl_boost
  7require live/glfw_live
  8require live/live_api
  9require live/live_commands
 10require live/live_vars
 11require live_host
 12require imgui/imgui_live
 13require imgui/imgui_boost_runtime
 14require imgui/imgui_boost_v2
 15require imgui/imgui_widgets_builtin
 16require imgui/imgui_containers_builtin
 17require imgui/imgui_scope_builtin
 18require imgui/imgui_visual_aids
 19
 20// =============================================================================
 21// TUTORIAL: log_capture — capture rendered widget text with with_log.
 22//
 23// 1.92 renamed the log-target enum: ImGuiLogType -> ImGuiLogFlags, and the
 24// values gained an Output prefix (TTY -> OutputTTY, Clipboard -> OutputClipboard,
 25// File -> OutputFile, Buffer -> OutputBuffer). The boost with_log wrapper now
 26// takes an ImGuiLogFlags:
 27//
 28//   with_log(ImGuiLogFlags.OutputClipboard, -1) {
 29//       text("captured")            // every widget's rendered text is logged
 30//   }
 31//
 32// LogBegin asserts logging is not already active, so with_log must NOT nest.
 33//
 34// STANDALONE: daslang.exe modules/dasImgui/examples/tutorial/log_capture.das
 35// LIVE:       daslang-live modules/dasImgui/examples/tutorial/log_capture.das
 36// =============================================================================
 37
 38var private g_capture_count = 0
 39var private g_last_clip = ""
 40var private g_capture_requested = false
 41
 42[export]
 43def init() {
 44    live_create_window("dasImgui log_capture tutorial", 820, 600)
 45    live_imgui_init(live_window)
 46    let io & = unsafe(GetIO())
 47    GetStyle().FontScaleMain = 1.3
 48}
 49
 50[export]
 51def update() {
 52    if (!live_begin_frame()) return
 53    begin_frame()
 54
 55    ImGui_ImplGlfw_NewFrame()
 56    apply_synth_io_override()
 57    NewFrame()
 58
 59    SetNextWindowPos(ImVec2(40.0f, 40.0f), ImGuiCond.Always)
 60    SetNextWindowSize(ImVec2(740.0f, 520.0f), ImGuiCond.Always)
 61    window(LC_WIN, (text = "log_capture", closable = false,
 62                    flags = ImGuiWindowFlags.None)) {
 63        text("with_log(ImGuiLogFlags.OutputClipboard, -1) captures rendered widget")
 64        text("text to the clipboard. Click to capture, then read it back below.")
 65        separator()
 66
 67        if (button(LC_BTN, (text = "Capture report to clipboard"))) {
 68            g_capture_requested = true
 69        }
 70        separator()
 71
 72        // The report renders every frame. On a capture frame, wrap it in a
 73        // clipboard log so each widget's text lands in the clipboard, then read
 74        // it straight back with GetClipboardText.
 75        let capture_now = g_capture_requested
 76        g_capture_requested = false
 77        if (capture_now) {
 78            g_capture_count++
 79            with_log(ImGuiLogFlags.OutputClipboard, -1) {
 80                text("=== Daslang Widget Report ===")
 81                text("Section: Fruits")
 82                text("  Apple, Banana, Cherry")
 83                LogRenderedText("(injected via LogRenderedText - capture #{g_capture_count})")
 84            }
 85            g_last_clip = GetClipboardText()
 86        } else {
 87            text("=== Daslang Widget Report ===")
 88            text("Section: Fruits")
 89            text("  Apple, Banana, Cherry")
 90        }
 91
 92        separator()
 93        text("Captures so far: {g_capture_count}. The injected line below appears ONLY")
 94        text("in the capture, never in the on-screen report above:")
 95        child(LC_VIEW, (text = "clip", size = float2(660.0f, 200.0f),
 96                        child_flags = ImGuiChildFlags.Borders,
 97                        window_flags = ImGuiWindowFlags.None)) {
 98            text(LC_TEXT, (text = g_last_clip))
 99        }
100    }
101
102    end_of_frame()
103    Render()
104    var w, h : int
105    live_get_framebuffer_size(w, h)
106    glViewport(0, 0, w, h)
107    glClearColor(0.10f, 0.10f, 0.12f, 1.0f)
108    glClear(GL_COLOR_BUFFER_BIT)
109    live_imgui_render()
110
111    live_end_frame()
112}
113
114[export]
115def shutdown() {
116    live_imgui_shutdown()
117    live_destroy_window()
118}
119
120[export]
121def main() {
122    init()
123    while (!exit_requested()) {
124        update()
125    }
126    shutdown()
127}

8.18.1.56.1.1. Requires

with_log is in imgui/imgui_scope_builtin (re-exported by imgui/imgui_boost_v2). GetClipboardText and LogRenderedText are in the carve-out of raw calls the lint allows.

8.18.1.56.1.2. Behaviour

  • Each widget submitted inside the with_log block has its rendered text appended to the chosen target.

  • LogRenderedText injects a line into the capture that is never drawn on screen — useful for machine-readable markers.

  • On the capture frame the demo logs to the clipboard, then reads it straight back with GetClipboardText and displays it in a child panel, so you can see exactly what was captured.

8.18.1.56.1.3. Migration note

Pre-1.92 code calling LogBegin(ImGuiLogType.Clipboard, ...) — or with_log(ImGuiLogType.Clipboard, ...) — should move to ImGuiLogFlags.OutputClipboard (and the matching Output* value for other targets).

See also

Full source: modules/dasImgui/examples/tutorial/log_capture.das

Feature smoke: modules/dasImgui/examples/features/internal_log_capture.das.

Boost macros — the macro layer.