Skip to content

Commit

Permalink
Bugfix: accept UTC.
Browse files Browse the repository at this point in the history
  • Loading branch information
vjache committed May 9, 2012
1 parent 0850229 commit b956218
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
4 changes: 2 additions & 2 deletions dev.config
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
{archive_after, {7, day}}, % Recorder will move & zip logs older than this
% (if not specified explicitely then archive
% directory will be './errlogs/archive' i.e.
% relative to <'dir' property value>+/+'archive')
{locate_em, error_logger} % Locator will seek event managers registered
% relative to <'dir' property value> +/+'archive')
{locate_em, {local,error_logger}} % Locator will seek event managers registered
% with this name on each visible node in a cluster
]}
]}
Expand Down
4 changes: 3 additions & 1 deletion include/types.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@
[{ InstanceName :: atom(), % Instance section
[instance_config_item()]}] % Instance specific properties
}
]} .
]} .

-define(IS_TIMESTAMP(T), (is_integer(element(1,T)) andalso is_integer(element(2,T)) andalso is_integer(element(3,T)))).
2 changes: 1 addition & 1 deletion src/logmachine.app.src
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%% -*- mode: erlang; -*-
{application, logmachine,
[{description, "An Erlang Log Machine"},
{vsn, "0.0.11"},
{vsn, "0.0.12"},
{registered, []},
{build_dependencies, []},
{env, []},
Expand Down
8 changes: 5 additions & 3 deletions src/logmachine.erl
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ subscribe(InstanceName, FromTimestamp, SubPid, Marker, MatchSpec) ->
%%-------------------------------------------------------------------------------
-spec get_zlist(InstanceName :: atom(),
FromTimestamp :: timestamp()) -> zlists:zlist(history_entry()).
get_zlist(InstanceName, FromTimestamp) ->
get_zlist(InstanceName, FromTimestamp) when ?IS_TIMESTAMP(FromTimestamp) ->
case logmachine_cache_srv:get_interval(InstanceName) of
% If fits into RAM
{From, _To} when From =< FromTimestamp ->
{From, _To} when From =< FromTimestamp, ?IS_TIMESTAMP(From) ->
logmachine_cache_srv:get_history(InstanceName, FromTimestamp);
% Otherwise read from disk log
_ ->
Expand All @@ -108,7 +108,9 @@ get_zlist(InstanceName, FromTimestamp) ->
% Exclude last element
zlists:dropwhile(fun(E1) -> E==E1 end, ZList)
end)
end.
end;
get_zlist(InstanceName, {{_,_,_},{_,_,_},_}=FromTimestamp) ->
get_zlist(InstanceName, logmachine_util:utc_to_now(FromTimestamp)).

%%-------------------------------------------------------------------------------
%% @doc
Expand Down
5 changes: 2 additions & 3 deletions src/logmachine_recorder_srv.erl
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,10 @@ get_history(InstanceName, FromTimestamp, ToTimestamp) ->
From :: timestamp()) -> zlists:zlist(history_entry()) .
get_history(InstanceName, From) ->
LogDir=get_data_dir(InstanceName),
FromLT=to_long_timestamp(From),
LogFilesToScan=get_log_files(InstanceName, FromLT),
LogFilesToScan=get_log_files(InstanceName, From),
%% ?ECHO({"LOGS_TO_SCAN",zlists:expand(LogFilesToScan)}),
zlists:dropwhile(
fun({T,_})-> to_long_timestamp(T) < FromLT end,
fun({T,_})-> T < From end,
zlists:generate(
LogFilesToScan,
fun(Filename)->
Expand Down
16 changes: 15 additions & 1 deletion src/logmachine_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@
%%
%% Exported Functions
%%
-export([make_name/1, to_millis/1, now_to_millis/1,millis_to_now/1, send_after/2, ensure_dir/1]).
-export([make_name/1,
to_millis/1,
now_to_millis/1,
millis_to_now/1,
send_after/2,
ensure_dir/1,
utc_to_ms1970/1,
utc_to_now/1]).

%%
%% API Functions
%%
-define(SEC1970, 62167219200).

ensure_dir(Dir) ->
case filelib:ensure_dir(filename:join(Dir, "fake")) of
Expand Down Expand Up @@ -68,6 +76,12 @@ to_millis({N,hms}) ->
send_after(Period, Message) ->
{ok,_}=timer:send_after(to_millis(Period), Message).

utc_to_ms1970({{Year,Month,Day}, {Hour,Min,Sec}, Mls}) ->
(calendar:datetime_to_gregorian_seconds({{Year,Month,Day},{Hour,Min,Sec}}) - ?SEC1970)*1000 + Mls.

utc_to_now(UTC) ->
millis_to_now(utc_to_ms1970(UTC)).

%%
%% Local Functions
%%
Expand Down

0 comments on commit b956218

Please sign in to comment.