Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Split log out of init.lua

  • Loading branch information...
commit 142861a16d672a938189f246b73b9ad41580fcdb 1 parent 8d81f1b
@pavouk authored
Showing with 39 additions and 22 deletions.
  1. +1 −22 lgi/init.lua
  2. +38 −0 lgi/log.lua
View
23 lgi/init.lua
@@ -45,28 +45,7 @@ end
-- Prepare logging support. 'log' is module-exported table, containing all
-- functionality related to logging wrapped around GLib g_log facility.
-lgi.log = {}
-
--- Creates table containing methods 'message', 'warning', 'critical', 'error',
--- 'debug' methods which log to specified domain.
-function lgi.log.domain(name)
- local domain = lgi.log[name] or {}
- for _, level in ipairs { 'message', 'warning', 'critical',
- 'error', 'debug' } do
- if not domain[level] then
- domain[level] =
- function(format, ...)
- local ok, msg = pcall(string.format, format, ...)
- if not ok then
- msg = ("BAD FMT: `%s', `%s'"):format(format, msg)
- end
- core.log(name, level:upper(), msg)
- end
- end
- end
- lgi.log[name] = domain
- return domain
-end
+lgi.log = require 'lgi.log'
-- For the rest of bootstrap, prepare logging to lgi domain.
local log = lgi.log.domain('lgi')
View
38 lgi/log.lua
@@ -0,0 +1,38 @@
+------------------------------------------------------------------------------
+--
+-- LGI support for GLib-based logging.
+--
+-- Copyright (c) 2011 Pavel Holejsovsky
+-- Licensed under the MIT license:
+-- http://www.opensource.org/licenses/mit-license.php
+--
+------------------------------------------------------------------------------
+
+local pcall, ipairs = pcall, ipairs
+local string = require 'string'
+local core = require 'lgi.core'
+
+local log = {}
+
+-- Creates table containing methods 'message', 'warning', 'critical', 'error',
+-- 'debug' methods which log to specified domain.
+function log.domain(name)
+ local domain = log[name] or {}
+ for _, level in ipairs { 'message', 'warning', 'critical',
+ 'error', 'debug' } do
+ if not domain[level] then
+ domain[level] =
+ function(format, ...)
+ local ok, msg = pcall(string.format, format, ...)
+ if not ok then
+ msg = ("BAD FMT: `%s', `%s'"):format(format, msg)
+ end
+ core.log(name, level:upper(), msg)
+ end
+ end
+ end
+ log[name] = domain
+ return domain
+end
+
+return log
Please sign in to comment.
Something went wrong with that request. Please try again.