Skip to content

Commit 48a52dd

Browse files
feat: add log_level off
## Details Request: #235 Adds option to set "off" as value for log_level. This should prevent any logs from being written to the log file. The default value is kept as "error". Minor changes to how buffer level locking works to include file name in all cases to ease debugging.
1 parent 82184c4 commit 48a52dd

File tree

8 files changed

+28
-17
lines changed

8 files changed

+28
-17
lines changed

doc/render-markdown.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2024 November 13
1+
*render-markdown.txt* For 0.10.0 Last change: 2024 November 17
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*

lua/render-markdown/core/log.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ end
5858
---@param buf integer
5959
---@param ... any
6060
function M.buf(level, name, buf, ...)
61-
M.add(level, string.format('%s %d', name, buf), ...)
61+
M.add(level, string.format('%s|%s|%d', name, util.file_name(buf), buf), ...)
6262
end
6363

6464
---@param level render.md.config.LogLevel
@@ -98,6 +98,8 @@ function M.level_value(level)
9898
return 2
9999
elseif level == 'error' then
100100
return 3
101+
elseif level == 'off' then
102+
return 4
101103
else
102104
return 0
103105
end

lua/render-markdown/core/util.lua

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,20 @@ function M.textoff(win)
125125
return #infos == 1 and infos[1].textoff or 0
126126
end
127127

128-
---@param file string
128+
---@param buf integer
129+
---@return string
130+
function M.file_name(buf)
131+
local file = vim.api.nvim_buf_get_name(buf)
132+
return vim.fn.fnamemodify(file, ':t')
133+
end
134+
135+
---@param source string|integer
129136
---@return number
130-
function M.file_size_mb(file)
137+
function M.file_size_mb(source)
138+
local file = source
139+
if type(file) == 'number' then
140+
file = vim.api.nvim_buf_get_name(file)
141+
end
131142
local ok, stats = pcall(function()
132143
return (vim.uv or vim.loop).fs_stat(file)
133144
end)

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local state = require('render-markdown.state')
44
local M = {}
55

66
---@private
7-
M.version = '7.5.5'
7+
M.version = '7.5.6'
88

99
function M.check()
1010
M.start('version')

lua/render-markdown/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ local M = {}
228228
---@field public win_options? table<string, render.md.UserWindowOption>
229229

230230
---@alias render.md.config.Preset 'none'|'lazy'|'obsidian'
231-
---@alias render.md.config.LogLevel 'debug'|'info'|'error'
231+
---@alias render.md.config.LogLevel 'off'|'debug'|'info'|'error'
232232

233233
---@class (exact) render.md.UserConfig: render.md.UserBufferConfig
234234
---@field public preset? render.md.config.Preset

lua/render-markdown/manager.lua

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,36 +83,34 @@ end
8383
---@param buf integer
8484
---@return boolean
8585
function M.should_attach(buf)
86-
local file = vim.api.nvim_buf_get_name(buf)
87-
local log_name = string.format('attach %s', vim.fn.fnamemodify(file, ':t'))
88-
log.buf('info', log_name, buf, 'start')
86+
log.buf('info', 'attach', buf, 'start')
8987

9088
if vim.tbl_contains(buffers, buf) then
91-
log.buf('info', log_name, buf, 'skip', 'already attached')
89+
log.buf('info', 'attach', buf, 'skip', 'already attached')
9290
return false
9391
end
9492

9593
local file_type, file_types = util.get('buf', buf, 'filetype'), state.file_types
9694
if not vim.tbl_contains(file_types, file_type) then
9795
local reason = string.format('%s /∈ %s', file_type, vim.inspect(file_types))
98-
log.buf('info', log_name, buf, 'skip', 'file type', reason)
96+
log.buf('info', 'attach', buf, 'skip', 'file type', reason)
9997
return false
10098
end
10199

102100
local config = state.get(buf)
103101
if not config.enabled then
104-
log.buf('info', log_name, buf, 'skip', 'state disabled')
102+
log.buf('info', 'attach', buf, 'skip', 'state disabled')
105103
return false
106104
end
107105

108-
local file_size, max_file_size = util.file_size_mb(file), config.max_file_size
106+
local file_size, max_file_size = util.file_size_mb(buf), config.max_file_size
109107
if file_size > max_file_size then
110108
local reason = string.format('%f > %f', file_size, max_file_size)
111-
log.buf('info', log_name, buf, 'skip', 'file size', reason)
109+
log.buf('info', 'attach', buf, 'skip', 'file size', reason)
112110
return false
113111
end
114112

115-
log.buf('info', log_name, buf, 'success')
113+
log.buf('info', 'attach', buf, 'success')
116114
table.insert(buffers, buf)
117115
return true
118116
end

lua/render-markdown/state.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ function M.validate()
269269
:type('log_runtime', 'boolean')
270270
:list('file_types', 'string')
271271
:one_of('preset', { 'none', 'lazy', 'obsidian' })
272-
:one_of('log_level', { 'debug', 'info', 'error' })
272+
:one_of('log_level', { 'off', 'debug', 'info', 'error' })
273273
:nested('injections', function(injections)
274274
injections
275275
:nested('ALL', function(injection)

tests/state_spec.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe('state', function()
8282
'render-markdown.debounce: expected type number, got table',
8383
'render-markdown.enabled: expected type boolean, got string',
8484
'render-markdown.heading.enabled: expected type boolean, got string',
85-
'render-markdown.log_level: expected one of { "debug", "info", "error" }, got string',
85+
'render-markdown.log_level: expected one of { "off", "debug", "info", "error" }, got string',
8686
'render-markdown.log_runtime: expected type boolean, got string',
8787
'render-markdown.max_file_size: expected type number, got boolean',
8888
'render-markdown.overrides.buftype.nofile.sign.highlight: expected type string or nil, got boolean',

0 commit comments

Comments
 (0)