bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[patch] uniform bash loging


From: Piotr Grzybowski
Subject: [patch] uniform bash loging
Date: Mon, 14 Dec 2015 12:57:05 +0100

Hi All,

 for some time I had been struggling with the logging system in my
scripts. I wanted it to automatically detect the status of last
executed command, print the customizable time stamp, work from within
functions, and so on. For me it took a couple of lines of echo, output
redirection, and if instructions to get what I wanted and needed.
 Then I created a log builtin, which I have cleaned now a much as I
could so the main idea is clear, and enclose as a diff against
bash-4.4-testing branched at 54a5fbe126d2a28913a81f7191d7ac6db70e1f43
.
 It is aimed at providing an uniform logging for bash. At the moment
it works as follows:

$ log "processing started."
[31867] Mon, 14 Dec 2015 12:32:41 +0100 processing started.

$ export LOG_FMT_HEADER="[ @%s %d-%m-%Y ]"
$ log "processing 10%."
[31867] [ @1450092818 14-12-2015 ] processing 10%.

$ function stat_file() { local stat; stat=`stat "${1}" 2>&1`; log
"getting status ($stat) ."; }
$ stat_file /tmp/it_is_here
[31867]stat_file [ @1450093235 14-12-2015 ] getting status (  File:
`/tmp/it_is_here'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Access: 2015-12-14 12:40:01.000000000 +0100
Modify: 2015-12-14 12:40:01.000000000 +0100
Change: 2015-12-14 12:40:01.000000000 +0100) .
$ stat_file /tmp/it_is_not_here
[31867]stat_file [ @1450093237 14-12-2015 ] error. getting status
(stat: cannot stat `/tmp/it_is_not_here': No such file or directory) .

$ unset LOG_FMT_HEADER
$ mkdir /tmp/it_is_not_here/directory 2>/dev/null; log "creating
directory." >/dev/null;
[31867] Mon, 14 Dec 2015 12:52:43 +0100 error. creating directory.

$ log "done." 2>/dev/null
[31867] Mon, 14 Dec 2015 12:53:46 +0100 done.

 I provide the diff so you can try it; it still needs lot of work and attention.
 What do you think?

cheers,
pg

Attachment: patch_log_builtin_uniform_bash_logging.diff
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]