Skip to content

Commit

Permalink
Added parameter to limit logline count
Browse files Browse the repository at this point in the history
  • Loading branch information
timbleimehl committed Sep 30, 2019
1 parent fab6514 commit d9f4fb4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Docker image for a random log generator, based on Alpine Linux.

This image will execute a container which will generate four random log messages:

* `2018-03-02T22:33:27-06:00 ERROR something happened in this execution.`
* `2018-03-02T22:33:27-06:00 INFO takes the value and converts it to string.`
* `2018-03-02T22:33:27-06:00 WARN variable not in use.`
* `2018-03-02T22:33:27-06:00 DEBUG first loop completed.`
- `2018-03-02T22:33:27-06:00 ERROR something happened in this execution.`
- `2018-03-02T22:33:27-06:00 INFO takes the value and converts it to string.`
- `2018-03-02T22:33:27-06:00 WARN variable not in use.`
- `2018-03-02T22:33:27-06:00 DEBUG first loop completed.`

## Why this Image?

Expand All @@ -22,8 +22,8 @@ I've had the necessity to create a random logger to test log configurations with

In this git repository you will find the docker image definitions for the random Logger for Alpine Linux

* `Dockerfile` -> Contains image definition.
* `entrypoint.sh` -> Shell code to generate log messages.
- `Dockerfile` -> Contains image definition.
- `entrypoint.sh` -> Shell code to generate log messages.

## How do I use this image?

Expand All @@ -36,6 +36,10 @@ docker pull chentex/random-logger:latest
# use different intervals to print logs every random(100, 400) milliseconds
docker run chentex/random-logger:latest 100 400

# use the third parameter so limit the number of loglines (after generating the lines the container will stop).
# if not set it runs infinite
docker run chentex/random-logger:latest 100 400 100

# to run the image just execute
docker run -d chentex/random-logger:latest
```
Expand All @@ -57,8 +61,8 @@ docker logs <- container-id ->
First things first, you can find these docker images in `chentex/random-logger`
but you can also build a specific version on your own, you only need:

* docker
* git
- docker
- git

Clone this repo

Expand All @@ -80,6 +84,7 @@ docker build -f Dockerfile -t yourbase/yourname:version .
```

---

For more on docker build reference to the [Documentation](https://docs.docker.com/engine/reference/commandline/build/)

You can get the source from the image in the [Repository](https://github.com/chentex/random-logger)
10 changes: 9 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/bin/sh
while [ 1 ]
n=-1
c=0
if [ -n "$3" ]
then
n=$3
fi

while [ $n -ne $c ]
do
WAIT=$(shuf -i $1-$2 -n 1)
sleep $(echo "scale=4; $WAIT/1000" | bc)
Expand All @@ -15,4 +22,5 @@ do
"4") echo "$D DEBUG This is a debug log that shows a log that can be ignored."
;;
esac
c=$(( c+1 ))
done

0 comments on commit d9f4fb4

Please sign in to comment.