您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

420 行
18 KiB

Disable I/O to the console if the old-style Erlang console is used There's a nasty problem with the Erlang VM + lager when the old-style Erlang console is used. You can use the "-oldshell" flag to explicitly get the old-style shell. However, if the Erlang VM is started when *not* associated with a pseudo-tty, the VM will silently use the old-style shell (because the new-style shell requires a pty to support command line editing, etc.). The most common way of starting the Erlang VM without a pty is to start it via a non-interactive SSH session. This patch is opinionated in what to do in the case when the old- style shell is detected. My opinion is: 1. Shout loudly to the console log (in a separate Erlang process, so that the main lager event handler proc won't be blocked by any problems with the old-style console). It's almost certainly likely that you really don't want to run Erlang with the old-style shell. But many sysadmins don't look closely at their systems' log files, so (for example) shouting the same message 10x in a row is legit. Reviewers: YMMV. 2. Set a SASL alarm. Again, many sysadmins' are bad at looking at log messages. Setting a SASL alarm is another method to try to get their attention. To test, create a test script called `/tmp/testit.sh`, changing the `-pz` parameter to point to the correct place for lager's `ebin` subdirectory: #!/bin/sh erl -pz /Users/fritchie/b/src/lager/ebin -eval '{application:start(sasl), lager_console_backend:init([error, true]), timer:sleep(5*1000), io:format("\n\nInfo: ~p\n\n", [{{alarms, alarm_handler:get_alarms()}, {user_drv, whereis(user_drv)}}]), erlang:halt()}.' Then run it twice, using the following: First time: ssh -t localhost sh /tmp/testit.sh Second time: ssh localhost sh /tmp/testit.sh The last lines of the first time should look like: Info: {{alarms,[]},{user_drv,<0.22.0>}} The last lines of the second time should look like: Info: {{alarms, [{lager_console_backend, "WARNING: old-style console is in use, so lager_console_backend log output to the console is disabled. Restart the VM on a pseudo-tty to ensure use of the new-style VM console."}]}, {user_drv,undefined}}
12 年前
Disable I/O to the console if the old-style Erlang console is used There's a nasty problem with the Erlang VM + lager when the old-style Erlang console is used. You can use the "-oldshell" flag to explicitly get the old-style shell. However, if the Erlang VM is started when *not* associated with a pseudo-tty, the VM will silently use the old-style shell (because the new-style shell requires a pty to support command line editing, etc.). The most common way of starting the Erlang VM without a pty is to start it via a non-interactive SSH session. This patch is opinionated in what to do in the case when the old- style shell is detected. My opinion is: 1. Shout loudly to the console log (in a separate Erlang process, so that the main lager event handler proc won't be blocked by any problems with the old-style console). It's almost certainly likely that you really don't want to run Erlang with the old-style shell. But many sysadmins don't look closely at their systems' log files, so (for example) shouting the same message 10x in a row is legit. Reviewers: YMMV. 2. Set a SASL alarm. Again, many sysadmins' are bad at looking at log messages. Setting a SASL alarm is another method to try to get their attention. To test, create a test script called `/tmp/testit.sh`, changing the `-pz` parameter to point to the correct place for lager's `ebin` subdirectory: #!/bin/sh erl -pz /Users/fritchie/b/src/lager/ebin -eval '{application:start(sasl), lager_console_backend:init([error, true]), timer:sleep(5*1000), io:format("\n\nInfo: ~p\n\n", [{{alarms, alarm_handler:get_alarms()}, {user_drv, whereis(user_drv)}}]), erlang:halt()}.' Then run it twice, using the following: First time: ssh -t localhost sh /tmp/testit.sh Second time: ssh localhost sh /tmp/testit.sh The last lines of the first time should look like: Info: {{alarms,[]},{user_drv,<0.22.0>}} The last lines of the second time should look like: Info: {{alarms, [{lager_console_backend, "WARNING: old-style console is in use, so lager_console_backend log output to the console is disabled. Restart the VM on a pseudo-tty to ensure use of the new-style VM console."}]}, {user_drv,undefined}}
12 年前
Disable I/O to the console if the old-style Erlang console is used There's a nasty problem with the Erlang VM + lager when the old-style Erlang console is used. You can use the "-oldshell" flag to explicitly get the old-style shell. However, if the Erlang VM is started when *not* associated with a pseudo-tty, the VM will silently use the old-style shell (because the new-style shell requires a pty to support command line editing, etc.). The most common way of starting the Erlang VM without a pty is to start it via a non-interactive SSH session. This patch is opinionated in what to do in the case when the old- style shell is detected. My opinion is: 1. Shout loudly to the console log (in a separate Erlang process, so that the main lager event handler proc won't be blocked by any problems with the old-style console). It's almost certainly likely that you really don't want to run Erlang with the old-style shell. But many sysadmins don't look closely at their systems' log files, so (for example) shouting the same message 10x in a row is legit. Reviewers: YMMV. 2. Set a SASL alarm. Again, many sysadmins' are bad at looking at log messages. Setting a SASL alarm is another method to try to get their attention. To test, create a test script called `/tmp/testit.sh`, changing the `-pz` parameter to point to the correct place for lager's `ebin` subdirectory: #!/bin/sh erl -pz /Users/fritchie/b/src/lager/ebin -eval '{application:start(sasl), lager_console_backend:init([error, true]), timer:sleep(5*1000), io:format("\n\nInfo: ~p\n\n", [{{alarms, alarm_handler:get_alarms()}, {user_drv, whereis(user_drv)}}]), erlang:halt()}.' Then run it twice, using the following: First time: ssh -t localhost sh /tmp/testit.sh Second time: ssh localhost sh /tmp/testit.sh The last lines of the first time should look like: Info: {{alarms,[]},{user_drv,<0.22.0>}} The last lines of the second time should look like: Info: {{alarms, [{lager_console_backend, "WARNING: old-style console is in use, so lager_console_backend log output to the console is disabled. Restart the VM on a pseudo-tty to ensure use of the new-style VM console."}]}, {user_drv,undefined}}
12 年前
Disable I/O to the console if the old-style Erlang console is used There's a nasty problem with the Erlang VM + lager when the old-style Erlang console is used. You can use the "-oldshell" flag to explicitly get the old-style shell. However, if the Erlang VM is started when *not* associated with a pseudo-tty, the VM will silently use the old-style shell (because the new-style shell requires a pty to support command line editing, etc.). The most common way of starting the Erlang VM without a pty is to start it via a non-interactive SSH session. This patch is opinionated in what to do in the case when the old- style shell is detected. My opinion is: 1. Shout loudly to the console log (in a separate Erlang process, so that the main lager event handler proc won't be blocked by any problems with the old-style console). It's almost certainly likely that you really don't want to run Erlang with the old-style shell. But many sysadmins don't look closely at their systems' log files, so (for example) shouting the same message 10x in a row is legit. Reviewers: YMMV. 2. Set a SASL alarm. Again, many sysadmins' are bad at looking at log messages. Setting a SASL alarm is another method to try to get their attention. To test, create a test script called `/tmp/testit.sh`, changing the `-pz` parameter to point to the correct place for lager's `ebin` subdirectory: #!/bin/sh erl -pz /Users/fritchie/b/src/lager/ebin -eval '{application:start(sasl), lager_console_backend:init([error, true]), timer:sleep(5*1000), io:format("\n\nInfo: ~p\n\n", [{{alarms, alarm_handler:get_alarms()}, {user_drv, whereis(user_drv)}}]), erlang:halt()}.' Then run it twice, using the following: First time: ssh -t localhost sh /tmp/testit.sh Second time: ssh localhost sh /tmp/testit.sh The last lines of the first time should look like: Info: {{alarms,[]},{user_drv,<0.22.0>}} The last lines of the second time should look like: Info: {{alarms, [{lager_console_backend, "WARNING: old-style console is in use, so lager_console_backend log output to the console is disabled. Restart the VM on a pseudo-tty to ensure use of the new-style VM console."}]}, {user_drv,undefined}}
12 年前
Disable I/O to the console if the old-style Erlang console is used There's a nasty problem with the Erlang VM + lager when the old-style Erlang console is used. You can use the "-oldshell" flag to explicitly get the old-style shell. However, if the Erlang VM is started when *not* associated with a pseudo-tty, the VM will silently use the old-style shell (because the new-style shell requires a pty to support command line editing, etc.). The most common way of starting the Erlang VM without a pty is to start it via a non-interactive SSH session. This patch is opinionated in what to do in the case when the old- style shell is detected. My opinion is: 1. Shout loudly to the console log (in a separate Erlang process, so that the main lager event handler proc won't be blocked by any problems with the old-style console). It's almost certainly likely that you really don't want to run Erlang with the old-style shell. But many sysadmins don't look closely at their systems' log files, so (for example) shouting the same message 10x in a row is legit. Reviewers: YMMV. 2. Set a SASL alarm. Again, many sysadmins' are bad at looking at log messages. Setting a SASL alarm is another method to try to get their attention. To test, create a test script called `/tmp/testit.sh`, changing the `-pz` parameter to point to the correct place for lager's `ebin` subdirectory: #!/bin/sh erl -pz /Users/fritchie/b/src/lager/ebin -eval '{application:start(sasl), lager_console_backend:init([error, true]), timer:sleep(5*1000), io:format("\n\nInfo: ~p\n\n", [{{alarms, alarm_handler:get_alarms()}, {user_drv, whereis(user_drv)}}]), erlang:halt()}.' Then run it twice, using the following: First time: ssh -t localhost sh /tmp/testit.sh Second time: ssh localhost sh /tmp/testit.sh The last lines of the first time should look like: Info: {{alarms,[]},{user_drv,<0.22.0>}} The last lines of the second time should look like: Info: {{alarms, [{lager_console_backend, "WARNING: old-style console is in use, so lager_console_backend log output to the console is disabled. Restart the VM on a pseudo-tty to ensure use of the new-style VM console."}]}, {user_drv,undefined}}
12 年前
  1. %% Copyright (c) 2011-2012, 2014 Basho Technologies, Inc. All Rights Reserved.
  2. %%
  3. %% This file is provided to you under the Apache License,
  4. %% Version 2.0 (the "License"); you may not use this file
  5. %% except in compliance with the License. You may obtain
  6. %% a copy of the License at
  7. %%
  8. %% http://www.apache.org/licenses/LICENSE-2.0
  9. %%
  10. %% Unless required by applicable law or agreed to in writing,
  11. %% software distributed under the License is distributed on an
  12. %% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. %% KIND, either express or implied. See the License for the
  14. %% specific language governing permissions and limitations
  15. %% under the License.
  16. %% @doc Console backend for lager. Configured with a single option, the loglevel
  17. %% desired.
  18. -module(lager_console_backend).
  19. -behaviour(gen_event).
  20. -export([init/1, handle_call/2, handle_event/2, handle_info/2, terminate/2,
  21. code_change/3]).
  22. -record(state, {level :: {'mask', integer()},
  23. formatter :: atom(),
  24. format_config :: any(),
  25. colors=[] :: list()}).
  26. -ifdef(TEST).
  27. -include_lib("eunit/include/eunit.hrl").
  28. -compile([{parse_transform, lager_transform}]).
  29. -endif.
  30. -include("lager.hrl").
  31. -define(TERSE_FORMAT,[time, " ", color, "[", severity,"] ", message]).
  32. %% @private
  33. init([Level, true]) -> % for backwards compatibility
  34. init([Level,{lager_default_formatter,[{eol, eol()}]}]);
  35. init([Level,false]) -> % for backwards compatibility
  36. init([Level,{lager_default_formatter,?TERSE_FORMAT ++ [eol()]}]);
  37. init([Level,{Formatter,FormatterConfig}]) when is_atom(Formatter) ->
  38. Colors = case application:get_env(lager, colored) of
  39. {ok, true} ->
  40. {ok, LagerColors} = application:get_env(lager, colors),
  41. LagerColors;
  42. _ -> []
  43. end,
  44. try {is_new_style_console_available(), lager_util:config_to_mask(Level)} of
  45. {false, _} ->
  46. Msg = "Lager's console backend is incompatible with the 'old' shell, not enabling it",
  47. %% be as noisy as possible, log to every possible place
  48. try
  49. alarm_handler:set_alarm({?MODULE, "WARNING: " ++ Msg})
  50. catch
  51. _:_ ->
  52. error_logger:warning_msg(Msg ++ "~n")
  53. end,
  54. io:format("WARNING: " ++ Msg ++ "~n"),
  55. ?INT_LOG(warning, Msg, []),
  56. {error, {fatal, old_shell}};
  57. {true, Levels} ->
  58. {ok, #state{level=Levels,
  59. formatter=Formatter,
  60. format_config=FormatterConfig,
  61. colors=Colors}}
  62. catch
  63. _:_ ->
  64. {error, {fatal, bad_log_level}}
  65. end;
  66. init(Level) ->
  67. init([Level,{lager_default_formatter,?TERSE_FORMAT ++ [eol()]}]).
  68. %% @private
  69. handle_call(get_loglevel, #state{level=Level} = State) ->
  70. {ok, Level, State};
  71. handle_call({set_loglevel, Level}, State) ->
  72. try lager_util:config_to_mask(Level) of
  73. Levels ->
  74. {ok, ok, State#state{level=Levels}}
  75. catch
  76. _:_ ->
  77. {ok, {error, bad_log_level}, State}
  78. end;
  79. handle_call(_Request, State) ->
  80. {ok, ok, State}.
  81. %% @private
  82. handle_event({log, Message},
  83. #state{level=L,formatter=Formatter,format_config=FormatConfig,colors=Colors} = State) ->
  84. case lager_util:is_loggable(Message, L, ?MODULE) of
  85. true ->
  86. io:put_chars(user, Formatter:format(Message,FormatConfig,Colors)),
  87. {ok, State};
  88. false ->
  89. {ok, State}
  90. end;
  91. handle_event(_Event, State) ->
  92. {ok, State}.
  93. %% @private
  94. handle_info(_Info, State) ->
  95. {ok, State}.
  96. %% @private
  97. terminate(_Reason, _State) ->
  98. ok.
  99. %% @private
  100. code_change(_OldVsn, State, _Extra) ->
  101. {ok, State}.
  102. eol() ->
  103. case application:get_env(lager, colored) of
  104. {ok, true} ->
  105. "\e[0m\r\n";
  106. _ ->
  107. "\r\n"
  108. end.
  109. -ifdef(TEST).
  110. is_new_style_console_available() ->
  111. true.
  112. -else.
  113. is_new_style_console_available() ->
  114. %% Criteria:
  115. %% 1. If the user has specified '-noshell' on the command line,
  116. %% then we will pretend that the new-style console is available.
  117. %% If there is no shell at all, then we don't have to worry
  118. %% about log events being blocked by the old-style shell.
  119. %% 2. Windows doesn't support the new shell, so all windows users
  120. %% have is the oldshell.
  121. %% 3. If the user_drv process is registered, all is OK.
  122. %% 'user_drv' is a registered proc name used by the "new"
  123. %% console driver.
  124. init:get_argument(noshell) /= error orelse
  125. element(1, os:type()) /= win32 orelse
  126. is_pid(whereis(user_drv)).
  127. -endif.
  128. -ifdef(TEST).
  129. console_log_test_() ->
  130. %% tiny recursive fun that pretends to be a group leader
  131. F = fun(Self) ->
  132. fun() ->
  133. YComb = fun(Fun) ->
  134. receive
  135. {io_request, From, ReplyAs, {put_chars, unicode, _Msg}} = Y ->
  136. From ! {io_reply, ReplyAs, ok},
  137. Self ! Y,
  138. Fun(Fun);
  139. Other ->
  140. ?debugFmt("unexpected message ~p~n", [Other]),
  141. Self ! Other
  142. end
  143. end,
  144. YComb(YComb)
  145. end
  146. end,
  147. {foreach,
  148. fun() ->
  149. error_logger:tty(false),
  150. application:load(lager),
  151. application:set_env(lager, handlers, []),
  152. application:set_env(lager, error_logger_redirect, false),
  153. lager:start(),
  154. whereis(user)
  155. end,
  156. fun(User) ->
  157. unregister(user),
  158. register(user, User),
  159. application:stop(lager),
  160. application:stop(goldrush),
  161. error_logger:tty(true)
  162. end,
  163. [
  164. {"regular console logging",
  165. fun() ->
  166. Pid = spawn(F(self())),
  167. unregister(user),
  168. register(user, Pid),
  169. erlang:group_leader(Pid, whereis(lager_event)),
  170. gen_event:add_handler(lager_event, lager_console_backend, info),
  171. lager_config:set(loglevel, {element(2, lager_util:config_to_mask(info)), []}),
  172. lager:log(info, self(), "Test message"),
  173. receive
  174. {io_request, From, ReplyAs, {put_chars, unicode, Msg}} ->
  175. From ! {io_reply, ReplyAs, ok},
  176. TestMsg = "Test message" ++ eol(),
  177. ?assertMatch([_, "[info]", TestMsg], re:split(Msg, " ", [{return, list}, {parts, 3}]))
  178. after
  179. 500 ->
  180. ?assert(false)
  181. end
  182. end
  183. },
  184. {"verbose console logging",
  185. fun() ->
  186. Pid = spawn(F(self())),
  187. unregister(user),
  188. register(user, Pid),
  189. erlang:group_leader(Pid, whereis(lager_event)),
  190. gen_event:add_handler(lager_event, lager_console_backend, [info, true]),
  191. lager_config:set(loglevel, {element(2, lager_util:config_to_mask(info)), []}),
  192. lager:info("Test message"),
  193. PidStr = pid_to_list(self()),
  194. receive
  195. {io_request, _, _, {put_chars, unicode, Msg}} ->
  196. TestMsg = "Test message" ++ eol(),
  197. ?assertMatch([_, _, "[info]", PidStr, _, TestMsg], re:split(Msg, "[ @]", [{return, list}, {parts, 6}]))
  198. after
  199. 500 ->
  200. ?assert(false)
  201. end
  202. end
  203. },
  204. {"custom format console logging",
  205. fun() ->
  206. Pid = spawn(F(self())),
  207. unregister(user),
  208. register(user, Pid),
  209. erlang:group_leader(Pid, whereis(lager_event)),
  210. gen_event:add_handler(lager_event, lager_console_backend,
  211. [info, {lager_default_formatter, [date,"#",time,"#",severity,"#",node,"#",pid,"#",
  212. module,"#",function,"#",file,"#",line,"#",message,"\r\n"]}]),
  213. lager_config:set(loglevel, {?INFO, []}),
  214. lager:info("Test message"),
  215. PidStr = pid_to_list(self()),
  216. NodeStr = atom_to_list(node()),
  217. ModuleStr = atom_to_list(?MODULE),
  218. receive
  219. {io_request, _, _, {put_chars, unicode, Msg}} ->
  220. TestMsg = "Test message" ++ eol(),
  221. ?assertMatch([_, _, "info", NodeStr, PidStr, ModuleStr, _, _, _, TestMsg],
  222. re:split(Msg, "#", [{return, list}, {parts, 10}]))
  223. after
  224. 500 ->
  225. ?assert(false)
  226. end
  227. end
  228. },
  229. {"tracing should work",
  230. fun() ->
  231. Pid = spawn(F(self())),
  232. unregister(user),
  233. register(user, Pid),
  234. gen_event:add_handler(lager_event, lager_console_backend, info),
  235. erlang:group_leader(Pid, whereis(lager_event)),
  236. lager_config:set(loglevel, {element(2, lager_util:config_to_mask(info)), []}),
  237. lager:debug("Test message"),
  238. receive
  239. {io_request, From, ReplyAs, {put_chars, unicode, _Msg}} ->
  240. From ! {io_reply, ReplyAs, ok},
  241. ?assert(false)
  242. after
  243. 500 ->
  244. ?assert(true)
  245. end,
  246. {ok, _} = lager:trace_console([{module, ?MODULE}]),
  247. lager:debug("Test message"),
  248. receive
  249. {io_request, From1, ReplyAs1, {put_chars, unicode, Msg1}} ->
  250. From1 ! {io_reply, ReplyAs1, ok},
  251. TestMsg = "Test message" ++ eol(),
  252. ?assertMatch([_, "[debug]", TestMsg], re:split(Msg1, " ", [{return, list}, {parts, 3}]))
  253. after
  254. 500 ->
  255. ?assert(false)
  256. end
  257. end
  258. },
  259. {"tracing doesn't duplicate messages",
  260. fun() ->
  261. Pid = spawn(F(self())),
  262. unregister(user),
  263. register(user, Pid),
  264. gen_event:add_handler(lager_event, lager_console_backend, info),
  265. lager_config:set(loglevel, {element(2, lager_util:config_to_mask(info)), []}),
  266. erlang:group_leader(Pid, whereis(lager_event)),
  267. lager:debug("Test message"),
  268. receive
  269. {io_request, From, ReplyAs, {put_chars, unicode, _Msg}} ->
  270. From ! {io_reply, ReplyAs, ok},
  271. ?assert(false)
  272. after
  273. 500 ->
  274. ?assert(true)
  275. end,
  276. {ok, _} = lager:trace_console([{module, ?MODULE}]),
  277. lager:error("Test message"),
  278. receive
  279. {io_request, From1, ReplyAs1, {put_chars, unicode, Msg1}} ->
  280. From1 ! {io_reply, ReplyAs1, ok},
  281. TestMsg = "Test message" ++ eol(),
  282. ?assertMatch([_, "[error]", TestMsg], re:split(Msg1, " ", [{return, list}, {parts, 3}]))
  283. after
  284. 1000 ->
  285. ?assert(false)
  286. end,
  287. %% make sure this event wasn't duplicated
  288. receive
  289. {io_request, From2, ReplyAs2, {put_chars, unicode, _Msg2}} ->
  290. From2 ! {io_reply, ReplyAs2, ok},
  291. ?assert(false)
  292. after
  293. 500 ->
  294. ?assert(true)
  295. end
  296. end
  297. },
  298. {"blacklisting a loglevel works",
  299. fun() ->
  300. Pid = spawn(F(self())),
  301. unregister(user),
  302. register(user, Pid),
  303. gen_event:add_handler(lager_event, lager_console_backend, info),
  304. lager_config:set(loglevel, {element(2, lager_util:config_to_mask(info)), []}),
  305. lager:set_loglevel(lager_console_backend, '!=info'),
  306. erlang:group_leader(Pid, whereis(lager_event)),
  307. lager:debug("Test message"),
  308. receive
  309. {io_request, From1, ReplyAs1, {put_chars, unicode, Msg1}} ->
  310. From1 ! {io_reply, ReplyAs1, ok},
  311. TestMsg = "Test message" ++ eol(),
  312. ?assertMatch([_, "[debug]", TestMsg], re:split(Msg1, " ", [{return, list}, {parts, 3}]))
  313. after
  314. 1000 ->
  315. ?assert(false)
  316. end,
  317. %% info is blacklisted
  318. lager:info("Test message"),
  319. receive
  320. {io_request, From2, ReplyAs2, {put_chars, unicode, _Msg2}} ->
  321. From2 ! {io_reply, ReplyAs2, ok},
  322. ?assert(false)
  323. after
  324. 500 ->
  325. ?assert(true)
  326. end
  327. end
  328. },
  329. {"whitelisting a loglevel works",
  330. fun() ->
  331. Pid = spawn(F(self())),
  332. unregister(user),
  333. register(user, Pid),
  334. gen_event:add_handler(lager_event, lager_console_backend, info),
  335. lager_config:set(loglevel, {element(2, lager_util:config_to_mask(info)), []}),
  336. lager:set_loglevel(lager_console_backend, '=debug'),
  337. erlang:group_leader(Pid, whereis(lager_event)),
  338. lager:debug("Test message"),
  339. receive
  340. {io_request, From1, ReplyAs1, {put_chars, unicode, Msg1}} ->
  341. From1 ! {io_reply, ReplyAs1, ok},
  342. TestMsg = "Test message" ++ eol(),
  343. ?assertMatch([_, "[debug]", TestMsg], re:split(Msg1, " ", [{return, list}, {parts, 3}]))
  344. after
  345. 1000 ->
  346. ?assert(false)
  347. end,
  348. %% info is blacklisted
  349. lager:error("Test message"),
  350. receive
  351. {io_request, From2, ReplyAs2, {put_chars, unicode, _Msg2}} ->
  352. From2 ! {io_reply, ReplyAs2, ok},
  353. ?assert(false)
  354. after
  355. 500 ->
  356. ?assert(true)
  357. end
  358. end
  359. }
  360. ]
  361. }.
  362. set_loglevel_test_() ->
  363. {foreach,
  364. fun() ->
  365. error_logger:tty(false),
  366. application:load(lager),
  367. application:set_env(lager, handlers, [{lager_console_backend, info}]),
  368. application:set_env(lager, error_logger_redirect, false),
  369. lager:start()
  370. end,
  371. fun(_) ->
  372. application:stop(lager),
  373. application:stop(goldrush),
  374. error_logger:tty(true)
  375. end,
  376. [
  377. {"Get/set loglevel test",
  378. fun() ->
  379. ?assertEqual(info, lager:get_loglevel(lager_console_backend)),
  380. lager:set_loglevel(lager_console_backend, debug),
  381. ?assertEqual(debug, lager:get_loglevel(lager_console_backend)),
  382. lager:set_loglevel(lager_console_backend, '!=debug'),
  383. ?assertEqual(info, lager:get_loglevel(lager_console_backend)),
  384. lager:set_loglevel(lager_console_backend, '!=info'),
  385. ?assertEqual(debug, lager:get_loglevel(lager_console_backend)),
  386. ok
  387. end
  388. },
  389. {"Get/set invalid loglevel test",
  390. fun() ->
  391. ?assertEqual(info, lager:get_loglevel(lager_console_backend)),
  392. ?assertEqual({error, bad_log_level},
  393. lager:set_loglevel(lager_console_backend, fatfinger)),
  394. ?assertEqual(info, lager:get_loglevel(lager_console_backend))
  395. end
  396. }
  397. ]
  398. }.
  399. -endif.