Skip to content

feat: Implement log endpoint#437

Merged
motionduck merged 3 commits into
developfrom
log-endpoint
Aug 17, 2025
Merged

feat: Implement log endpoint#437
motionduck merged 3 commits into
developfrom
log-endpoint

Conversation

@motionduck
Copy link
Copy Markdown
Member

@motionduck motionduck commented Aug 17, 2025

This pull request introduces a new API endpoint for logging messages from a client to new a database table called log_client, while the server log table has been renamed to log_server. It also adds validation, error handling, and comprehensive tests for the new logging functionality.

API and Logging Functionality

  • Added a new POST /api/log endpoint that allows authenticated clients to send log messages to the server, with validation for message content and log level.
    • The request body requires a message property, which can be any string up to 1000 characters.
    • Optionally, a client can provide a level property, which can be any of the following strings: "alert", "error", "warn", "info", "fail", "success", "log", "debug", or"verbose". If not provided, the log will default to log level "info".
    • Optionally, a client can provide a timestamp property, which if not provided will default to the current time.
    • Each log entry will be saved alongside the request's user ID, session ID, and IP address.

Database Schema and Logging Procedure

  • Added a new table log_client, while renaming the old log table to log_server.
  • Split the log_to_db SQL function into two separate functions log_server_to_db and log_client_to_db.

Testing and Documentation

  • Added integration tests for the new logging endpoint, covering validation, error handling, and successful log insertion scenarios. (server/tests/log.test.ts)
  • Updated the OpenAPI documentation to include the new endpoint, as well as another older endpoint that was not yet documented.

Closes #431

+ Add origin column to database log table
+ Update API documentation
+ Add tests
@motionduck motionduck added this to the 2.5.0 milestone Aug 17, 2025
@motionduck motionduck self-assigned this Aug 17, 2025
@motionduck motionduck added backend feature A new feature labels Aug 17, 2025
@motionduck motionduck requested a review from aydex August 17, 2025 18:43
+ Update documentation and tests accordingly
@motionduck motionduck marked this pull request as draft August 17, 2025 21:47
@motionduck motionduck marked this pull request as ready for review August 17, 2025 22:40
@motionduck motionduck merged commit 562b55f into develop Aug 17, 2025
6 checks passed
@motionduck motionduck deleted the log-endpoint branch August 17, 2025 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend feature A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement log endpoint

2 participants