Records the run logs of the shell program
Signed-off-by: Liu Yinsi liuyinsi@163.com --- lib/log.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lib/log.sh
diff --git a/lib/log.sh b/lib/log.sh new file mode 100644 index 0000000..83c330c --- /dev/null +++ b/lib/log.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. + +log_info() +{ + date +"%F %T $* [INFO]" +} + +log_debug() +{ + date +"%F %T $* [DEBUG]" +} + +log_warn() +{ + date +"%F %T $* [WARN]" >&2 +} + +log_error() +{ + date +"%F %T $* [ERROR]" >&2 +}
On Thu, Jan 28, 2021 at 12:37:15PM +0800, Liu Yinsi wrote:
Records the run logs of the shell program
Signed-off-by: Liu Yinsi liuyinsi@163.com
lib/log.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lib/log.sh
diff --git a/lib/log.sh b/lib/log.sh new file mode 100644 index 0000000..83c330c --- /dev/null +++ b/lib/log.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+log_info() +{
- date +"%F %T $* [INFO]"
[INFO] should come before $*
+}
+log_debug() +{
- date +"%F %T $* [DEBUG]"
+}
+log_warn() +{
- date +"%F %T $* [WARN]" >&2
+}
+log_error() +{
- date +"%F %T $* [ERROR]" >&2
+}
2.23.0
On Thu, Jan 28, 2021 at 12:59:40PM +0800, Wu Fengguang wrote:
On Thu, Jan 28, 2021 at 12:37:15PM +0800, Liu Yinsi wrote:
Records the run logs of the shell program
Signed-off-by: Liu Yinsi liuyinsi@163.com
lib/log.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lib/log.sh
diff --git a/lib/log.sh b/lib/log.sh new file mode 100644 index 0000000..83c330c --- /dev/null +++ b/lib/log.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+log_info() +{
- date +"%F %T $* [INFO]"
[INFO] should come before $*
How about use format
"%F %T $0 INFO: $*"
Thanks, Fengguang
On Thu, Jan 28, 2021 at 03:12:05PM +0800, Wu Fengguang wrote:
On Thu, Jan 28, 2021 at 01:48:27PM +0800, Liu Yinsi wrote:
[INFO] should come before $*
How about use format
"%F %T $0 INFO: $*"
OK
How about "%F %T $PWD/$0 INFO: $*"
This will show absolute path of error script, Is it redundant?
OK, then use ${0##*/}
OK
Thanks, Yinsi
Thanks, Fengguang