From b698760ea3f55bc04a4f34eaaef56cb74c74021f Mon Sep 17 00:00:00 2001 From: SisMaker <1713699517@qq.com> Date: Mon, 1 Feb 2021 21:44:15 +0800 Subject: [PATCH] =?UTF-8?q?ft:=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/formatter/rumFormat.erl | 18 ------------ src/formatter/rumFormatter.erl | 20 +------------ src/misc/rumCrashLog.erl | 20 ------------- src/misc/rumErrLoggerH.erl | 16 ---------- src/misc/rumStdlib.erl | 19 ------------ src/rotator/rumRotatorExm.erl | 20 +++++++------ src/rotator/rumRotatorIns.erl | 53 ++++++++++++++++++---------------- 7 files changed, 40 insertions(+), 126 deletions(-) diff --git a/src/formatter/rumFormat.erl b/src/formatter/rumFormat.erl index bbc75d2..57749ad 100644 --- a/src/formatter/rumFormat.erl +++ b/src/formatter/rumFormat.erl @@ -1,21 +1,3 @@ -%% -%% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1996-2011-2012. All Rights Reserved. -%% -%% The contents of this file are subject to the Erlang Public License, -%% Version 1.1, (the "License"); you may not use this file except in -%% compliance with the License. You should have received a copy of the -%% Erlang Public License along with this software. If not, it can be -%% retrieved online at http://www.erlang.org/. -%% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -%% the License for the specific language governing rights and limitations -%% under the License. -%% -%% %CopyrightEnd% -%% -module(rumFormat). %% fork of io_lib_format that uses trunc_io to protect against large terms diff --git a/src/formatter/rumFormatter.erl b/src/formatter/rumFormatter.erl index a7c236b..1dcde81 100644 --- a/src/formatter/rumFormatter.erl +++ b/src/formatter/rumFormatter.erl @@ -1,25 +1,7 @@ -%% Copyright (c) 2011-2012 Basho Technologies, Inc. All Rights Reserved. -%% -%% This file is provided to you under the Apache License, -%% Version 2.0 (the "License"); you may not use this file -%% except in compliance with the License. You may obtain -%% a copy of the License at -%% -%% http://www.apache.org/licenses/LICENSE-2.0 -%% -%% Unless required by applicable law or agreed to in writing, -%% software distributed under the License is distributed on an -%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -%% KIND, either express or implied. See the License for the -%% specific language governing permissions and limitations -%% under the License. - -module(rumFormatter). -%% -%% Include files -%% -include("eRum.hrl"). + -ifdef(TEST). -include_lib("eunit/include/eunit.hrl"). -endif. diff --git a/src/misc/rumCrashLog.erl b/src/misc/rumCrashLog.erl index b7d75a2..606615c 100644 --- a/src/misc/rumCrashLog.erl +++ b/src/misc/rumCrashLog.erl @@ -1,23 +1,3 @@ -%% ------------------------------------------------------------------- -%% -%% Copyright (c) 2011-2017 Basho Technologies, Inc. -%% -%% This file is provided to you under the Apache License, -%% Version 2.0 (the "License"); you may not use this file -%% except in compliance with the License. You may obtain -%% a copy of the License at -%% -%% http://www.apache.org/licenses/LICENSE-2.0 -%% -%% Unless required by applicable law or agreed to in writing, -%% software distributed under the License is distributed on an -%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -%% KIND, either express or implied. See the License for the -%% specific language governing permissions and limitations -%% under the License. -%% -%% ------------------------------------------------------------------- - %% @doc Lager crash log writer. This module implements a gen_server which writes %% error_logger error messages out to a file in their original format. The %% location to which it logs is configured by the application var `crash_log'. diff --git a/src/misc/rumErrLoggerH.erl b/src/misc/rumErrLoggerH.erl index 6e6fdc7..bb74fb3 100644 --- a/src/misc/rumErrLoggerH.erl +++ b/src/misc/rumErrLoggerH.erl @@ -1,19 +1,3 @@ -%% Copyright (c) 2011-2015 Basho Technologies, Inc. All Rights Reserved. -%% -%% This file is provided to you under the Apache License, -%% Version 2.0 (the "License"); you may not use this file -%% except in compliance with the License. You may obtain -%% a copy of the License at -%% -%% http://www.apache.org/licenses/LICENSE-2.0 -%% -%% Unless required by applicable law or agreed to in writing, -%% software distributed under the License is distributed on an -%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -%% KIND, either express or implied. See the License for the -%% specific language governing permissions and limitations -%% under the License. - %% @doc A error_logger backend for redirecting events into lager. %% Error messages and crash logs are also optionally written to a crash log. diff --git a/src/misc/rumStdlib.erl b/src/misc/rumStdlib.erl index f5166aa..c9067c5 100644 --- a/src/misc/rumStdlib.erl +++ b/src/misc/rumStdlib.erl @@ -1,22 +1,3 @@ -%% -%% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. -%% -%% The contents of this file are subject to the Erlang Public License, -%% Version 1.1, (the "License"); you may not use this file except in -%% compliance with the License. You should have received a copy of the -%% Erlang Public License along with this software. If not, it can be -%% retrieved online at http://www.erlang.org/. -%% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -%% the License for the specific language governing rights and limitations -%% under the License. -%% -%% %CopyrightEnd% -%% - %% @doc Functions from Erlang OTP distribution that are really useful %% but aren't exported. %% diff --git a/src/rotator/rumRotatorExm.erl b/src/rotator/rumRotatorExm.erl index 0c80336..9808cf2 100644 --- a/src/rotator/rumRotatorExm.erl +++ b/src/rotator/rumRotatorExm.erl @@ -1,18 +1,20 @@ -module(rumRotatorExm). %% Create a log file --callback(create_logfile(Name :: list(), Buffer :: {integer(), integer()} | any()) -> - {ok, {file:io_device(), integer(), file:date_time(), integer()}} | {error, any()}). +-callback createLogFile(Name :: list(), Buffer :: {integer(), integer()} | any()) -> + {ok, {file:io_device(), integer(), file:date_time(), integer()}} | + {error, any()}. %% Open a log file --callback(open_logfile(Name :: list(), Buffer :: {integer(), integer()} | any()) -> - {ok, {file:io_device(), integer(), file:date_time(), integer()}} | {error, any()}). +-callback openLogFile(Name :: list(), Buffer :: {integer(), integer()} | any()) -> + {ok, {file:io_device(), integer(), file:date_time(), integer()}} | + {error, any()}. %% Ensure reference to current target, could be rotated --callback(ensure_logfile(Name :: list(), FD :: file:io_device(), Inode :: integer(), Ctime :: file:date_time(), - Buffer :: {integer(), integer()} | any()) -> - {ok, {file:io_device(), integer(), file:date_time(), integer()}} | {error, any()}). +-callback ensureLogFile(Name :: list(), FD :: file:io_device(), Inode :: integer(), CTime :: file:date_time(), Buffer :: {integer(), integer()} | any()) -> + {ok, {file:io_device(), integer(), file:date_time(), integer()}} | + {error, any()}. %% Rotate the log file --callback(rotate_logfile(Name :: list(), Count :: integer()) -> - ok). +-callback rotateLogFile(Name :: list(), Count :: integer()) -> + ok. diff --git a/src/rotator/rumRotatorIns.erl b/src/rotator/rumRotatorIns.erl index 3321a5f..00cb017 100644 --- a/src/rotator/rumRotatorIns.erl +++ b/src/rotator/rumRotatorIns.erl @@ -1,21 +1,24 @@ -module(rumRotatorIns). --include_lib("kernel/include/file.hrl"). - -behaviour(rumRotatorExm). +-include_lib("kernel/include/file.hrl"). + -export([ - create_logfile/2, open_logfile/2, ensure_logfile/5, rotate_logfile/2 + createLogFile/2 + , openLogFile/2 + , ensureLogFile/5 + , rotateLogFile/2 ]). -ifdef(TEST). -include_lib("eunit/include/eunit.hrl"). -endif. -create_logfile(Name, Buffer) -> - open_logfile(Name, Buffer). +createLogFile(Name, Buffer) -> + openLogFile(Name, Buffer). -open_logfile(Name, Buffer) -> +openLogFile(Name, Buffer) -> case filelib:ensure_dir(Name) of ok -> Options = [append, raw] ++ @@ -29,9 +32,9 @@ open_logfile(Name, Buffer) -> case file:read_file_info(Name, [raw]) of {ok, FInfo0} -> Inode = FInfo0#file_info.inode, - {ok, Ctime} = maybe_update_ctime(Name, FInfo0), + {ok, CTime} = maybe_update_ctime(Name, FInfo0), Size1 = FInfo0#file_info.size, - {ok, {FD, Inode, Ctime, Size1}}; + {ok, {FD, Inode, CTime, Size1}}; X -> X end; Y -> Y @@ -39,14 +42,14 @@ open_logfile(Name, Buffer) -> Z -> Z end. -ensure_logfile(Name, undefined, _Inode, _Ctime, Buffer) -> - open_logfile(Name, Buffer); -ensure_logfile(Name, FD, Inode0, Ctime0, Buffer) -> - case rumUtil:has_file_changed(Name, Inode0, Ctime0) of +ensureLogFile(Name, undefined, _Inode, _CTime, Buffer) -> + openLogFile(Name, Buffer); +ensureLogFile(Name, FD, Inode0, CTime0, Buffer) -> + case rumUtil:has_file_changed(Name, Inode0, CTime0) of {true, _FInfo} -> reopen_logfile(Name, FD, Buffer); {_, FInfo} -> - {ok, {FD, Inode0, Ctime0, FInfo#file_info.size}} + {ok, {FD, Inode0, CTime0, FInfo#file_info.size}} end. reopen_logfile(Name, FD0, Buffer) -> @@ -55,8 +58,8 @@ reopen_logfile(Name, FD0, Buffer) -> _ = file:datasync(FD0), _ = file:close(FD0), _ = file:close(FD0), - case open_logfile(Name, Buffer) of - {ok, {_FD1, _Inode, _Size, _Ctime} = FileInfo} -> + case openLogFile(Name, Buffer) of + {ok, {_FD1, _Inode, _Size, _CTime} = FileInfo} -> %% inode changed, file was probably moved and %% recreated {ok, FileInfo}; @@ -65,26 +68,26 @@ reopen_logfile(Name, FD0, Buffer) -> end. %% renames failing are OK -rotate_logfile(File, 0) -> +rotateLogFile(File, 0) -> %% open the file in write-only mode to truncate/create it case file:open(File, [write]) of {ok, FD} -> _ = file:close(FD), _ = file:close(FD), - {ok, _Ctime} = maybe_update_ctime(File), + {ok, _CTime} = maybe_update_ctime(File), ok; Error -> Error end; -rotate_logfile(File0, 1) -> +rotateLogFile(File0, 1) -> File1 = File0 ++ ".0", _ = file:rename(File0, File1), - rotate_logfile(File0, 0); -rotate_logfile(File0, Count) -> + rotateLogFile(File0, 0); +rotateLogFile(File0, Count) -> File1 = File0 ++ "." ++ integer_to_list(Count - 2), File2 = File0 ++ "." ++ integer_to_list(Count - 1), _ = file:rename(File1, File2), - rotate_logfile(File0, Count - 1). + rotateLogFile(File0, Count - 1). maybe_update_ctime(Name) -> case file:read_file_info(Name, [raw]) of @@ -130,7 +133,7 @@ rotate_file_test() -> % creates the file that Inner looks for. % Don't shoot the messenger, it was worse before this refactoring. lists:foreach(Inner, lists:seq(0, Count - 1)), - rotate_logfile(TestLog, RotCount) + rotateLogFile(TestLog, RotCount) end, lists:foreach(Outer, lists:seq(0, (RotCount * 2))), rumUtil:delete_test_dir(TestDir). @@ -139,7 +142,7 @@ rotate_file_zero_count_test() -> %% Test that a rotation count of 0 simply truncates the file {ok, TestDir} = rumUtil:create_test_dir(), TestLog = filename:join(TestDir, "rotation.log"), - ?assertMatch(ok, rotate_logfile(TestLog, 0)), + ?assertMatch(ok, rotateLogFile(TestLog, 0)), ?assertNot(filelib:is_regular(TestLog ++ ".0")), ?assertEqual(true, filelib:is_regular(TestLog)), ?assertEqual(1, length(filelib:wildcard(TestLog ++ "*"))), @@ -167,7 +170,7 @@ rotate_file_fail_test() -> _ -> %% hose up the permissions ok = rumUtil:set_dir_permissions("u-w", TestDir), - ?assertMatch({error, _}, rotate_logfile(TestLog, 10)) + ?assertMatch({error, _}, rotateLogFile(TestLog, 10)) end, %% check we still only have one file, rotation.log @@ -177,7 +180,7 @@ rotate_file_fail_test() -> %% fix the permissions ok = rumUtil:set_dir_permissions("u+w", TestDir), - ?assertMatch(ok, rotate_logfile(TestLog, 10)), + ?assertMatch(ok, rotateLogFile(TestLog, 10)), ?assert(filelib:is_regular(TestLog ++ ".0")), ?assertEqual(true, filelib:is_regular(TestLog)), ?assertEqual(2, length(filelib:wildcard(TestLog ++ "*"))),