Skip to content

Commit e794869

Browse files
committed
Send logs to Grafana Loki
Closes #221
1 parent 5cc641b commit e794869

6 files changed

+31
-2
lines changed

.env-example

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ CLIPTOK_ANTIPHISHING_ENDPOINT=useyourimagination
44
CLOUDFLARED_TOKEN=ignoreifnotrelevant
55
USERNAME_CHECK_ENDPOINT=https://api.example.com/username
66
CLIPTALK_WEBHOOK=https://discord.com
7-
UPTIME_KUMA_PUSH_URL=
7+
UPTIME_KUMA_PUSH_URL=
8+
TS_AUTHKEY=tskey-auth-asdfg-asdfghj

Cliptok.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<PackageReference Include="Serilog.Expressions" Version="5.0.0" />
2222
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
2323
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
24+
<PackageReference Include="Serilog.Sinks.Grafana.Loki" Version="8.3.0" />
2425
<PackageReference Include="Serilog.Sinks.TextWriter" Version="3.0.0" />
2526
<PackageReference Include="StackExchange.Redis" Version="2.8.0" />
2627
<PackageReference Include="System.Linq" Version="4.3.0" />

Program.cs

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using DSharpPlus.Extensions;
22
using DSharpPlus.Net.Gateway;
3+
using Serilog.Sinks.Grafana.Loki;
34
using System.Reflection;
45

56
namespace Cliptok
@@ -118,6 +119,11 @@ static async Task Main(string[] _)
118119
break;
119120
}
120121

122+
if (cfgjson.LokiURL is not null && cfgjson.LokiServiceName is not null)
123+
{
124+
loggerConfig.WriteTo.GrafanaLoki(cfgjson.LokiURL, [new LokiLabel { Key = "app", Value = cfgjson.LokiServiceName }]);
125+
}
126+
121127
Log.Logger = loggerConfig.CreateLogger();
122128

123129
hasteUploader = new HasteBinClient(cfgjson.HastebinEndpoint);

Structs.cs

+5
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ public class ConfigJson
290290
[JsonProperty("logLevel")]
291291
public Level LogLevel { get; private set; } = Level.Information;
292292

293+
[JsonProperty("lokiURL")]
294+
public string LokiURL { get; private set; } = null;
295+
296+
[JsonProperty("lokiServiceName")]
297+
public string LokiServiceName { get; private set; } = null;
293298
}
294299

295300
public enum Level { Information, Warning, Error, Debug, Verbose }

config.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -317,5 +317,7 @@
317317
"tqsMutedRole": 752821045408563230,
318318
"tqsMuteDurationHours": 2,
319319
"autoWarnMsgAutoDeleteDays": 3,
320-
"logLevel": "Debug"
320+
"logLevel": "Debug",
321+
"lokiURL": "http://100.79.19.82:3100",
322+
"lokiServiceName": "cliptok"
321323
}

docker-compose.yml

+14
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,17 @@ services:
5353
- /var/run/docker.sock:/var/run/docker.sock
5454
command: --interval 30 --label-enable
5555
restart: always
56+
tailscale:
57+
image: tailscale/tailscale:latest
58+
volumes:
59+
- ./data/ts-state:/var/lib/tailscale
60+
environment:
61+
- TS_AUTHKEY=${TS_AUTHKEY}
62+
- TS_STATE_DIR=/var/lib/tailscale
63+
- TS_USERSPACE=false
64+
- TS_EXTRA_ARGS=--hostname=cliptok --accept-dns=false --accept-routes=false # i'm not having my tailnet misconfigurations break cliptok
65+
cap_add:
66+
- net_admin
67+
- sys_module
68+
restart: always
69+
network_mode: service:bot

0 commit comments

Comments
 (0)