You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by jh...@apache.org on 2013/02/11 06:43:17 UTC
[3/8] git commit: Write to the view server log file if needed
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/d82c1508
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/d82c1508
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/d82c1508
Branch: refs/heads/1677-feature-query_server_log_file
Commit: d82c1508f453e07071a2ab64ee09a46e03969c3c
Parents: a94ff59
Author: Jason Smith (work) <jh...@iriscouch.com>
Authored: Mon Feb 11 05:29:24 2013 +0000
Committer: Jason Smith (work) <jh...@iriscouch.com>
Committed: Mon Feb 11 05:29:24 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/d82c1508/src/couchdb/couch_log.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_log.erl b/src/couchdb/couch_log.erl
index 2e9a351..86d9bc8 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, query_server/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}).
+query_server(Port, Message) ->
+ MessageBin = couch_util:to_binary(Message),
+ {ConsoleMsg, FileMsg, QueryFileMsg} =
+ get_query_server_messages(self(), info, Port, MessageBin),
+ gen_event:sync_notify(error_logger,
+ {couch_query_server, ConsoleMsg, FileMsg, QueryFileMsg}).
+
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_query_server, ConMsg, FileMsg, QueryFileMsg}, State) ->
+ log_query_server(State, ConMsg, FileMsg, QueryFileMsg),
+ {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_query_server(#state{fd=Fd, query_srv_fd=QueryFd}=State, ConsoleMsg, FileMsg, QueryMsg) ->
+ log(State, ConsoleMsg, FileMsg),
+ case QueryFd of
+ Fd -> ok;
+ _ -> ok = io:put_chars(QueryFd, QueryMsg)
+ 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_query_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],
+ QueryFileMsg = <<Message/binary, "\n">>,
+ {ConsoleMsg, FileMsg, QueryFileMsg}.
+
% 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/d82c1508/src/couchdb/couch_os_process.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_os_process.erl b/src/couchdb/couch_os_process.erl
index 3a267be..38fe611 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
- ?LOG_INFO("OS Process ~p Log :: ~s", [OsProc#os_proc.port, Msg]),
+ couch_log:query_server(OsProc#os_proc.port, Msg),
readjson(OsProc);
[<<"error">>, Id, Reason] ->
throw({error, {couch_util:to_existing_atom(Id),Reason}});