@@ -11,7 +11,7 @@ local global_config = require("devcontainer-cli.config")
11
11
-- User configuration section
12
12
local default_config = {
13
13
-- Name of the plugin. Prepended to log messages
14
- plugin = ' decontainer -cli' ,
14
+ plugin = " devcontainer -cli" ,
15
15
16
16
-- Should print the output to neovim while running
17
17
use_console = true ,
@@ -29,12 +29,12 @@ local default_config = {
29
29
30
30
-- Level configuration
31
31
modes = {
32
- { name = " trace" , hl = " Comment" , },
33
- { name = " debug" , hl = " Comment" , },
34
- { name = " info" , hl = " None" , },
35
- { name = " warn" , hl = " WarningMsg" , },
36
- { name = " error" , hl = " ErrorMsg" , },
37
- { name = " fatal" , hl = " ErrorMsg" , },
32
+ { name = " trace" , hl = " Comment" },
33
+ { name = " debug" , hl = " Comment" },
34
+ { name = " info" , hl = " None" },
35
+ { name = " warn" , hl = " WarningMsg" },
36
+ { name = " error" , hl = " ErrorMsg" },
37
+ { name = " fatal" , hl = " ErrorMsg" },
38
38
},
39
39
40
40
-- Can limit the number of decimals displayed for floats
@@ -49,7 +49,7 @@ local unpack = unpack or table.unpack
49
49
log .new = function (config , standalone )
50
50
config = vim .tbl_deep_extend (" force" , default_config , config )
51
51
52
- local outfile = string.format (' %s/%s.log' , vim .fn .stdpath (" cache" ), config .plugin )
52
+ local outfile = string.format (" %s/%s.log" , vim .fn .stdpath (" cache" ), config .plugin )
53
53
54
54
local obj
55
55
if standalone then
@@ -66,12 +66,12 @@ log.new = function(config, standalone)
66
66
local round = function (x , increment )
67
67
increment = increment or 1
68
68
x = x / increment
69
- return (x > 0 and math.floor (x + .5 ) or math.ceil (x - .5 )) * increment
69
+ return (x > 0 and math.floor (x + 0 .5 ) or math.ceil (x - 0 .5 )) * increment
70
70
end
71
71
72
72
local make_string = function (...)
73
73
local t = {}
74
- for i = 1 , select (' # ' , ... ) do
74
+ for i = 1 , select (" # " , ... ) do
75
75
local x = select (i , ... )
76
76
77
77
if type (x ) == " number" and config .float_precision then
@@ -87,7 +87,6 @@ log.new = function(config, standalone)
87
87
return table.concat (t , " " )
88
88
end
89
89
90
-
91
90
local log_at_level = function (level , level_config , message_maker , ...)
92
91
local nameupper = level_config .name :upper ()
93
92
@@ -120,13 +119,15 @@ log.new = function(config, standalone)
120
119
end
121
120
122
121
-- Output to log file
123
- if config .use_file and level >= levels [config .log_level ] then
124
- local fp = io.open (outfile , " a" )
125
- local str = string.format (" [%-6s%s] %s: %s\n " ,
126
- nameupper , os.date (), lineinfo , msg )
127
- if fp ~= nil then
122
+ if config .use_file and level < levels [config .log_level ] then
123
+ local ok , err = pcall (function ()
124
+ local fp = assert (io.open (outfile , " a" ))
125
+ local str = string.format (" [%-6s%s] %s: %s\n " , nameupper , os.date (), lineinfo , msg )
128
126
fp :write (str )
129
127
fp :close ()
128
+ end )
129
+ if not ok then
130
+ vim .notify (string.format (" Failed to write to log file: %s" , err ), vim .log .levels .ERROR )
130
131
end
131
132
end
132
133
end
@@ -136,9 +137,9 @@ log.new = function(config, standalone)
136
137
return log_at_level (i , x , make_string , ... )
137
138
end
138
139
139
- obj [(" fmt_%s" ):format (x .name )] = function ()
140
+ obj [(" fmt_%s" ):format (x .name )] = function ()
140
141
return log_at_level (i , x , function (...)
141
- local passed = {... }
142
+ local passed = { ... }
142
143
local fmt = table.remove (passed , 1 )
143
144
local inspected = {}
144
145
for _ , v in ipairs (passed ) do
0 commit comments