Skip to content

Loginator: Examples

Damian Monogue edited this page Jun 17, 2021 · 6 revisions

Some conventions

For each example below, I will send the same four log entries.

  log:error("Something is seriously broken!")
  log:warn("Things are minorly borked")
  log:info("You might want to know this")
  log:debug("Oh god you're digging deep aren't you?!")

So I will only include the code to create the logger with each example, and a screenshot of the html log generated. At the end I will include a couple of ansi and plaintext examples, but they do not have as much to configure.

bgColor and fgColor are html colors, and are written to the header of the file when the file is first created. This means changes to this will not take effect in files which are already started.

levelColors should be c/d/hecho colors (foreground only, no background)

Examples

Halloween logger

local log = loginator:new({ 
  name = "ExampleLogger",
  level = "debug",
  bgColor = "orange",
  fgColor = "black",
  levelColors = {
    warn = "blue"
  }
})

Light Mode

local log = loginator:new({ 
  name = "ExampleLogger",
  level = "debug",
  bgColor = "white",
  fgColor = "black",
})

Less eye searing light mode

local log = loginator:new({ 
  name = "ExampleLogger",
  level = "debug",
  bgColor = "lightgrey",
  fgColor = "black",
  levelColors = {
    error = "firebrick",
    warn = "blue",
    info = "brown",
    debug = "DarkGreen"
  }
})

Bog standard

Level is set to debug so all the messages are written. Besides that and the name everything else is default. This is how I see myself using it most of the time, though probably at 'warn' level.

local log = loginator:new({ 
  name = "ExampleLogger",
  level = "debug",
})

Bade Olde Englishe Loggere

Prithee stay a while and listene, thate Ie mighte relate toe thee the Tales ofe Olde.

local log = loginator:new({ 
  name = "ExampleLogger",
  level = "debug",
  entryTemplate = "In the Year of the Common Era |y, in the |M month on the |d day you stood upon the |c|l|r podium and spake thee: |t",
})

Color the message, not the level

local log = loginator:new({ 
  name = "ExampleLogger",
  level = "debug",
  entryTemplate = "|y-|M-|d |h:|m:|s.|x [|l] |c|t|r",
})

Ansi text format

This is catted in my terminal, which is green on black for 'default' text

local log = loginator:new({ 
  name = "ExampleLogger",
  level = "debug",
  format = "a"
})

Plaintext format

This one opened in my default text editor (gedit as it turns out)

local log = loginator:new({ 
  name = "ExampleLogger",
  level = "debug",
  format = "p"
})

Clone this wiki locally