Skip to content

Commit

Permalink
Send logs to Grafana Loki
Browse files Browse the repository at this point in the history
Closes #221
  • Loading branch information
Erisa committed Aug 22, 2024
1 parent 5cc641b commit e794869
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ CLIPTOK_ANTIPHISHING_ENDPOINT=useyourimagination
CLOUDFLARED_TOKEN=ignoreifnotrelevant
USERNAME_CHECK_ENDPOINT=https://api.example.com/username
CLIPTALK_WEBHOOK=https://discord.com
UPTIME_KUMA_PUSH_URL=
UPTIME_KUMA_PUSH_URL=
TS_AUTHKEY=tskey-auth-asdfg-asdfghj
1 change: 1 addition & 0 deletions Cliptok.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<PackageReference Include="Serilog.Expressions" Version="5.0.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.Grafana.Loki" Version="8.3.0" />
<PackageReference Include="Serilog.Sinks.TextWriter" Version="3.0.0" />
<PackageReference Include="StackExchange.Redis" Version="2.8.0" />
<PackageReference Include="System.Linq" Version="4.3.0" />
Expand Down
6 changes: 6 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using DSharpPlus.Extensions;
using DSharpPlus.Net.Gateway;
using Serilog.Sinks.Grafana.Loki;
using System.Reflection;

namespace Cliptok
Expand Down Expand Up @@ -118,6 +119,11 @@ static async Task Main(string[] _)
break;
}

if (cfgjson.LokiURL is not null && cfgjson.LokiServiceName is not null)
{
loggerConfig.WriteTo.GrafanaLoki(cfgjson.LokiURL, [new LokiLabel { Key = "app", Value = cfgjson.LokiServiceName }]);
}

Log.Logger = loggerConfig.CreateLogger();

hasteUploader = new HasteBinClient(cfgjson.HastebinEndpoint);
Expand Down
5 changes: 5 additions & 0 deletions Structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ public class ConfigJson
[JsonProperty("logLevel")]
public Level LogLevel { get; private set; } = Level.Information;

[JsonProperty("lokiURL")]
public string LokiURL { get; private set; } = null;

[JsonProperty("lokiServiceName")]
public string LokiServiceName { get; private set; } = null;
}

public enum Level { Information, Warning, Error, Debug, Verbose }
Expand Down
4 changes: 3 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -317,5 +317,7 @@
"tqsMutedRole": 752821045408563230,
"tqsMuteDurationHours": 2,
"autoWarnMsgAutoDeleteDays": 3,
"logLevel": "Debug"
"logLevel": "Debug",
"lokiURL": "http://100.79.19.82:3100",
"lokiServiceName": "cliptok"
}
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,17 @@ services:
- /var/run/docker.sock:/var/run/docker.sock
command: --interval 30 --label-enable
restart: always
tailscale:
image: tailscale/tailscale:latest
volumes:
- ./data/ts-state:/var/lib/tailscale
environment:
- TS_AUTHKEY=${TS_AUTHKEY}
- TS_STATE_DIR=/var/lib/tailscale
- TS_USERSPACE=false
- TS_EXTRA_ARGS=--hostname=cliptok --accept-dns=false --accept-routes=false # i'm not having my tailnet misconfigurations break cliptok
cap_add:
- net_admin
- sys_module
restart: always
network_mode: service:bot

0 comments on commit e794869

Please sign in to comment.