Permalink
Browse files

[bp] Add a possibility to specify certain log to browse.

Originally reviewed on http://review.couchbase.org/9378

Conflicts:

	cbbrowse_logs.in

Change-Id: I38c1227a7a79e4f044efe836f069e3e6f1543a16
Reviewed-on: http://review.couchbase.org/13538
Tested-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
  • Loading branch information...
1 parent 203fec1 commit dbcf5cf30f8810d59f86548193c33dc3cfeaf2eb @aartamonau aartamonau committed with alk Sep 2, 2011
Showing with 63 additions and 23 deletions.
  1. +8 −1 cbbrowse_logs.in
  2. +15 −3 cbbrowse_logs_cluster
  3. +40 −19 src/ns_log_browser.erl
View
@@ -8,4 +8,11 @@ export PATH
ERL_LIBS="@PREFIX@/lib/couchdb/erlang/lib:@PREFIX@/lib/ns_server/erlang/lib"
export ERL_LIBS
-exec erl -pa ebin -noshell -run ns_log_browser -report_dir "@PREFIX@/var/lib/couchbase/logs" -run init stop -- "$@"
+if [ x"$1" != "x" ]
+then
+ extra_args="-log $1"
+fi
+
+exec erl -pa ebin -noshell -run ns_log_browser \
+ -report_dir "@PREFIX@/var/lib/couchbase/logs" ${extra_args} \
+ -run init stop -- "$@"
View
@@ -6,11 +6,17 @@ progname=`basename $0`
usage() {
cat 1>&2 <<EOF
-Usage: ${progname} <node>
+Usage: ${progname} <node> [logname]
- Example: To dump the logs for node 0, try running the following command
+ Examples:
+
+ To dump the logs for node 0, try running the following command
${0} n_0
+
+ To dump the error log for node 0, try running the following command
+
+ ${0} n_0 errors
EOF
exit 1
}
@@ -28,5 +34,11 @@ then
exit 1
fi
+if [ x"$2" != "x" ]
+then
+ extra_args="-log $2"
+fi
+
exec erl -pa ebin -noshell \
- -run ns_log_browser -report_dir logs/"$1" -run init stop -- "$@"
+ -run ns_log_browser -report_dir logs/"$1" ${extra_args} \
+ -run init stop -- "$@"
@@ -1,7 +1,8 @@
-module(ns_log_browser).
-export([start/0]).
--export([stream_logs/1, stream_logs/2, stream_logs/3]).
+-export([log_exists/1, log_exists/2]).
+-export([stream_logs/1, stream_logs/2, stream_logs/3, stream_logs/4]).
-include("ns_common.hrl").
@@ -12,12 +13,13 @@ usage(Fmt, Args) ->
-spec usage() -> no_return().
usage() ->
- io:format("Usage: <progname> -report_dir <dir>~n"),
+ io:format("Usage: <progname> -report_dir <dir> [-log <name>]~n"),
halt(1).
start() ->
Options = case parse_arguments([{h, 0, undefined, false},
- {report_dir, 1, undefined}],
+ {report_dir, 1, undefined},
+ {log, 1, undefined, ?DEFAULT_LOG_FILENAME}],
init:get_arguments()) of
{ok, O} ->
O;
@@ -27,22 +29,28 @@ start() ->
usage("option ~p requires ~p arguments~n", [K, N]);
Error -> usage("parse error: ~p~n", [Error])
end,
+
case proplists:get_value(h, Options) of
true -> usage();
false -> ok
end,
Dir = proplists:get_value(report_dir, Options),
-
- stream_logs(Dir,
- fun (Data) ->
- %% originally standard_io was used here
- %% instead of group_leader(); though this is
- %% perfectly valid (e.g. this tested in
- %% otp/lib/kernel/tests/file_SUITE.erl) it makes
- %% dialyzer unhappy
- file:write(group_leader(), Data)
- end).
-
+ Log = proplists:get_value(log, Options),
+
+ case log_exists(Dir, Log) of
+ true ->
+ stream_logs(Dir, Log,
+ fun (Data) ->
+ %% originally standard_io was used here
+ %% instead of group_leader(); though this is
+ %% perfectly valid (e.g. this tested in
+ %% otp/lib/kernel/tests/file_SUITE.erl) it makes
+ %% dialyzer unhappy
+ file:write(group_leader(), Data)
+ end);
+ false ->
+ usage("Requested log file ~p does not exist.~n", [Log])
+ end.
%% Option parser
map_args(K, N, undefined, D, A) ->
@@ -89,15 +97,28 @@ parse_arguments(Opts, Args) ->
error:{parse_error, Reason, K, A} -> {parse_error, Reason, K, A}
end.
+log_exists(Log) ->
+ {ok, Dir} = application:get_env(error_logger_mf_dir),
+ log_exists(Dir, Log).
+
+log_exists(Dir, Log) ->
+ Path = filename:join(Dir, Log),
+ IdxPath = lists:append(Path, ".idx"),
+
+ filelib:is_regular(IdxPath).
+
stream_logs(Fn) ->
+ stream_logs(?DEFAULT_LOG_FILENAME, Fn).
+
+stream_logs(Log, Fn) ->
{ok, Dir} = application:get_env(error_logger_mf_dir),
- stream_logs(Dir, Fn).
+ stream_logs(Dir, Log, Fn).
-stream_logs(Dir, Fn) ->
- stream_logs(Dir, Fn, 65536).
+stream_logs(Dir, Log, Fn) ->
+ stream_logs(Dir, Log, Fn, 65536).
-stream_logs(Dir, Fn, ChunkSz) ->
- Path = filename:join(Dir, ?DEFAULT_LOG_FILENAME),
+stream_logs(Dir, Log, Fn, ChunkSz) ->
+ Path = filename:join(Dir, Log),
{Ix, _, _, NFiles} = disk_log_1:read_index_file(Path),
Ixs = lists:seq(Ix + 1, NFiles) ++ lists:seq(1, Ix),

0 comments on commit dbcf5cf

Please sign in to comment.