vim-maktaba icon indicating copy to clipboard operation
vim-maktaba copied to clipboard

Maktaba should offer a simple log handler

Open malcolmr opened this issue 9 years ago • 4 comments

Maktaba's logging is useful, but unless I'm missing something, there's easy no way to use it out of the box, as you need your own log handler before it'll do anything.

We don't want to install a log handler by default, but it would be useful to provide an optional maktaba#log#InstallSimpleLogHandler() that adds a handler that accumulates log records into a (user-specified?) limited-size list, along with a maktaba#log#GetSimpleLogHandlerRecords() or similar.

malcolmr avatar Mar 23 '15 13:03 malcolmr

You can get it with two hacky lines of vimscript:

let g:maktaba_log = []
call maktaba#log#AddHandler(maktaba#function#FromExpr('add(g:maktaba_log, a:000)'), 1)

The real answer is to publish a simple plugin to receive and display the logs. We can document that hack to get it in the meantime, or maybe we could add something like maktaba#log#NewReceiverList([with_recent]) -> list to get that down to

let g:maktaba_log = maktaba#log#NewReceiverList(1)

I don't think bounding it will be that big a deal either, at least for the short-term solution.

dbarnett avatar Mar 24 '15 06:03 dbarnett

A logging plugin would certainly be nice, but I was thinking of something that would be available to someone just using Maktaba.

I like the idea of providing something simple. I think what you're proposing with NewReceiverList() is effectively the combination of the two things I suggested? (I'm not sure a name like IfNecessaryInstallNewTrivialLogHandlerAndAnywayReturnLogEntries() is entirely sensible, but those are the semantics we're talking about, right?)

Is there any reason a casual caller wouldn't want the recent log entries?

malcolmr avatar Mar 24 '15 12:03 malcolmr

Almost. The list reference would be updated as new messages come in.

But actually, something like maktaba#log#DumpRecentEntries() could just return a copy of s:log_queue. Then users just have to bump the 'history' setting early if they want to not lose early log entries (a message in the log tells them so).

BTW, don't want to optimize for the no-logging-plugin case too much, because reading entries from a vimscript list is pretty awkward and the plugin is very small. We thought about including more of a user interface in maktaba but it didn't fit well for a library.

dbarnett avatar Mar 24 '15 16:03 dbarnett

I also noticed maktaba doesn't shout warning and error logging to the user as messages come in (#185). That part should be pretty easy to make built-in.

dbarnett avatar Mar 25 '17 17:03 dbarnett