Updated Branches: refs/heads/console_log bbf0f59f0 -> 32919befd (forced update)
Write to the view server log file if needed Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/32919bef Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/32919bef Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/32919bef Branch: refs/heads/console_log Commit: 32919befdd85c283f8893e6f6df36f47b68c91de Parents: 4997b78 Author: Jason Smith (work) <[email protected]> Authored: Sat Feb 2 15:31:37 2013 +0000 Committer: Jason Smith (work) <[email protected]> Committed: Sat Feb 2 15:31:37 2013 +0000 ---------------------------------------------------------------------- src/couchdb/couch_log.erl | 26 +++++++++++++++++++++++++- src/couchdb/couch_os_process.erl | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/32919bef/src/couchdb/couch_log.erl ---------------------------------------------------------------------- diff --git a/src/couchdb/couch_log.erl b/src/couchdb/couch_log.erl index 7d7ed0a..714f92c 100644 --- a/src/couchdb/couch_log.erl +++ b/src/couchdb/couch_log.erl @@ -15,7 +15,7 @@ % public API -export([start_link/0, stop/0]). --export([debug/2, info/2, warn/2, error/2]). +-export([debug/2, info/2, warn/2, error/2, view/2]). -export([debug_on/0, info_on/0, warn_on/0, get_level/0, get_level_integer/0, set_level/1]). -export([debug_on/1, info_on/1, warn_on/1, get_level/1, get_level_integer/1, set_level/2]). -export([read/2]). @@ -52,6 +52,13 @@ error(Format, Args) -> {ConsoleMsg, FileMsg} = get_log_messages(self(), error, Format, Args), gen_event:sync_notify(error_logger, {couch_error, ConsoleMsg, FileMsg}). +view(Port, Message) -> + MessageBin = couch_util:to_binary(Message), + {ConsoleMsg, FileMsg, ViewFileMsg} = + get_view_server_messages(self(), info, Port, MessageBin), + gen_event:sync_notify(error_logger, + {couch_view_server, ConsoleMsg, FileMsg, ViewFileMsg}). + level_integer(error) -> ?LEVEL_ERROR; level_integer(warn) -> ?LEVEL_WARN; @@ -202,6 +209,9 @@ handle_event({couch_info, ConMsg, FileMsg}, State) -> handle_event({couch_debug, ConMsg, FileMsg}, State) -> log(State, ConMsg, FileMsg), {ok, State}; +handle_event({couch_view_server, ConMsg, FileMsg, ViewFileMsg}, State) -> + log_view(State, ConMsg, FileMsg, ViewFileMsg), + {ok, State}; handle_event({error_report, _, {Pid, _, _}}=Event, #state{sasl = true} = St) -> {ConMsg, FileMsg} = get_log_messages(Pid, error, "~p", [Event]), log(St, ConMsg, FileMsg), @@ -234,12 +244,26 @@ log(#state{fd = Fd}, ConsoleMsg, FileMsg) -> ok = io:put_chars(ConsoleMsg), ok = io:put_chars(Fd, FileMsg). +log_view(#state{fd=Fd, view_fd=ViewFd}=State, ConsoleMsg, FileMsg, ViewMsg) -> + log(State, ConsoleMsg, FileMsg), + case ViewFd of + Fd -> ok; + _ -> ok = io:put_chars(ViewFd, ViewMsg) + end. + get_log_messages(Pid, Level, Format, Args) -> ConsoleMsg = unicode:characters_to_binary(io_lib:format( "[~s] [~p] " ++ Format ++ "~n", [Level, Pid | Args])), FileMsg = ["[", couch_util:rfc1123_date(), "] ", ConsoleMsg], {ConsoleMsg, iolist_to_binary(FileMsg)}. +get_view_server_messages(Pid, Level, Port, Message) -> + ConsoleMsg = unicode:characters_to_binary(io_lib:format( + "[~s] [~p] OS Process ~p Log :: ~s~n", [Level, Pid, Port, Message])), + FileMsg = ["[", couch_util:rfc1123_date(), "] ", ConsoleMsg], + ViewFileMsg = Message, + {ConsoleMsg, FileMsg, ViewFileMsg}. + % Read Bytes bytes from the end of log file, jumping Offset bytes towards % the beginning of the file first. http://git-wip-us.apache.org/repos/asf/couchdb/blob/32919bef/src/couchdb/couch_os_process.erl ---------------------------------------------------------------------- diff --git a/src/couchdb/couch_os_process.erl b/src/couchdb/couch_os_process.erl index dafdc9e..8b5cedd 100644 --- a/src/couchdb/couch_os_process.erl +++ b/src/couchdb/couch_os_process.erl @@ -142,7 +142,7 @@ readjson(OsProc) when is_record(OsProc, os_proc) -> case ?JSON_DECODE(Line) of [<<"log">>, Msg] when is_binary(Msg) -> % we got a message to log. Log it and continue - couch_log:view(Msg), + couch_log:view(OsProc#os_proc.port, Msg), readjson(OsProc); [<<"error">>, Id, Reason] -> throw({error, {couch_util:to_existing_atom(Id),Reason}});
