Add functionality to upload log-file
Hello, I use restic to backup different machines, including some windows machines. To monitor for any problems, I like to receive the log-files on some central server to check for problems. Since on windows syslog is not supported, that sadly is not an option. So I added a config option to upload the log-file to some configured URL. Because I think this could be useful for somebody else I opened this pull request.
Greetings FH
[!CAUTION]
Review failed
The head commit changed during the review from 87ee9e0cc9dfeb65eab60a12e5d8a92ed04fac5f to b0746a1648e6e99095ab3c03bf5bb6631615b054.
Walkthrough
The changes introduce support for uploading log files to a specified URL after job completion. This is achieved by adding a LogUploadUrl field to the global configuration, modifying the logger setup to accept and use this field, and implementing a decorator that uploads the log file via HTTP POST when the logger is closed. New tests cover both successful and failed upload scenarios. Additionally, the VSCode launch configuration is updated with a new debug profile. The main application now handles errors from the logger's close operation and reports them to standard error.
Changes
| File(s) | Change Summary |
|---|---|
.vscode/launch.json |
Added a new debug configuration named "Private profiles.toml" to run the application with a specific configuration file. |
config/global.go |
Added a new LogUploadUrl field to the Global struct for specifying the log upload destination. |
logger.go |
Modified logger setup to accept a log upload target, introduced a decorator (logUploadingLogCloser) that uploads the log file to the specified URL on closure, and split the file handler logic into path resolution and handler creation. Added new helper functions and updated function signatures to support the new upload functionality. |
logger_test.go |
Updated an existing test for file handler path resolution and added two new tests: one for successful log upload via HTTP and one for handling upload failures. |
main.go |
Updated the logging setup to pass the log upload URL to the logger and to handle errors from the logger's close operation, reporting any issues to standard error. |
Sequence Diagram(s)
sequenceDiagram
participant Main
participant Logger
participant LogUploader
participant HTTPServer
Main->>Logger: setupTargetLogger(flags, logTarget, logUploadTarget, commandOutput)
Logger->>Logger: getLogfilePath(logTarget)
Logger->>Logger: getFileHandler(resolvedPath)
Logger->>Logger: createLogUploadingLogHandler(handler, resolvedPath, logUploadTarget)
Logger-->>Main: returns log handler (possibly wrapped with uploader)
Main->>Logger: closer.Close()
alt logUploadTarget and logfilePath set
Logger->>LogUploader: logUploadingLogCloser.Close()
LogUploader->>Logger: Close embedded log handler
LogUploader->>LogUploader: Open log file
LogUploader->>HTTPServer: POST log file to logUploadTarget
HTTPServer-->>LogUploader: HTTP response
alt HTTP 2xx
LogUploader-->>Main: success
else HTTP error or failure
LogUploader-->>Main: error
end
else
Logger-->>Main: Close log handler (no upload)
end
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
-
I pushed a fix in commit <commit_id>, please review it. -
Generate unit testing code for this file. -
Open a follow-up GitHub issue for this discussion.
-
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:-
@coderabbitai generate unit testing code for this file. -
@coderabbitai modularize this function.
-
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:-
@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase. -
@coderabbitai read src/utils.ts and generate unit testing code. -
@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format. -
@coderabbitai help me debug CodeRabbit configuration file.
-
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
-
@coderabbitai pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai generate docstringsto generate docstrings for this PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
Hey!
Thanks for this PR, I think it will be useful indeed.
The issue in the tests are fixed: you need to rebase your branch from master and that should work 👍🏻
Hey,
thanks for fixing that. I saw there is still a test-case that is failing. I currently don't have much time, but I will look into it, as soon as I can.
Greetings FH