Skip to content

Commit 0834426

Browse files
committed
update
1 parent 595d1dd commit 0834426

File tree

5 files changed

+99
-60
lines changed

5 files changed

+99
-60
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM alpine:latest
22

3-
RUN apk add --no-cache inotify-tools coreutils bash rsync
3+
RUN apk add --no-cache bash inotify-tools coreutils
44

55
WORKDIR /app
66

README.md

Lines changed: 86 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,92 @@
22
<img src="icon.png" alt="FolderLog icon" width="120"/>
33
</p>
44

5+
<p align="center">
6+
<img src="icon.svg" alt="FolderLog icon" width="120"/>
7+
</p>
8+
9+
# FolderLog
10+
11+
FolderLog is a minimal Docker container to watch folders and log file changes.
12+
13+
---
14+
15+
## Features
16+
- Recursive monitoring of all top-level directories in `/watched`
17+
- Logs written to `/logs`
18+
- One log file per folder
19+
- Configurable log file extension (`LOG_EXT`)
20+
- Optional exclusion regex (`EXCLUDE_REGEX`)
21+
- Minimal CPU and memory usage (Alpine + inotify-tools)
22+
23+
---
24+
25+
## Usage
26+
Mount your folders and logs:
27+
28+
### Docker Compose
29+
```yaml
30+
version: "3.9"
31+
services:
32+
folderlog:
33+
image: ghcr.io/diegocjorge/folderlog:latest
34+
container_name: folderlog
35+
volumes:
36+
- ./folder1:/watched/folder1:ro
37+
- ./folder2:/watched/folder2:ro
38+
- ./logs:/logs
39+
environment:
40+
- LOG_EXT=.txt
41+
# - EXCLUDE_REGEX=.*\.tmp #optional
42+
restart: unless-stopped
43+
```
44+
45+
### Docker Run Example
46+
```bash
47+
docker run -d \
48+
-v ./folder1:/watched/folder1:ro \
49+
-v ./folder2:/watched/folder2:ro \
50+
-v ./logs:/logs \
51+
-e LOG_EXT=.txt \
52+
ghcr.io/diegocjorge/folderlog:latest
53+
```
54+
55+
### Notes
56+
57+
* You can mount **multiple directories** directly under `/watched` by specifying multiple `-v` options in your Docker run command.
58+
* Each top-level folder inside `/watched` will have its own separate log file named after the folder (e.g., `folder1.txt`, `folder2.txt`).
59+
* Events from subfolders are included in their parent folder’s log file.
60+
61+
---
62+
63+
## Environment Variables
64+
65+
| Variable | Description | Example Values |
66+
|---------------|----------------------------------------------|---------------------------------------|
67+
| `LOG_EXT` | File extension for log files (default `.log`) | `.log`, `.txt` |
68+
| `EXCLUDE_REGEX` | Regex pattern to exclude files or folders from logging | `.*\.tmp` |
69+
70+
- **Simple regex example:** Exclude all files ending with `.tmp`
71+
`EXCLUDE_REGEX=.*\.tmp`
72+
73+
- **Advanced regex example:** Exclude any files/folders inside `tmp` or `cache` directories
74+
`EXCLUDE_REGEX=.*/(tmp|cache)/.*`
75+
76+
---
77+
78+
## License
79+
MIT License
80+
81+
82+
83+
84+
85+
86+
87+
88+
89+
90+
591
# FolderLog
692

793
**FolderLog** is a lightweight Docker container that monitors **all directories inside `/watched`**.
@@ -102,22 +188,3 @@ Each log entry includes a timestamp, event type, and affected file or folder pat
102188

103189
This makes it easy to track changes and events inside each monitored folder.
104190

105-
---
106-
107-
## Environment Variables
108-
109-
| Variable | Description | Example Values |
110-
|---------------|----------------------------------------------|---------------------------------------|
111-
| `LOG_EXT` | File extension for log files (default `.log`) | `.log`, `.txt` |
112-
| `EXCLUDE_REGEX` | Regex pattern to exclude files or folders from logging | `.*\.tmp` |
113-
114-
- **Simple regex example:** Exclude all files ending with `.tmp`
115-
`EXCLUDE_REGEX=.*\.tmp`
116-
117-
- **Advanced regex example:** Exclude any files/folders inside `tmp` or `cache` directories
118-
`EXCLUDE_REGEX=.*/(tmp|cache)/.*`
119-
120-
---
121-
122-
## License
123-
MIT License

docker-compose.yml

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,10 @@ services:
44
image: ghcr.io/diegocjorge/folderlog:latest
55
container_name: folderlog
66
volumes:
7-
# Mount one or multiple directories directly under /watched
87
- ./folder1:/watched/folder1:ro
98
- ./folder2:/watched/folder2:ro
10-
11-
# Internal folder for writing logs temporarily inside the container
12-
- folderlog_temp:/log_temp
13-
14-
# Mount the logs directory as an external or SMB volume for persistent storage
159
- ./logs:/logs
1610
environment:
17-
- LOG_EXT=.txt # Change the log file extension (default is .log)
18-
19-
# Example 1: ignore temporary files ending with ".tmp"
20-
- EXCLUDE_REGEX=.*\.tmp
21-
22-
# Example 2: ignore everything inside "node_modules" directories
23-
# - EXCLUDE_REGEX=.*/node_modules/.*
24-
25-
# Example 3: ignore multiple file types (.tmp, .log, .bak)
26-
# - EXCLUDE_REGEX=.*\.(tmp|log|bak)$
27-
restart: unless-stopped
28-
29-
volumes:
30-
folderlog_temp:
11+
- LOG_EXT=.txt
12+
# - EXCLUDE_REGEX=.*\.tmp #optional
13+
restart: unless-stopped

entrypoint.sh

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,27 @@
11
#!/bin/bash
22
set -e
33

4-
LOG_EXT=${LOG_EXT:-.log}
4+
LOG_EXT=${LOG_EXT:-.txt}
55
EXCLUDE_REGEX=${EXCLUDE_REGEX:-}
66

7-
mkdir -p /log_temp
87
mkdir -p /logs
98

109
echo "📂 Watching all directories inside /watched"
1110

12-
# Function to sync logs
13-
sync_logs() {
14-
echo "🔄 Syncing logs to /logs"
15-
rsync -a --no-perms --no-owner --no-group /log_temp/ /logs/
16-
}
17-
18-
# Trap SIGTERM for graceful shutdown
19-
trap 'echo "⚡ Container stopping..."; sync_logs; exit 0' SIGTERM
20-
21-
# Start watchers for each top-level directory
2211
for dir in /watched/*; do
2312
if [ -d "$dir" ]; then
2413
root_dir=$(basename "$dir")
25-
log_file="/log_temp/${root_dir}${LOG_EXT}"
26-
mkdir -p "$(dirname "$log_file")"
14+
log_file="/logs/${root_dir}${LOG_EXT}"
2715
touch "$log_file"
2816
echo "Watching $dir -> $log_file"
2917

3018
inotifywait -m -r ${EXCLUDE_REGEX:+--exclude "$EXCLUDE_REGEX"} "$dir" \
3119
-e create -e delete -e modify -e move --format '%w%f %e' |
3220
while read -r filepath event; do
3321
echo "$(date +'%Y-%m-%d %H:%M:%S') [$event] $filepath"
34-
done | tee -a "$log_file" >/dev/null &
22+
done >> "$log_file" &
3523
fi
24+
s
3625
done
3726

38-
# Periodically sync /log_temp to /logs every 10 seconds
39-
while true; do
40-
sync_logs
41-
sleep 10
42-
done
27+
wait

icon.svg

Lines changed: 4 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)