Skip to content

Commit

Permalink
Merge pull request #20 from Kyorai/mk-switch-to-otp-logger
Browse files Browse the repository at this point in the history
Replace Lager with OTP logger
  • Loading branch information
michaelklishin authored Mar 8, 2021
2 parents 56bc1b1 + 3bd988c commit 08c28fa
Show file tree
Hide file tree
Showing 19 changed files with 269 additions and 600 deletions.
36 changes: 36 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Cuttlefish Change Log

## 3.0.0 (under development)

### OTP Logger Instead of Lager

The library now uses standard OTP logger instead of Lager.

Log entries use a very similar format but the timestamp
formatting has changed.

In older releases with Lager:

```
15:12:26.054 [info] No app.config or vm.args detected in /etc, activating cuttlefish
```

In 3.0, on a cutting edge Erlang version:

```
2021-03-08T15:14:55.963768+03:00 [info] No app.config or vm.args detected in /etc, activating cuttlefish
```

GitHub issue: [#19](https://github.com/Kyorai/cuttlefish/issues/19).


## 2.7.0 (Mar 7, 2021)

### Erlang 24 Support

Cuttlefish is now compatible (builds, runs) with Erlang 24.

### Older Erlang Releases Support Dropped

Cuttlefish now supports Erlang 22 through 24. `2.6.0` was the last
release to support older Erlang versions, e.g. 18 or 19.
3 changes: 3 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
build: off

# Erlang 22.3 is only available in this image
image: "Visual Studio 2019"

install:
- curl -OL https://s3.amazonaws.com/rebar3/rebar3

Expand Down
5 changes: 2 additions & 3 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
{plugins, [rebar3_hex]}.

{erl_opts, [warnings_as_errors,
{parse_transform, lager_transform},
debug_info,
warn_untyped_record]}.

{deps, [getopt, {lager, "~>3.9.1"}]}.
{deps, [getopt]}.

{escript_emu_args, "%%! -escript main cuttlefish_escript +S 1 +A 0\n"}.
{escript_incl_apps, [goldrush, getopt, lager, cuttlefish]}.
{escript_incl_apps, [getopt, cuttlefish]}.
{escript_main_app, cuttlefish}.

{provider_hooks, [{post, [{compile, {default, escriptize}}]}]}.
Expand Down
12 changes: 3 additions & 9 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
{"1.2.0",
[{<<"getopt">>,{pkg,<<"getopt">>,<<"1.0.2">>},0},
{<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.9">>},1},
{<<"lager">>,{pkg,<<"lager">>,<<"3.9.1">>},0}]}.
[{<<"getopt">>,{pkg,<<"getopt">>,<<"1.0.2">>},0}]}.
[
{pkg_hash,[
{<<"getopt">>, <<"33D9B44289FE7AD08627DDFE1D798E30B2DA0033B51DA1B3A2D64E72CD581D02">>},
{<<"goldrush">>, <<"F06E5D5F1277DA5C413E84D5A2924174182FB108DABB39D5EC548B27424CD106">>},
{<<"lager">>, <<"5885BC71308CD38F9D025C8ECDE4E5CCE1CE8565F80BFC6199865C845D6DBE95">>}]},
{<<"getopt">>, <<"33D9B44289FE7AD08627DDFE1D798E30B2DA0033B51DA1B3A2D64E72CD581D02">>}]},
{pkg_hash_ext,[
{<<"getopt">>, <<"A0029AEA4322FB82A61F6876A6D9C66DC9878B6CB61FAA13DF3187384FD4EA26">>},
{<<"goldrush">>, <<"99CB4128CFFCB3227581E5D4D803D5413FA643F4EB96523F77D9E6937D994CEB">>},
{<<"lager">>, <<"3F59BA75A04A99E5F18BF91C89F46DCE536F83C6CB415FE26E6E75A62BEF37DC">>}]}
{<<"getopt">>, <<"A0029AEA4322FB82A61F6876A6D9C66DC9878B6CB61FAA13DF3187384FD4EA26">>}]}
].
2 changes: 1 addition & 1 deletion src/cuttlefish.app.src
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application,cuttlefish,
[{description,"cuttlefish configuration abstraction"},
{vsn,"2.7.0"},
{vsn,"3.0.0"},
{registered,[]},
{applications,[kernel,stdlib]},
{env,[]},
Expand Down
4 changes: 3 additions & 1 deletion src/cuttlefish.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

-module(cuttlefish).

-include_lib("kernel/include/logger.hrl").

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-endif.
Expand Down Expand Up @@ -123,7 +125,7 @@ invalid(Reason) ->
%% being logged.
-spec warn(iodata()) -> ok.
warn(Str) ->
_ = lager:warning(Str, []).
_ = ?LOG_WARNING(Str, []).

-ifdef(TEST).

Expand Down
19 changes: 12 additions & 7 deletions src/cuttlefish_conf.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
%% -------------------------------------------------------------------
-module(cuttlefish_conf).

-include_lib("kernel/include/logger.hrl").

-export([
generate/1,
generate_file/2,
Expand Down Expand Up @@ -168,7 +170,7 @@ generate_element(MappingRecord) ->
case Level of
basic -> ok;
Level ->
_ = lager:warning("{level, ~p} has been deprecated. Use 'hidden' or '{hidden, true}'", [Level])
_ = ?LOG_WARNING("{level, ~p} has been deprecated. Use 'hidden' or '{hidden, true}'", [Level])
end,

case generate_element(Hidden, Level, Default, Commented) of
Expand Down Expand Up @@ -370,24 +372,27 @@ files_incomplete_parse_test() ->
ok.

generate_element_level_advanced_test() ->
cuttlefish_lager_test_backend:bounce(warning),
_ = cuttlefish_test_logging:set_up(),
_ = cuttlefish_test_logging:bounce(warning),
assert_no_output({level, advanced}),
[Log] = cuttlefish_lager_test_backend:get_logs(),
[Log] = cuttlefish_test_logging:get_logs(),
?assertMatch({match, _}, re:run(Log, "{level, advanced} has been deprecated. Use 'hidden' or '{hidden, true}'")),
ok.

generate_element_level_intermediate_test() ->
cuttlefish_lager_test_backend:bounce(warning),
_ = cuttlefish_test_logging:set_up(),
_ = cuttlefish_test_logging:bounce(warning),
assert_no_output({level, intermediate}),
[Log] = cuttlefish_lager_test_backend:get_logs(),
[Log] = cuttlefish_test_logging:get_logs(),
?assertMatch({match, _}, re:run(Log, "{level, intermediate} has been deprecated. Use 'hidden' or '{hidden, true}'")),
ok.

generate_element_hidden_test() ->
cuttlefish_lager_test_backend:bounce(warning),
_ = cuttlefish_test_logging:set_up(),
_ = cuttlefish_test_logging:bounce(warning),
assert_no_output(hidden),
assert_no_output({hidden, true}),
?assertEqual([], cuttlefish_lager_test_backend:get_logs()),
?assertEqual([], cuttlefish_test_logging:get_logs()),
ok.

included_file_test() ->
Expand Down
12 changes: 7 additions & 5 deletions src/cuttlefish_error.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
%% -------------------------------------------------------------------
-module(cuttlefish_error).

-include_lib("kernel/include/logger.hrl").

-type error() :: {'error', {atom(), term()}}.
-type errorlist() :: {'errorlist', [error()]}.
-export_type([error/0, errorlist/0]).
Expand Down Expand Up @@ -177,11 +179,11 @@ print(FormatString, Args) ->
print({error, ErrorTerm}) ->
print(lists:flatten(xlate(ErrorTerm)));
print(String) ->
case _ = lager:error("~s", [String]) of
{error, lager_not_running} ->
io:format("~s~n", [String]),
ok;
ok -> ok
try
?LOG_ERROR("~s", [String])
catch _:_:_ ->
io:format("~s~n", [String]),
ok
end.

-ifdef(TEST).
Expand Down
Loading

0 comments on commit 08c28fa

Please sign in to comment.