Filter log messages by a numeric severity.

log-filter Scripts often decide which messages to show based on a threshold. This example keeps the message levels as immediate scalar values and records a compact summary.

Log Filters

threshold
log_filter.lua
Replay: real traced execution (multi-file project)
local threshold = 2
local shown = 0
local labels = ""

for _, level in ipairs({1, 2, 3}) do
  if level >= threshold then
    shown = shown + 1
    labels = labels .. "L" .. level
  end
end

print("threshold=" .. threshold)
print("shown=" .. shown)
print("labels=" .. labels)
local threshold = 1
local shown = 0
local labels = ""

for _, level in ipairs({1, 2, 3}) do
  if level >= threshold then
    shown = shown + 1
    labels = labels .. "L" .. level
  end
end

print("threshold=" .. threshold)
print("shown=" .. shown)
print("labels=" .. labels)
local threshold = 3
local shown = 0
local labels = ""

for _, level in ipairs({1, 2, 3}) do
  if level >= threshold then
    shown = shown + 1
    labels = labels .. "L" .. level
  end
end

print("threshold=" .. threshold)
print("shown=" .. shown)
print("labels=" .. labels)
  1. threshold ← 2, shown ← 0, labels ← (empty)

    1local threshold→ 2 = 2 --@threshold=1, 32local shown→ 0 = 03local labels→ (empty) = ""
  2. _, level in ipairs({1, 2, 3}) do

    pass 1 of 3
    5for _1, level1 in ipairs({1, 2, 3}) do6  if level >= threshold then7    shown = shown + 1
    All 3 passes — pass 1 is the card above
    pass_levelthresholdshownlabels
    111
    22220 1(empty) L2
    33321 2L2 L2L3
  3. shown ← 1, labels ← L2

    pass 1 of 2
    5for _, level in ipairs({1, 2, 3}) do6  if level2 >= threshold2 then7    shown→ 1 = shown + 18    labels→ L2 = labels .. "L" .. level29  end
  4. shown ← 2, labels ← L2L3

    pass 2 of 2
    5for _, level in ipairs({1, 2, 3}) do6  if level3 >= threshold2 then7    shown→ 2 = shown + 18    labels→ L2L3 = labels .. "L" .. level39  end
  5. print("threshold=" .. threshold)

    12print("threshold=" .. threshold2)13print("shown=" .. shown2)14print("labels=" .. labelsL2L3)
    outputthreshold=2
    shown=2
    labels=L2L3
  1. threshold ← 1, shown ← 0, labels ← (empty)

    1local threshold→ 1 = 12local shown→ 0 = 03local labels→ (empty) = ""
  2. _, level in ipairs({1, 2, 3}) do

    pass 1 of 3
    5for _1, level1 in ipairs({1, 2, 3}) do6  if level >= threshold then7    shown = shown + 1
    All 3 passes — pass 1 is the card above
    pass_level
    111
    222
    333
  3. shown ← 1, labels ← L1

    pass 1 of 3
    5for _, level in ipairs({1, 2, 3}) do6  if level1 >= threshold1 then7    shown→ 1 = shown + 18    labels→ L1 = labels .. "L" .. level19  end
    All 3 passes — pass 1 is the card above
    passlevelshownlabels
    110 1(empty) L1
    221 2L1 L1L2
    332 3L1L2 L1L2L3
  4. print("threshold=" .. threshold)

    12print("threshold=" .. threshold1)13print("shown=" .. shown3)14print("labels=" .. labelsL1L2L3)
    outputthreshold=1
    shown=3
    labels=L1L2L3
  1. threshold ← 3, shown ← 0, labels ← (empty)

    1local threshold→ 3 = 32local shown→ 0 = 03local labels→ (empty) = ""
  2. _, level in ipairs({1, 2, 3}) do

    pass 1 of 3
    5for _1, level1 in ipairs({1, 2, 3}) do6  if level >= threshold then7    shown = shown + 1
    All 3 passes — pass 1 is the card above
    pass_levelthresholdshownlabels
    111
    222
    33330 1(empty) L3
  3. shown ← 1, labels ← L3

    5for _, level in ipairs({1, 2, 3}) do6  if level3 >= threshold3 then7    shown→ 1 = shown + 18    labels→ L3 = labels .. "L" .. level39  end
  4. print("threshold=" .. threshold)

    12print("threshold=" .. threshold3)13print("shown=" .. shown1)14print("labels=" .. labelsL3)
    outputthreshold=3
    shown=1
    labels=L3