X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=src%2Fcommon;h=3b3b7a51f3b8daac02ddf018d1ae22ea2fa1c3aa;hb=1e26301ec4cd2afc45c968c3fe3d77bf296b03fb;hp=34d9b5adfcace1cf8cf4858788a03d602ade4e4a;hpb=5bb8d410b08bf36d1ff3f36257ac364080d80aa9;p=monkeysphere.git diff --git a/src/common b/src/common index 34d9b5a..3b3b7a5 100644 --- a/src/common +++ b/src/common @@ -4,6 +4,8 @@ # # Written by # Jameson Rollins +# Jamie McClelland +# Daniel Kahn Gillmor # # Copyright 2008, released under the GPL, version 3 or later @@ -26,15 +28,57 @@ failure() { exit ${2:-'255'} } -# write output to stderr +# write output to stderr based on specified LOG_LEVEL the first +# parameter is the priority of the output, and everything else is what +# is echoed to stderr log() { + local priority local level + local output + local alllevels + local found= - level="$1" + # don't include SILENT in alllevels: it's handled separately + # list in decreasing verbosity (all caps). + # separate with $IFS explicitly, since we do some fancy footwork + # elsewhere. + alllevels="DEBUG${IFS}INFO${IFS}ERROR" + + # translate lowers to uppers in global log level + LOG_LEVEL=$(echo "$LOG_LEVEL" | tr "[:lower:]" "[:upper:]") + + # just go ahead and return if the log level is silent + if [ "$LOG_LEVEL" = 'SILENT' ] ; then + return + fi + + for level in $alllevels ; do + if [ "$LOG_LEVEL" = "$level" ] ; then + found=true + fi + done + if [ -z "$found" ] ; then + # default to INFO: + LOG_LEVEL=INFO + fi + + # get priority from first parameter, translating all lower to + # uppers + priority=$(echo "$1" | tr "[:lower:]" "[:upper:]") shift - echo -n "ms: " >&2 - echo "$@" >&2 + # scan over available levels + for level in $alllevels ; do + # output if the log level matches, set output to true + # this will output for all subsequent loops as well. + if [ "$LOG_LEVEL" = "$level" ] ; then + output=true + fi + if [ "$priority" = "$level" -a "$output" = 'true' ] ; then + echo -n "ms: " >&2 + echo "$@" >&2 + fi + done } # cut out all comments(#) and blank lines from standard input @@ -441,7 +485,7 @@ process_user_id() { # if the gpg query return code is not 0, return 1 if [ "$?" -ne 0 ] ; then - log error " no primary keys found." + log info " no primary keys found." return 1 fi @@ -458,7 +502,7 @@ process_user_id() { lastKeyOK= fingerprint= - log error " primary key found: $keyid" + log info " primary key found: $keyid" # if overall key is not valid, skip if [ "$validity" != 'u' -a "$validity" != 'f' ] ; then @@ -507,7 +551,7 @@ process_user_id() { # output a line for the primary key # 0 = ok, 1 = bad if [ "$keyOK" -a "$uidOK" -a "$lastKeyOK" ] ; then - log error " * acceptable primary key." + log info " * acceptable primary key." if [ -z "$sshKey" ] ; then log error " ! primary key could not be translated (not RSA or DSA?)." else @@ -563,7 +607,7 @@ process_user_id() { # output a line for the sub key # 0 = ok, 1 = bad if [ "$keyOK" -a "$uidOK" -a "$lastKeyOK" ] ; then - log error " * acceptable sub key." + log info " * acceptable sub key." if [ -z "$sshKey" ] ; then log error " ! sub key could not be translated (not RSA or DSA?)." else