From cd43e57b999422980ea95df7f1d03117342e358e Mon Sep 17 00:00:00 2001 From: kaotisk Date: Fri, 1 Mar 2024 09:36:53 +0200 Subject: Simplifying logs --- api/lib/akLogThis/index.js | 2 +- bin/ak-cli | 10 +-- bin/ak-comments | 48 ++++++++------- bin/ak-follow | 7 ++- bin/ak-following | 6 +- bin/ak-logthis | 12 ++-- bin/ak-news | 12 ++-- bin/ak-todos | 148 +++++++++++++++++++++++---------------------- bin/ak-zblock-manipulator | 7 ++- bin/ak-zchain-chk | 4 ++ 10 files changed, 139 insertions(+), 117 deletions(-) diff --git a/api/lib/akLogThis/index.js b/api/lib/akLogThis/index.js index 8f8dded..8f26c84 100644 --- a/api/lib/akLogThis/index.js +++ b/api/lib/akLogThis/index.js @@ -4,7 +4,7 @@ const config = require('../../config') module.exports = (type, message) => { const command = spawn( "ak-logthis", - ["", "["+type+"]", message] + ["ak-daemon", type, message] ); var buffer = ""; diff --git a/bin/ak-cli b/bin/ak-cli index 69b6a1c..a6bfb90 100755 --- a/bin/ak-cli +++ b/bin/ak-cli @@ -1,6 +1,6 @@ #!/bin/bash #set -xe -program=`basename $0` +PROGRAM=`basename $0` tempdir=`mktemp -d` curdir=`pwd` launch_timestamp=`date -u +%s` @@ -14,7 +14,7 @@ new_line(){ # logit "WARNING" "Message" # logit "INFO" "Message" logit(){ - ak-logthis "<$program>" "[$1]" "$2" + ak-logthis "$PROGRAM" "$1" "$2" } # exit_program 0 'Clean exit' @@ -31,7 +31,7 @@ exit_program(){ } description(){ - full_title="$(printf '%s - %s' "$program" "$description_text")" + full_title="$(printf '%s - %s' "$PROGRAM" "$description_text")" delimiter_count=`echo -n $full_title | wc -c` printf '%s' "$full_title" new_line @@ -43,8 +43,8 @@ description(){ new_line } #description(){ -# printf '%s - \n' "$program" -# printf '===========================================\n' "$program" +# printf '%s - \n' "$PROGRAM" +# printf '===========================================\n' "$PROGRAM" #} help_all(){ diff --git a/bin/ak-comments b/bin/ak-comments index e20ab85..add1872 100755 --- a/bin/ak-comments +++ b/bin/ak-comments @@ -1,4 +1,8 @@ #!/bin/bash +PROGRAM="$(basename $0)" +logit(){ + ak-logthis "$PROGRAM" "$1" "$2" +} ZCOMMENTSDIR="$AK_WORKDIR/comments" TEMP="/tmp/aktmp" if [ ! -d $ZCOMMENTSDIR ]; then @@ -6,33 +10,33 @@ if [ ! -d $ZCOMMENTSDIR ]; then cd $ZCOMMENTSDIR ak-logthis "[INFO]" "zcommentsdir created" else - ak-logthis "[INFO]" "zcommentsdir found" + logit "INFO" "zcommentsdir found" fi _ak_modules_comments_create(){ - if [ ! -z $1 ] - then - REFER_TO="$1" - else - ak-logthis "[ERROR]" "No reference given" - echo "[ERROR]" "No reference given" - exit 1 - fi + if [ ! -z $1 ] + then + REFER_TO="$1" + else + logit "ERROR" "No reference given" + echo "ERROR" "No reference given" + exit 1 + fi TEMP="$(ak-tempassin)" cd $TEMP - export COMMENTS_FILE="$(date -u +%s)" - vi $COMMENTS_FILE - echo "Renaming..." - TO_FILE=$COMMENTS_FILE - IPFS_FILE=$(ak-ipfs-add $COMMENTS_FILE) - mv $COMMENTS_FILE $ZCOMMENTSDIR/$TO_FILE - _ak_modules_comments_add $TO_FILE - ak-logthis "[INFO]" "Adding to git repo..." - cd $ZCOMMENTSDIR - if [ ! -z $REFER_TO ] - then - ak-reference create $REFERENCE $REFER_TO - fi + export COMMENTS_FILE="$(date -u +%s)" + vi $COMMENTS_FILE + echo "Renaming..." + TO_FILE=$COMMENTS_FILE + IPFS_FILE=$(ak-ipfs-add $COMMENTS_FILE) + mv $COMMENTS_FILE $ZCOMMENTSDIR/$TO_FILE + _ak_modules_comments_add $TO_FILE + logit "INFO" "Adding to git repo..." + cd $ZCOMMENTSDIR + if [ ! -z $REFER_TO ] + then + ak-reference create $REFERENCE $REFER_TO + fi } _ak_modules_comments_index(){ diff --git a/bin/ak-follow b/bin/ak-follow index 0d6107c..a4ca070 100755 --- a/bin/ak-follow +++ b/bin/ak-follow @@ -1,19 +1,22 @@ #!/bin/bash FOLLOWING="$HOME/.arching-kaos/following" PROGRAM="$(basename $0)" +logit(){ + ak-logthis "$PROGRAM" "$1" "$2" +} if [ ! -z $1 ] then grep $1 $FOLLOWING if [ $? == 0 ] then - ak-logthis "<$(basename $0)>" "[ERROR]" "Already exists" + logit "ERROR" "Already exists" exit 1 fi echo $1 >> $FOLLOWING IPFS=$(ak-ipfs-add $FOLLOWING) if [ $? != 0 ] then - ak-logthis "<$PROGRAM>" "[ERROR]" "Addition failed" + logit "ERROR" "Addition failed" exit 1 fi ak-profile set following $IPFS diff --git a/bin/ak-following b/bin/ak-following index 02ed85e..deb631d 100755 --- a/bin/ak-following +++ b/bin/ak-following @@ -1,10 +1,14 @@ #!/bin/bash +PROGRAM="$(basename $0)" +logit(){ + ak-logthis "$PROGRAM" "$1" "$2" +} FOLLOWING="$HOME/.arching-kaos/following" if [ -f $FOLLOWING ] then cat $FOLLOWING else - ak-logthis "No following file, creating" + logit "INFO" "No following file, creating" touch $FOLLOWING echo "None found" fi diff --git a/bin/ak-logthis b/bin/ak-logthis index 295f60d..2ac3d80 100755 --- a/bin/ak-logthis +++ b/bin/ak-logthis @@ -6,25 +6,25 @@ then then if [ ! -z "$3" ] then - echo "$TS" "$1" "$2" "$3" >> $AK_LOGSFILE + echo "$TS" "<$1>" "[$2]" "$3" >> $AK_LOGSFILE if [ "$AK_DEBUG" == "yes" ] then - echo "$TS" "$1" "$2" "$3" >&2 + echo "$TS" "<$1>" "[$2]" "$3" >&2 fi exit 0 else - echo "$TS" "$1" "[ERROR]" "No message" >> $AK_LOGSFILE + echo "$TS" "<$1>" "[ERROR]" "No message" >> $AK_LOGSFILE if [ "$AK_DEBUG" == "yes" ] then - echo "$TS" "$1" "[ERROR]" "No message" >&2 + echo "$TS" "<$1>" "[ERROR]" "No message" >&2 fi exit 1 fi else - echo "$TS" "$1" "[ERROR]" "No type and message" >> $AK_LOGSFILE + echo "$TS" "<$1>" "[ERROR]" "No type and message" >> $AK_LOGSFILE if [ "$AK_DEBUG" == "yes" ] then - echo "$TS" "$1" "[ERROR]" "No type and message" >&2 + echo "$TS" "<$1>" "[ERROR]" "No type and message" >&2 fi exit 1 fi diff --git a/bin/ak-news b/bin/ak-news index 220aafa..b730821 100755 --- a/bin/ak-news +++ b/bin/ak-news @@ -5,19 +5,19 @@ ZNEWSDIR="$AK_WORKDIR/news" TEMP="/tmp/aktmp" logit(){ - ak-logthis "<$PROGRAM>" "$1" "$2" + ak-logthis "$PROGRAM" "$1" "$2" } if [ ! -d $ZNEWSDIR ]; then mkdir $ZNEWSDIR if [ "$?" == 0 ]; then - logit "[INFO]" "$ZNEWSDIR created" + logit "INFO" "$ZNEWSDIR created" else - logit "[ERROR]" "$ZNEWSDIR couldn't be created" + logit "ERROR" "$ZNEWSDIR couldn't be created" exit 1 fi else - logit "[INFO]" "$ZNEWSDIR found" + logit "INFO" "$ZNEWSDIR found" fi cd $ZNEWSDIR @@ -188,8 +188,8 @@ _ak_modules_news_read(){ ak-ipfs-cat $linkToText else - ak-logthis "[ERROR]" "Not a news block." - echo "[ERROR] Not a news block." + logit "ERROR" "Not a news block." + echo "ERROR Not a news block." exit 1 fi rm temp diff --git a/bin/ak-todos b/bin/ak-todos index 3b5813f..89e8960 100755 --- a/bin/ak-todos +++ b/bin/ak-todos @@ -1,88 +1,92 @@ #!/bin/bash +PROGRAM="$(basename $0)" +logit(){ + ak-logthis "$PROGRAM" "$1" "$2" +} ZTODOSDIR="$AK_WORKDIR/todos" TEMP="/tmp/aktmp" if [ ! -d $ZTODOSDIR ]; then - mkdir $ZTODOSDIR - cd $ZTODOSDIR - git init - echo "Todos repository" > README - echo "Qmetc" >> README - git add README - git commit -m "Initiated todos repository" - ak-logthis "ztodosdir created along with git repo" + mkdir $ZTODOSDIR + cd $ZTODOSDIR + git init + echo "Todos repository" > README + echo "Qmetc" >> README + git add README + git commit -m "Initiated todos repository" + logit "[INFO]" "ztodosdir created along with git repo" else - ak-logthis "ztodosdir found" + logit "[INFO]" "ztodosdir found" fi _ak_modules_todos_create(){ TEMP="$(ak-tempassin)" cd $TEMP - export TODOS_FILE="$(date -u +%s)" - vi $TODOS_FILE - ak-logthis "Renaming..." - TITLE="$(head -n 1 $TODOS_FILE)" - TO_FILE=$TODOS_FILE-$(echo $TITLE | tr '[:upper:]' '[:lower:]' | sed -e 's/ /\_/g' ) - IPFS_FILE=$(ak-ipfs-add $TODOS_FILE) - mv $TODOS_FILE $ZTODOSDIR/$TO_FILE - sed -e 's,Qm.*,'"$IPFS_FILE"',g' $ZTODOSDIR/README - _ak_modules_todos_add $ZTODOSDIR/$TO_FILE - ak-logthis "Adding to git repo..." - cd $ZTODOSDIR - git add $TO_FILE README - git commit -m "Added $TO_FILE with $(head -n 1 $ZTODOSDIR/$TO_FILE)" - git clean --force - # rm -rf $TEMP + export TODOS_FILE="$(date -u +%s)" + vi $TODOS_FILE + logit "[INFO]" "Renaming..." + TITLE="$(head -n 1 $TODOS_FILE)" + TO_FILE=$TODOS_FILE-$(echo $TITLE | tr '[:upper:]' '[:lower:]' | sed -e 's/ /\_/g' ) + IPFS_FILE=$(ak-ipfs-add $TODOS_FILE) + mv $TODOS_FILE $ZTODOSDIR/$TO_FILE + sed -e 's,Qm.*,'"$IPFS_FILE"',g' $ZTODOSDIR/README + _ak_modules_todos_add $ZTODOSDIR/$TO_FILE + logit "[INFO]" "Adding to git repo..." + cd $ZTODOSDIR + git add $TO_FILE README + git commit -m "Added $TO_FILE with $(head -n 1 $ZTODOSDIR/$TO_FILE)" + git clean --force + # rm -rf $TEMP } _ak_modules_todos_index(){ - FILES="$(ls -1 $ZTODOSDIR)" - i=0 - for FILE in $FILES - do - DATE=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') - TITLE=$(head -n 1 $ZTODOSDIR/$FILE) - echo $i \| $DATE \| $TITLE - let i+=1 - done + FILES="$(ls -1 $ZTODOSDIR)" + i=0 + for FILE in $FILES + do + DATE=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') + TITLE=$(head -n 1 $ZTODOSDIR/$FILE) + echo $i \| $DATE \| $TITLE + let i+=1 + done } _ak_modules_todos_title(){ - echo ak-todos-cli - echo "--------------" + echo ak-todos-cli + echo "--------------" } _ak_modules_todos_import(){ - echo "#TODO" - if [ ! -z $1 ] - then - if [ ! -d $1 ] - then - echo "Folder does not exists" - exit 4 - else - echo "Folder $1 exists" - fl="$(ls -1 $1)" - for f in $fl - do - _ak_modules_todos_add $1/$f - done - fi - else - echo "No value" - exit 6 - fi - exit 224 + echo "#TODO" + if [ ! -z $1 ] + then + if [ ! -d $1 ] + then + echo "Folder does not exists" + exit 4 + else + echo "Folder $1 exists" + fl="$(ls -1 $1)" + for f in $fl + do + _ak_modules_todos_add $1/$f + done + fi + else + echo "No value" + exit 6 + fi + exit 224 } _ak_modules_todos_add(){ TEMP="$(ak-tempassin)" cd $TEMP - if [ -f $1 ]; then - FILE="$1" - ak-logthis "Adding todos from $FILE" - DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') - TITLE=$(head -n 1 $FILE) - FILE_IPFS_HASH=$(ak-ipfs-add $FILE) - FILE_SIGN_FILE=$FILE".asc" - gpg2 --homedir $AK_GPGHOME --detach-sign --sign-with $AK_FINGERPRINT --armor --output $FILE_SIGN_FILE $FILE - FILE_SIGNATURE=$(ak-ipfs-add $FILE_SIGN_FILE) - cat > data < data <