printf Parser Module


1. Variables

  • none

2. Functions

2.1. build_grammar

Constructs an LPEG grammar based on the printf format/args array.


  • t (array) - Column one is the format string and the additional columns are the capture names of the arguments. Capture names starting with an @ are expressions so the default parser for a type can be overridden when necessary.


  • grammar (LPEG user data object) or an error is thrown

2.2. load_messages

Compile the provide list of printf_messages into the grammars table.


  • printf_messages (array) - array of printf message specifications to be compiled into grammars

    printf_messages = {
    -- array (string and/or array) the order specified here is the load and evaluation order.
     -- string: name of a module containing a `printf_messages` array to import
     -- array: creates an on the fly grammar using a printf format specifications.
       -- see:
    {"%s:%lu: invalid line", "path", "linenum"},
    "lpeg.openssh_portable", -- must export a `printf_messages` array
  • grammars (array/nil) - optional existing grammar array to append to
  • grammars_size (number/nil) - number of items in the array
  • module (string/nil) - identifer to help locate errors in nested includes


  • grammars (array) or an error is thrown

2.3. match_sample

Finds the grammar associated with the specified log message.


  • grammars (array) - Output from load_printf_grammars


  • grammar (userdata/nil) - Best match for the sample input or nil if no match is found

source code: printf.lua

results matching ""

    No results matching ""