Skip to content
This repository
Browse code

Merge pull request #68 from thomasc/fix/direct-console-logger-to-user

Direct the console logger output to user
  • Loading branch information...
commit c7133603ccdcf37462fb2639073c284f9a69a015 2 parents 7a882db + 938d351
Andrew Thompson authored August 09, 2012

Showing 1 changed file with 17 additions and 7 deletions. Show diff stats Hide diff stats

  1. 24  src/lager_console_backend.erl
24  src/lager_console_backend.erl
@@ -70,9 +70,9 @@ handle_event({log, Dest, Level, {Date, Time}, [LevelStr, Location, Message]},
70 70
         true ->
71 71
             case Verbose of
72 72
                 true ->
73  
-                    io:put_chars([Date, " ", Time, " ", LevelStr, Location, Message, "\r\n"]);
  73
+                    io:put_chars(user, [Date, " ", Time, " ", LevelStr, Location, Message, "\r\n"]);
74 74
                 _ ->
75  
-                    io:put_chars([Time, " ", LevelStr, Message, "\r\n"])
  75
+                    io:put_chars(user, [Time, " ", LevelStr, Message, "\r\n"])
76 76
             end,
77 77
             {ok, State};
78 78
         false ->
@@ -82,9 +82,9 @@ handle_event({log, Level, {Date, Time}, [LevelStr, Location, Message]},
82 82
   #state{level=LogLevel, verbose=Verbose} = State) when Level =< LogLevel ->
83 83
     case Verbose of
84 84
         true ->
85  
-            io:put_chars([Date, " ", Time, " ", LevelStr, Location, Message, "\r\n"]);
  85
+            io:put_chars(user, [Date, " ", Time, " ", LevelStr, Location, Message, "\r\n"]);
86 86
         _ ->
87  
-            io:put_chars([Time, " ", LevelStr, Message, "\r\n"])
  87
+            io:put_chars(user, [Time, " ", LevelStr, Message, "\r\n"])
88 88
     end,
89 89
     {ok, State};
90 90
 handle_event(_Event, State) ->
@@ -121,7 +121,6 @@ console_log_test_() ->
121 121
                     YComb(YComb)
122 122
             end
123 123
     end,
124  
-
125 124
     {foreach,
126 125
         fun() ->
127 126
                 error_logger:tty(false),
@@ -130,9 +129,12 @@ console_log_test_() ->
130 129
                 application:set_env(lager, error_logger_redirect, false),
131 130
                 application:start(compiler),
132 131
                 application:start(syntax_tools),
133  
-                application:start(lager)
  132
+                application:start(lager),
  133
+                whereis(user)
134 134
         end,
135  
-        fun(_) ->
  135
+        fun(User) ->
  136
+                unregister(user),
  137
+                register(user, User),
136 138
                 application:stop(lager),
137 139
                 error_logger:tty(true)
138 140
         end,
@@ -141,6 +143,8 @@ console_log_test_() ->
141 143
                 fun() ->
142 144
                         Pid = spawn(F(self())),
143 145
                         gen_event:add_handler(lager_event, lager_console_backend, info),
  146
+                        unregister(user),
  147
+                        register(user, Pid),
144 148
                         erlang:group_leader(Pid, whereis(lager_event)),
145 149
                         lager:log(info, self(), "Test message"),
146 150
                         receive
@@ -156,6 +160,8 @@ console_log_test_() ->
156 160
             {"verbose console logging",
157 161
                 fun() ->
158 162
                         Pid = spawn(F(self())),
  163
+                        unregister(user),
  164
+                        register(user, Pid),
159 165
                         erlang:group_leader(Pid, whereis(lager_event)),
160 166
                         gen_event:add_handler(lager_event, lager_console_backend, [info, true]),
161 167
                         lager:log(info, self(), "Test message"),
@@ -173,6 +179,8 @@ console_log_test_() ->
173 179
             {"tracing should work",
174 180
                 fun() ->
175 181
                         Pid = spawn(F(self())),
  182
+                        unregister(user),
  183
+                        register(user, Pid),
176 184
                         gen_event:add_handler(lager_event, lager_console_backend, info),
177 185
                         erlang:group_leader(Pid, whereis(lager_event)),
178 186
                         lager_mochiglobal:put(loglevel, {?INFO, []}),
@@ -200,6 +208,8 @@ console_log_test_() ->
200 208
             {"tracing doesn't duplicate messages",
201 209
                 fun() ->
202 210
                         Pid = spawn(F(self())),
  211
+                        unregister(user),
  212
+                        register(user, Pid),
203 213
                         gen_event:add_handler(lager_event, lager_console_backend, info),
204 214
                         lager_mochiglobal:put(loglevel, {?INFO, []}),
205 215
                         erlang:group_leader(Pid, whereis(lager_event)),

0 notes on commit c713360

Please sign in to comment.
Something went wrong with that request. Please try again.