Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ volumes:
Logs are stored in the `logs/` directory in the persistent directory. In a docker container, it should be at `/nc_app_context_chat_backend/logs/`. The log file is named `ccb.log` and is set to otate at 20 MB with 10 backups. These logs are in JSONL format, i.e. each line is a valid JSON object.
Now only warning and above logs are printed to the console. All the debug logs are written to the log file if `debug` is set to `true` in the config file.
The logs of the embedding server are written to `logs/embedding_server_[date].log` in the persistent directory, it rotates with date change and is not in JSONL format, just raw stdout and stderr from the embedding server's process.
The internal vector database (PostgreSQL) writes its logs to `vector_db_data/pgsql/log/` in the persistent directory, one file per weekday (e.g. `postgresql-Mon.log`); each is overwritten when that weekday comes round again, so the logs are kept for about a week.

## Configuration
Configuration resides inside the persistent storage as `config.yaml`. The location is `$APP_PERSISTENT_STORAGE`. By default it would be at `/nc_app_context_chat_backend_data/config.yaml` inside the container.
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- add gh workflows for docker builds and do separate cpu, cuda and rocm (vulkan) images (#295) @kyteinsky

### Changed
- rotate the internal PostgreSQL logs into one file per weekday instead of a single ever-growing logfile (#312) @sanzakicesarr

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be dropped

- update readme according to the latest changes (#300) @kyteinsky
- bump llama_cpp_python to 0.3.23 (#301) @kyteinsky

Expand Down
15 changes: 13 additions & 2 deletions dockerfile_scripts/pgsql/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ source "$(dirname $(realpath $0))/env"

if [ x"$1" == "xstop" ]; then
echo -n Stopping PostgreSQL...
sudo -u postgres ${PG_BIN}/pg_ctl -D "$DATA_DIR" -l "${DATA_DIR}/logfile" -o "-p ${PG_PORT}" stop
sudo -u postgres ${PG_BIN}/pg_ctl -D "$DATA_DIR" -o "-p ${PG_PORT}" stop
exit 0
fi

Expand Down Expand Up @@ -47,8 +47,19 @@ if [ ! -d "$DATA_DIR/base" ]; then
sudo -u postgres ${PG_BIN}/initdb -D "$DATA_DIR" -E UTF8
fi

# Rotate the internal PostgreSQL logs with the built-in logging collector: one
# file per weekday (postgresql-Mon.log ... postgresql-Sun.log) under
# "$DATA_DIR/log". The collector overwrites a weekday file only on time-based
# rotation, not on startup, so a frequently-restarted container would otherwise
# append to last week's same-named file. Before starting, drop the pre-rotation
# single logfile and any weekday log at least six days old (find -mtime +5), so
# last week's file is always gone before its name is reused. See #303.
rm -f "${DATA_DIR}/logfile"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be cleaner to put this in a repair step
see https://github.com/nextcloud/context_chat_backend#how-to-generate-a-repair-step-file
use APP_VERSION=5.4.0 ./genrepair.sh
this can be used as an example on how to structure the repair file: https://github.com/nextcloud/context_chat_backend/blob/e869eb21964bf2241b1f3c269509388b5f6a7ed3/context_chat_backend/repair/repair5004_date20260521105831.py

find "${DATA_DIR}/log" -maxdepth 1 -type f -name 'postgresql-*.log' -mtime +5 -delete 2>/dev/null || true
PG_LOG_OPTS="-c logging_collector=on -c log_directory=log -c log_filename=postgresql-%a.log -c log_rotation_age=1d -c log_rotation_size=0 -c log_truncate_on_rotation=on"

Comment on lines +50 to +60

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdyt of having the log rotation based on file size instead of the current day of the week? It would mean we have a fixed estimate to how large the logs can grow, and also have logs going back much further than a week.
something like this maybe:

logging_collector = on
log_directory = 'log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_file_mode = 0640
log_rotation_size = 50MB

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, maybe it makes sense to keep all the args in one place, in the env file in the same pgsql folder as this file, so PG_LOG_OPTS could be declared there too

echo "Starting PostgreSQL..."
sudo -u postgres ${PG_BIN}/pg_ctl -D "$DATA_DIR" -l "${DATA_DIR}/logfile" -o "-p ${PG_PORT}" start
sudo -u postgres ${PG_BIN}/pg_ctl -D "$DATA_DIR" -o "-p ${PG_PORT} ${PG_LOG_OPTS}" start

echo "Waiting for PostgreSQL to start..."
until sudo -u postgres ${PG_SQL} -c "SELECT 1" > /dev/null 2>&1; do
Expand Down