log.vim : logging library
script karma |
Rating 12/3,
Downloaded by 1096 |
Comments, bugs, improvements
|
Vim wiki
|
created by |
Yukihiro Nakadaira |
|
script type |
utility |
|
description |
Usage:
" in .vimrc
call log#init('ALL', ['/dev/stdout', '~/.vim/log.txt'])
" in script
let s:log = log#getLogger(expand('<sfile>:t'))
function s:func()
call s:log.trace('start of func()')
if s:log.isDebugEnabled()
call s:log.debug('debug information')
endif
call s:log.trace('end of func()')
endfunction
" If you want to distribute your script without log.vim, use :silent! or
" exists().
silent! let s:log = log#getLogger(expand('<sfile>:t'))
function s:func()
silent! call s:log.info('aaa')
if exists('s:log')
call s:log.info('bbb')
endif
endfunction
Reference:
function log#init(level, targets [, format [, filter]])
@param level [String]
Log level. One of 'ALL|TRACE|DEBUG|INFO|WARN|ERROR|FATAL|NONE'.
For example, when level is 'WARN', output of log.warn(), log.error() and
log.fatal() will appear in log.
@param targets [mixed]
Output target. Filename or Function or Dictionary or List of these
values.
Filename:
Log is appended to the file.
Function:
function Log(str)
echo a:str
endfunction
Dictionary:
let Log = {}
function Log.__call__(str)
echohl Error
echo a:str
echohl None
endfunction
@param format [String]
Log format. {expr} is replaced by eval(expr). For example, {getpid()}
is useful to detect session. Following special variables are available.
{level} log level like DEBUG, INFO, etc...
{name} log name specified by log#getLogger(name)
{msg} log message
If this is 0, '', [] or {} (empty(format) is true), default is used.
default: [{level}][{strftime("%Y-%m-%d %H:%M:%S")}][{name}] {msg}
@param filter [mixed]
Pattern (String) or Function or Dictionary to filter log session.
Filter is applied to name that specified by log#getLogger(name). If
result is false, logging session do not output any text.
Pattern (String):
name =~ Pattern
Function:
function Filter(name)
return a:name == 'mylib'
endfunction
Dictionary:
let Filter = {}
let Filter.filter = ['alib', 'blib', 'clib']
function Filter.__call__(name)
return index(self.filter, a:name) != -1
endfunction
@return void
function log#getLogger(name)
@param name [String] Log name
@return Logger object |
|
install details |
Put this file in autoload directory in your 'runtimepath'. |
|
script versions (upload new version)
Click on the package to download.
ip used for rating: 3.17.162.15
|