Skip to content

Commit 07e0223

Browse files
authored
Merge pull request #16 from Tirsvad/main
Make tests methods Change var names Fix whitespace in infoscreen
2 parents 928c79f + 7433574 commit 07e0223

File tree

5 files changed

+316
-204
lines changed

5 files changed

+316
-204
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[Tt]emp/
22
[Ll]og/
33
documentation/doxygen/html
4+
src/Test/test.log

README.md

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<br />
99
<div align="center">
10-
<a href="https://github.com/TirsvadCLI/Linux.Distribution">
10+
<a href="https://github.com/TirsvadCLI/Linux.Bash.Logger">
1111
<img src="images/logo.png" alt="Logo" width="80" height="80">
1212
</a>
1313
</div>
@@ -22,6 +22,7 @@ This is a shell script designed to handle logging for various processes. It can
2222
- [Functions](#functions)
2323
- [Usage](#usage)
2424
- [Testing](#testing)
25+
- [Docker issues](#docker-issue)
2526
- [Contribution](#contribution)
2627
- [Code of conduct](#code-of-conduct)
2728

@@ -36,35 +37,35 @@ To use this logger script:
3637

3738
### Clone the Repository
3839
```bash
39-
git clone git@github.com:TirsvadCLI/Linux.Logger.git
40+
git clone git@github.com:TirsvadCLI/Linux.Bash.Logger.git
4041
```
4142

4243
## Functions
4344
### Initialization
44-
- `tcli_linux_logger_init()`: Initializes the logger, setting up output redirection and logging the start of the logger.
45+
- ` tcli_linux_bash_logger_init()`: Initializes the logger, setting up output redirection and logging the start of the logger.
4546

4647
### Logging Messages
47-
- `tcli_linux_logger_infoscreen()`: Displays an info message during processing.
48-
- `tcli_linux_logger_infoscreenDone()`: Shows a "DONE" message when a process is completed successfully.
49-
- `tcli_linux_logger_infoscreenFailed()`: Displays a "FAILED" message, including an error message.
50-
- `tcli_linux_logger_infoscreenFailedExit()`: Displays failure messages and exits the script with a specified error code.
51-
- `tcli_linux_logger_infoscreenWarn()`: Displays a warning message.
48+
- ` tcli_linux_bash_logger_infoscreen()`: Displays an info message during processing.
49+
- ` tcli_linux_bash_logger_infoscreenDone()`: Shows a "DONE" message when a process is completed successfully.
50+
- ` tcli_linux_bash_logger_infoscreenFailed()`: Displays a "FAILED" message, including an error message.
51+
- ` tcli_linux_bash_logger_infoscreenFailedExit()`: Displays failure messages and exits the script with a specified error code.
52+
- ` tcli_linux_bash_logger_infoscreenWarn()`: Displays a warning message.
5253

5354
### Status Checking
54-
- `tcli_linux_logger_infoscreenStatus()`: Checks the status of a command and logs either a failure or success message.
55+
- ` tcli_linux_bash_logger_infoscreenStatus()`: Checks the status of a command and logs either a failure or success message.
5556

5657
### Title Logging
57-
- `tcli_linux_logger_title()`: Creates a formatted title box for better organization in the logs.
58+
- ` tcli_linux_bash_logger_title()`: Creates a formatted title box for better organization in the logs.
5859

5960
### File Logging
60-
- `tcli_linux_logger_file_info()`: Logs informational messages to the log file.
61-
- `tcli_linux_logger_file_warn()`: Logs warning messages.
62-
- `tcli_linux_logger_file_error()`: Logs error messages.
63-
- `tcli_linux_logger_file()`: Generic function to handle the actual file logging for various levels.
61+
- ` tcli_linux_bash_logger_file_info()`: Logs informational messages to the log file.
62+
- ` tcli_linux_bash_logger_file_warn()`: Logs warning messages.
63+
- ` tcli_linux_bash_logger_file_error()`: Logs error messages.
64+
- ` tcli_linux_bash_logger_file()`: Generic function to handle the actual file logging for various levels.
6465

6566
## Usage
66-
1. `Source Logger.sh` in the start of your script.
67-
2. To use the logger, initialize it by calling `tcli_linux_logger_init("path/to/logfile.log")` with the desired log file path.
67+
1. `Source Run.sh` in the start of your script.
68+
2. To use the logger, initialize it by calling `tcli_linux_bash_logger_init("path/to/logfile.log")` with the desired log file path.
6869
3. Use the functions provided to log messages at different stages of your process.
6970
4. Check the log file for detailed information about process execution.
7071

@@ -76,10 +77,22 @@ docker-compose build
7677

7778
To run the test in the Docker container, execute:
7879
```bash
79-
docker run --rm -it tirsvadclilinuxlogger_debian_service:latest
80-
./test_Logger.sh
80+
docker run --rm -it tirsvadclilinuxbashlogger_debian_service:latest
8181
```
8282

83+
In the docker console
84+
```bash
85+
bash test_Run.sh
86+
```
87+
88+
### Docker issue
89+
90+
Follow this guide
91+
92+
[Step 1](https://docs.docker.com/engine/install/linux-postinstall/)
93+
94+
[Step 2](https://docs.docker.com/engine/security/rootless/)
95+
8396
## Contribution
8497
See more [here](CONTRIBUTING.md)
8598

@@ -89,26 +102,15 @@ See more [here](CODE_OF_CONDUCT.md)
89102
<!-- MARKDOWN LINKS & IMAGES -->
90103
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
91104

92-
[contributors-shield]: https://img.shields.io/github/contributors/TirsvadCLI/Linux.Logger?style=for-the-badge
93-
94-
[contributors-url]: https://github.com/TirsvadCLI/Linux.Logger/graphs/contributors
95-
96-
[forks-shield]: https://img.shields.io/github/forks/TirsvadCLI/Linux.Logger?style=for-the-badge
97-
98-
[forks-url]: https://github.com/TirsvadCLI/Linux.Logger/network/members
99-
100-
[stars-shield]: https://img.shields.io/github/stars/TirsvadCLI/Linux.Logger?style=for-the-badge
101-
102-
[stars-url]: https://github.com/TirsvadCLI/Linux.Logger/stargazers
103-
104-
[issues-shield]: https://img.shields.io/github/issues/TirsvadCLI/Linux.Logger?style=for-the-badge
105-
106-
[issues-url]: https://github.com/TirsvadCLI/Linux.Logger/issues
107-
108-
[license-shield]: https://img.shields.io/github/license/TirsvadCLI/Linux.Logger?style=for-the-badge
109-
110-
[license-url]: https://github.com/TirsvadCLI/Linux.Logger/blob/master/LICENSE
111-
105+
[contributors-shield]: https://img.shields.io/github/contributors/TirsvadCLI/Linux.Bash.Logger?style=for-the-badge
106+
[contributors-url]: https://github.com/TirsvadCLI/Linux.Bash.Logger/graphs/contributors
107+
[forks-shield]: https://img.shields.io/github/forks/TirsvadCLI/Linux.Bash.Logger?style=for-the-badge
108+
[forks-url]: https://github.com/TirsvadCLI/Linux.Bash.Logger/network/members
109+
[stars-shield]: https://img.shields.io/github/stars/TirsvadCLI/Linux.Bash.Logger?style=for-the-badge
110+
[stars-url]: https://github.com/TirsvadCLI/Linux.Bash.Logger/stargazers
111+
[issues-shield]: https://img.shields.io/github/issues/TirsvadCLI/Linux.Bash.Logger?style=for-the-badge
112+
[issues-url]: https://github.com/TirsvadCLI/Linux.Bash.Logger/issues
113+
[license-shield]: https://img.shields.io/github/license/TirsvadCLI/Linux.Bash.Logger?style=for-the-badge
114+
[license-url]: https://github.com/TirsvadCLI/Linux.Bash.Logger/blob/master/LICENSE
112115
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555
113-
114-
[linkedin-url]: https://www.linkedin.com/in/jens-tirsvad-nielsen-13b795b9/
116+
[linkedin-url]: https://www.linkedin.com/in/jens-tirsvad-nielsen-13b795b9/

src/Logger/Logger.sh renamed to src/Logger/Run.sh

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
## @author Jens Tirsvad Nielsen
99
## @date May 2023
1010

11+
## @brief string script directory
1112
declare -g TCLI_LINUX_BASH_LOGGER_SCRIPTDIR="$(dirname "$(realpath "${BASH_SOURCE}")")"
1213
## @brief string version
1314
declare -g TCLI_LINUX_BASH_LOGGER="0.2.0"
@@ -29,37 +30,47 @@ declare -g TCLI_LINUX_BASH_LOGGER_BLUE='\033[0;34m'
2930
declare -g TCLI_LINUX_BASH_LOGGER_YELLOW='\033[1;33m'
3031
## @brief string color white
3132
declare -g TCLI_LINUX_BASH_LOGGER_WHITE='\033[0;37m'
33+
## @brief back to line
34+
declare -g TCLI_LINUX_BASH_BACK_TO_LINE='\r\033[1C'
35+
## @brief log to file
36+
declare -g -i TCLI_LINUX_BASH_LOGGER_LOT_TO_FILE=1
3237

3338
## @fn tcli_linux_bash_logger_init()
3439
## @details
3540
## **Initial logger**
3641
## All error go to log file
3742
## Output to file example
38-
## printf "this output is visible" >&3
43+
## printf "this output is visible"
3944
## @param string full path of the log file
4045
tcli_linux_bash_logger_init() {
4146
local _file=${1}
4247
local _dir
4348
_dir=$(dirname "${1}")
4449
[ ! -d ${_dir} ] && mkdir $_dir || rm -f ${1}
45-
exec 3>&1 4>&2
46-
exec 1>$_file 2>&1
50+
exec 2>$_file
4751
tcli_linux_bash_logger_file_info "Loaded" "Logger $TCLI_LINUX_BASH_LOGGER_VERSION"
4852
}
4953

5054
## @fn tcli_linux_bash_logger_infoscreen()
5155
## @details
5256
## **Info of the process step [ ... ]**
57+
## @param string message
58+
## @param string message part 2 (optional)
5359
tcli_linux_bash_logger_infoscreen() {
54-
printf $(printf "[......] ${TCLI_LINUX_BASH_LOGGER_BROWN}$1 ${TCLI_LINUX_BASH_LOGGER_NC}$2$n") >&3
60+
if [ $2 ]; then
61+
local n=" "
62+
else
63+
local n=""
64+
fi
65+
printf $(printf "[......] ${TCLI_LINUX_BASH_LOGGER_BROWN}$1${n}${TCLI_LINUX_BASH_LOGGER_NC}$2$n")
5566
}
5667

5768
## @fn tcli_linux_bash_logger_infoscreenDone()
5869
## @details
5970
## **Info of the process step [ DONE ]**
6071
tcli_linux_bash_logger_infoscreenDone() {
61-
[ ${TCLI_LINUX_BASH_LOGGER_INFOSCREEN_WARN} == 1 ] && TCLI_LINUX_BASH_LOGGER_INFOSCREEN_WARN=0 || printf "\r\033[1C${TCLI_LINUX_BASH_LOGGER_GREEN} DONE ${TCLI_LINUX_BASH_LOGGER_NC}" >&3
62-
printf "\r\033[80C\n" >&3
72+
printf "\r\033[1C${TCLI_LINUX_BASH_LOGGER_GREEN} DONE ${TCLI_LINUX_BASH_LOGGER_NC}"
73+
#printf "\r\033[80C\n"
6374
}
6475

6576
## @fn tcli_linux_bash_logger_infoscreenFailed()
@@ -71,13 +82,12 @@ tcli_linux_bash_logger_infoscreenDone() {
7182
## @param string function or other notice in front of message
7283
tcli_linux_bash_logger_infoscreenFailed() {
7384
local -a _errormsg
74-
# ="${1:-} ${2:-} ${3:-}"
7585
[ ${1:-} ] && _errormsg=($1)
7686
[ ${2:-} ] && _errormsg+=($2)
7787
[ ${3:-} ] && _errormsg+=($3)
7888
[ ${TCLI_LINUX_BASH_LOGGER_INFOSCREEN_WARN} == 1 ] && TCLI_LINUX_BASH_LOGGER_INFOSCREEN_WARN=0
79-
printf "\r\033[1C${TCLI_LINUX_BASH_LOGGER_RED} FAILED ${TCLI_LINUX_BASH_LOGGER_NC}\n" >&3
80-
tcli_linux_bash_logger_file_error $(echo ${_errormsg[@]}) ${4:-}
89+
printf "${TCLI_LINUX_BASH_BACK_TO_LINE}${TCLI_LINUX_BASH_LOGGER_RED}FAILED ${TCLI_LINUX_BASH_LOGGER_NC}\n"
90+
[ ${TCLI_LINUX_BASH_LOGGER_LOT_TO_FILE} == 1 ] && tcli_linux_bash_logger_file_error $(echo ${_errormsg[@]}) ${4:-}
8191
}
8292

8393
## @fn tcli_linux_bash_logger_infoscreenFailedExit()
@@ -95,7 +105,7 @@ tcli_linux_bash_logger_infoscreenFailedExit() {
95105
[ ${1:-} ] && printf "${TCLI_LINUX_BASH_LOGGER_RED}${1}"
96106
[ ${2:-} ] && printf " ${TCLI_LINUX_BASH_LOGGER_BLUE}${2}"
97107
[ ${3:-} ] && printf " ${TCLI_LINUX_BASH_LOGGER_RED}${3}"
98-
printf "${TCLI_LINUX_BASH_LOGGER_NC}\n" >&3
108+
printf "${TCLI_LINUX_BASH_LOGGER_NC}\n"
99109
exit ${4:-1}
100110
}
101111

@@ -104,7 +114,7 @@ tcli_linux_bash_logger_infoscreenFailedExit() {
104114
## **Info of the process step [ FAILED ]**
105115
## Then exit with a error code
106116
tcli_linux_bash_logger_infoscreenWarn() {
107-
printf "\r\033[1C${TCLI_LINUX_BASH_LOGGER_YELLOW} WARN ${TCLI_LINUX_BASH_LOGGER_NC}" >&3
117+
printf "\r\033[1C${TCLI_LINUX_BASH_LOGGER_YELLOW} WARN ${TCLI_LINUX_BASH_LOGGER_NC}"
108118
TCLI_LINUX_BASH_LOGGER_INFOSCREEN_WARN=1
109119
}
110120

@@ -122,7 +132,7 @@ tcli_linux_bash_logger_infoscreenStatus() {
122132
## **TODO**
123133
tcli_linux_bash_logger_errorCheck() {
124134
if [ $? -eq 0 ]; then
125-
printf "${TCLI_LINUX_BASH_LOGGER_RED}An error has occured.${TCLI_LINUX_BASH_LOGGER_NC}" >&3
135+
printf "${TCLI_LINUX_BASH_LOGGER_RED}An error has occured.${TCLI_LINUX_BASH_LOGGER_NC}"
126136
# read -p "Press enter or space to ignore it. Press any other key to abort." -n 1 key
127137
# if [[ $key != "" ]]; then
128138
# exit
@@ -145,17 +155,17 @@ tcli_linux_bash_logger_title() {
145155
local _fillerchar=${3:-"+"}
146156
local -i _n_pad=$(((${_fillerlength} - ${#_title} - 2) / 2))
147157
local -i _i=$(($_n_pad * 2 + 2 + ${#_title}))
148-
printf -- "${_fillerchar}%.0s" $(seq ${_fillerlength}) >&3
149-
printf "\n" >&3
150-
printf -- "${_fillerchar}%.0s" $(seq ${_n_pad}) >&3
151-
printf $(printf ' %s ' "$_title") >&3
158+
printf -- "${_fillerchar}%.0s" $(seq ${_fillerlength})
159+
printf "\n"
160+
printf -- "${_fillerchar}%.0s" $(seq ${_n_pad})
161+
printf $(printf ' %s ' "$_title")
152162
if [ $(($_n_pad * 2 + ${#_title} + 2)) -lt ${_fillerlength} ]; then
153163
((_n_pad++))
154164
fi
155-
printf -- "${_fillerchar}%.0s" $(seq ${_n_pad}) >&3
156-
printf "\n" >&3
157-
printf -- "${_fillerchar}%.0s" $(seq ${_fillerlength}) >&3
158-
printf "\n" >&3
165+
printf -- "${_fillerchar}%.0s" $(seq ${_n_pad})
166+
printf "\n"
167+
printf -- "${_fillerchar}%.0s" $(seq ${_fillerlength})
168+
printf "\n"
159169
}
160170

161171
## @fn tcli_linux_bash_logger_file_info()

0 commit comments

Comments
 (0)