Menu
Coddy logo textTech

Recap - Log File Parser

Part of the Logic & Flow section of Coddy's Lua journey — lesson 40 of 54.

challenge icon

Challenge

Easy

Write a function parseLogEntry that takes logEntry and returns the extracted log information in a formatted string.

Use string.match() with multiple captures to extract the log level (in brackets), the message text, and the numeric ID from the log entry. Return these three pieces of information separated by commas.

Logic:

  • Use a pattern with three captures: one for the log level inside brackets, one for the message text, and one for the numeric ID
  • The log level is uppercase letters inside square brackets
  • The message is text between the colon and the numeric ID
  • The ID is one or more digits at the end
  • Return the three captured values in the format: level,message,id

Parameters:

  • logEntry (string): A log entry in the format [LEVEL]: Message text ID

Returns: The extracted information as level,message,id (string)

Try it yourself

function parseLogEntry(logEntry)
    -- Write code here
end

All lessons in Logic & Flow