Skip to content

Commit

Permalink
fixing several bugs surrounding deployment and reading log files from…
Browse files Browse the repository at this point in the history
… disk
  • Loading branch information
Jacob Vorreuter committed Jan 25, 2010
1 parent 892a2d8 commit 9202828
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 16 deletions.
16 changes: 14 additions & 2 deletions Makefile
@@ -1,11 +1,23 @@
VERSION=0.4

all: compile

compile:
(cd lib/log_roller;$(MAKE))
(cd lib/log_roller_server;$(MAKE))
(cd lib/log_roller_web;$(MAKE))
(cd lib/log_roller_web;$(MAKE))

clean:
(cd lib/log_roller;$(MAKE) clean)
(cd lib/log_roller_server;$(MAKE) clean)
(cd lib/log_roller_web;$(MAKE) clean)
(cd lib/log_roller_web;$(MAKE) clean)

install:
(cd lib/log_roller;$(MAKE) install $(prefix))
(cd lib/log_roller_server;$(MAKE) install $(prefix))
(cd lib/log_roller_web;$(MAKE) install $(prefix))

package: clean
@mkdir log_roller-$(VERSION)/ && cp -rf lib Makefile README.markdown log_roller-$(VERSION)
@COPYFILE_DISABLE=true tar zcf log_roller-$(VERSION).tgz log_roller-$(VERSION)
@rm -rf log_roller-$(VERSION)/
6 changes: 6 additions & 0 deletions lib/log_roller/Makefile
Expand Up @@ -17,3 +17,9 @@ rel: compile

clean:
rm -rf ebin/*.beam ebin/*.app doc/*.html doc/*.png doc/*-info doc/*.css bin/*.boot bin/*.rel bin/*.script Mnesia* erl_crash.dump *.tgz *.1 *.idx *.siz tmp

install:
mkdir -p $(prefix)/$(LIBDIR)/log_roller-$(VERSION)/{ebin,include}
mkdir -p $(prefix)/$(ROOTDIR)/bin
for i in ebin/*.beam include/* ebin/*.app; do install $$i $(prefix)/$(LIBDIR)/log_roller-$(VERSION)/$$i ; done
cp bin/*.boot $(prefix)/$(ROOTDIR)/bin/
8 changes: 8 additions & 0 deletions lib/log_roller_server/Makefile
Expand Up @@ -17,3 +17,11 @@ rel: compile

clean:
rm -rf ebin/*.beam ebin/*.app doc/*.html doc/*.png doc/*-info doc/*.css bin/*.boot bin/*.rel bin/*.script Mnesia* erl_crash.dump *.tgz *.1 *.idx *.siz tmp

install:
mkdir -p $(prefix)/$(LIBDIR)/log_roller_server-$(VERSION)/ebin
mkdir -p $(prefix)/$(ROOTDIR)/bin
for i in ebin/*.beam ebin/*.app; do install $$i $(prefix)/$(LIBDIR)/log_roller_server-$(VERSION)/$$i ; done
cp bin/*.boot $(prefix)/$(ROOTDIR)/bin/
@mkdir -p $(prefix)/etc/init.d
cp log_roller $(prefix)/etc/init.d/
8 changes: 4 additions & 4 deletions lib/log_roller_server/log_roller
Expand Up @@ -9,23 +9,23 @@ ARG3=${5}
HOSTNAME=`case \`uname\` in Darwin ) echo \`hostname\`;; * ) echo \`hostname --fqdn\`;; esac`

get_root() {
echo `erl -eval 'io:format("~s~n", [case code:lib_dir("log_roller") of {error,_} -> ""; S -> S end])' -s init stop -noshell`
echo `erl -eval 'io:format("~s~n", [case code:lib_dir("log_roller_server") of {error,_} -> ""; S -> S end])' -s init stop -noshell`
}

get_sasl() {
echo "-sasl sasl_error_logger false -sasl errlog_type all -sasl error_logger_mf_dir \"/var/log/log_roller\" -sasl error_logger_mf_maxbytes 1048576 -sasl error_logger_mf_maxfiles 1"
}

dev_server() {
erl -pa ebin -name log_roller@`hostname` +W w +A 1 -config priv/dev -boot bin/log_roller_server
erl -pa ebin -name log_roller@`hostname` +W w +A 1 -config priv/dev -boot log_roller_web
}

console_server() {
erl -name log_roller@$HOSTNAME +W w +A 1 -config $(get_root)/priv/log_roller -boot log_roller_server $(get_sasl)
erl -name log_roller@$HOSTNAME +W w +A 1 -config $(get_root)/priv/log_roller -boot log_roller_web $(get_sasl)
}

start_server() {
erl -detached -name log_roller@$HOSTNAME +W w +A 1 -config $(get_root)/priv/log_roller -boot log_roller_server -noshell $(get_sasl)
erl -detached -name log_roller@$HOSTNAME +W w +A 1 -config $(get_root)/priv/log_roller -boot log_roller_web -noshell $(get_sasl)
}

dev(){
Expand Down
9 changes: 5 additions & 4 deletions lib/log_roller_server/src/lr_read_from_disk.erl
Expand Up @@ -25,6 +25,7 @@
-author('jacob.vorreuter@gmail.com').

-export([start_continuation/2, terms/1]).
-compile(export_all).

-include_lib("kernel/include/file.hrl").
-include("log_roller.hrl").
Expand Down Expand Up @@ -55,9 +56,9 @@ terms(Cont) ->
%% while traveling backward through the log files. If the timestamp
%% jumps foreward that means all log files have been traversed.
case is_full_cycle(Timestamp1, Timestamp2) of
true ->
true when length(Terms) > 0 ->
exit({error, read_full_cycle});
false ->
_ ->
{ok, Cont2} = rewind_location(Cont1),
{ok, Cont2, Terms}
end.
Expand Down Expand Up @@ -112,7 +113,7 @@ read_chunk_from_file(#continuation{state=State}=Cont) ->
BinChunk = list_to_binary(Chunk),
BinRem = State#cstate.binary_remainder,
Bin = <<BinChunk/binary, BinRem/binary>>,
{ok, Terms, BinRem1, LTimestamp1} = parse_terms(Bin, <<>>, [], ?DEFAULT_TIMESTAMP),
{ok, Terms, BinRem1, LTimestamp1} = parse_terms(Bin, <<>>, [], State#cstate.last_timestamp),
Index = State#cstate.index,
Pos = State#cstate.position,
State1 = State#cstate{last_timestamp=LTimestamp1, binary_remainder=BinRem1},
Expand Down Expand Up @@ -184,7 +185,7 @@ rewind_location(#continuation{properties=Props, state=State}=Cont) ->
{ok, Cont#continuation{properties=Props1, state=State1}};
true -> %% more than a chunk's worth left
Pos1 = snap_to_grid(Pos - ?MAX_CHUNK_SIZE),
Props1 = Props#cprops{chunk_size=(Pos-Pos1)},
Props1 = Props#cprops{chunk_size=?MAX_CHUNK_SIZE},
State1 = State#cstate{position=Pos1},
{ok, Cont#continuation{properties=Props1, state=State1}}
end.
Expand Down
4 changes: 2 additions & 2 deletions lib/log_roller_server/src/lr_write_to_disk.erl
Expand Up @@ -125,7 +125,7 @@ handle_cast(_Message, State) -> {noreply, State}.
%% Description: Handling all non call/cast messages
%% @hidden
%%--------------------------------------------------------------------
handle_info({log_roller, _Sender, LogEntry}, #state{log=Log, filters=Filters, total_writes=Writes, cache_pid=CachePid}=State) ->
handle_info({log_roller, _Sender, LogEntry}, #state{log=Log, filters=Filters, total_writes=Writes}=State) ->
State1 =
case lr_filter:filter(LogEntry, Filters) of
[] ->
Expand All @@ -139,7 +139,7 @@ handle_info({log_roller, _Sender, LogEntry}, #state{log=Log, filters=Filters, to
end,
{noreply, State1};

handle_info({_,_,_,{wrap,_NumLostItems}}, #state{cache_pid=CachePid}=State) ->
handle_info({_,_,_,{wrap,_NumLostItems}}, State) ->
% CurrentFile = proplists:get_value(current_file, disk_log:info(Log)),
% lr_cache:set_page(CachePid, CurrentFile),
{noreply, State};
Expand Down
8 changes: 7 additions & 1 deletion lib/log_roller_web/Makefile
Expand Up @@ -20,4 +20,10 @@ rel: templates

clean:
rm -rf ebin/*.beam ebin/*.app doc/*.html doc/*.png doc/*-info doc/*.css bin/*.boot bin/*.rel bin/*.script Mnesia* erl_crash.dump *.tgz *.1 *.idx *.siz tmp


install:
mkdir -p $(prefix)/$(LIBDIR)/log_roller_web-$(VERSION)/{ebin,public}
mkdir -p $(prefix)/$(ROOTDIR)/bin
for i in ebin/*.beam ebin/*.app; do install $$i $(prefix)/$(LIBDIR)/log_roller_web-$(VERSION)/$$i ; done
cp -r public/* $(prefix)/$(LIBDIR)/log_roller_web-$(VERSION)/public/
cp bin/*.boot $(prefix)/$(ROOTDIR)/bin/
2 changes: 1 addition & 1 deletion lib/log_roller_web/ebin/log_roller_web.app.in
Expand Up @@ -12,7 +12,7 @@ ${MODULES}
]},
{registered, []},
{mod, {log_roller_web, []}},
{applications, [kernel, stdlib, mochiweb]},
{applications, [kernel, stdlib, mochiweb, log_roller_server]},
{start_phases, [{world, []}, {pg2, []}]}
]}.
EOF
1 change: 1 addition & 0 deletions lib/log_roller_web/src/log_roller_web.erl
Expand Up @@ -65,6 +65,7 @@ build_rel(AppVsn) ->
log_roller_utils:get_app_version(erts),
[log_roller_utils:get_app_version(AppName) || AppName <- Apps] ++ [
{mochiweb, "0.2"},
{log_roller_server, AppVsn},
{?MODULE, AppVsn}
]
},
Expand Down
6 changes: 4 additions & 2 deletions lib/log_roller_web/src/lr_web_server.erl
Expand Up @@ -34,7 +34,9 @@ start_link(Args) when is_list(Args) ->
Port = get_arg_value(port, Args, ?DEFAULT_PORT),
DocRoot = get_arg_value(doc_root, Args),
Loop = fun (Req) -> ?MODULE:loop(Req, DocRoot) end,
mochiweb_http:start([{loop, Loop}, {ip, Address}, {port, Port}]).
Res = mochiweb_http:start([{loop, Loop}, {ip, Address}, {port, Port}]),
io:format("mochiweb_http:start ~p, ~p, ~p: ~p~n", [Address, Port, DocRoot, Res]),
Res.

loop(Req, DocRoot) ->
PathTokens = [Req:get(method)|string:tokens(Req:get(path), "/")],
Expand Down Expand Up @@ -194,5 +196,5 @@ dict_val(types, Val) -> [list_to_atom(Val), list_to_atom(Val ++ "_report")];
dict_val(nodes, Val) -> [list_to_atom(Val)];
dict_val(grep, Val) -> Val.

get_nodes(Server) ->
get_nodes(_Server) ->
lists:sort([node()|nodes()]).

0 comments on commit 9202828

Please sign in to comment.