https://github.com/socksthewolf/workerlogstodiscord
Project for updating worker logs automatically to discord
https://github.com/socksthewolf/workerlogstodiscord
cloudflare cloudflare-workers discord discord-webhook-notifications discord-webhooks
Last synced: 5 months ago
JSON representation
Project for updating worker logs automatically to discord
- Host: GitHub
- URL: https://github.com/socksthewolf/workerlogstodiscord
- Owner: SocksTheWolf
- License: mit
- Created: 2025-02-01T08:04:22.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-08-28T04:10:49.000Z (6 months ago)
- Last Synced: 2025-08-28T11:18:09.443Z (6 months ago)
- Topics: cloudflare, cloudflare-workers, discord, discord-webhook-notifications, discord-webhooks
- Language: JavaScript
- Homepage:
- Size: 160 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WorkerLogsToDiscord
This hackjob of a worker allows you to push execution logs of any worker to a Discord webhook.
## Setup
Clone this repository and upload it to Cloudflare Workers. Add a `WEB_HOOK` secret on your Cloudflare dashboard that contains the Discord webhook url.
## To Log a Worker
* Add this code somewhere in the worker's code.
```js
const Logger = {
useForwarder: false,
logger: null,
serviceName: "",
configure: function(env) {
this.logger = env.LOGGER;
this.serviceName = env.WORKER_NAME || "Worker";
this.useForwarder = env.USE_LOG_FORWARDER === "true";
},
log: async function(msg, hookOverride=null) {
if (!this.useForwarder)
{
console.log(`${this.serviceName}: ${msg}`);
return;
}
await this.logger.postLog(this.serviceName, msg, hookOverride);
},
error: async function(msg, hookOverride=null) {
if (!this.useForwarder)
{
console.error(`${this.serviceName}: ${msg}`);
return;
}
await this.logger.postError(this.serviceName, msg);
},
warn: async function(msg, hookOverride=null) {
if (!this.useForwarder)
{
console.warn(`${this.serviceName}: ${msg}`);
return;
}
await this.logger.postWarning(this.serviceName, msg);
}
};
```
* Call the function `Logger.configure(env);` on any entrypoint to your worker (`fetch`, `schedule`, etc).
* Add the following to your `worker.toml`:
```toml
services = [
{ binding = "LOGGER", service = "workerlogstodiscord" },
]
[vars]
# if log forwarding should be used
USE_LOG_FORWARDER = "true"
# worker name (used for logging)
WORKER_NAME = "NAME OF SERVICE"
```
* When logging, replace any `console.` with `await Logger.`. Log, Warn, Error redirectors are all provided.