lua-log icon indicating copy to clipboard operation
lua-log copied to clipboard

Feature request: categories

Open d9k opened this issue 7 years ago • 2 comments

Feature request: categories and filter by categories.

Category must be a new non-required string parameter for log function .

d9k avatar Feb 26 '18 02:02 d9k

I do not think I like this idea.

When I create this library I think about it as a low level library. And to build complex loggers just need one more level which will build loggers based on configuration files like this.

local log = Logger[category]
log.error('message')

-- or even use `log` to build/find new loggers
local db_log = log.database

Where Logger will build new loggers by some config.

-- Config at first have to define all writers.
-- It is important because some writers create
-- worker threads to  do IO in background
writers = {
  file1 = { type = 'file' ... },
  file2 = { type = 'file' ... }.
  server1 = {type = 'net.udp'},
  email = {type = 'smtp'},
}

-- Then define loggers based on existed writers.
loggers = {
  category1 = {
    writers = {
         {writers.file1, writers.server1},
         alert = writers.email,
    }
    -- may be other settings
  },
  category1 = {
    writers = {
         {writers.file2, writers.server1},
         alert = writers.email,
    }
  },
}

moteus avatar Feb 26 '18 07:02 moteus

thx, @moteus, I was intending to overcome the lack of categories exactly the same way you're suggesting!

d9k avatar Feb 27 '18 00:02 d9k