sponsor Vim development Vim logo Vim Book Ad

log.vim : logging library

 script karma  Rating 12/3, Downloaded by 682    Comments, bugs, improvements  Vim wiki

created by
Yukihiro Nakadaira
script type
  " 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')
    call s:log.trace('end of func()')

  " 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')


  function log#init(level, targets [, format [, filter]])
  @param level [String]
    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
      Log is appended to the file.
      function Log(str)
        echo a:str
      let Log = {}
      function Log.__call__(str)
        echohl Error
        echo a:str
        echohl None
  @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 Filter(name)
        return a:name == 'mylib'
      let Filter = {}
      let Filter.filter = ['alib', 'blib', 'clib']
      function Filter.__call__(name)
        return index(self.filter, a:name) != -1
  @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'.

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
log.vim 1.0 2008-08-05 7.0 Yukihiro Nakadaira Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
SourceForge.net Logo