Commit d25eaf7af93ee647cdb7127b563f0dd13e4d16f4

Parents: ee907566fa4e10b03aed17aa480f0dfd42734bf9

From: Moritz Poldrack <git@moritz.sh>
Date: Fri Sep 15 12:48:01 2023 +0700

chore: replace custom logger with log/slog
Signed-off-by: Moritz Poldrack <git@moritz.sh>

Stats

internal/client/client.go +23/-23
internal/client/restapi.go +3/-3
internal/client/signal.go +6/-7
internal/conman/keys.go +10/-0
internal/conman/logger.go +22/-0
internal/mansion/room.go +6/-6
internal/mansion/type.go +11/-11
internal/player/mpv/actions.go +9/-9
internal/player/mpv/command.go +2/-3
internal/player/mpv/monitor.go +4/-5
internal/player/mpv/type.go +3/-3
internal/server/http/serve.go +20/-8
internal/server/http/wrapper.go +15/-2
internal/server/server.go +19/-11
main.go +33/-11
server.go +10/-4

Changeset

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
diff --git a/internal/client/client.go b/internal/client/client.go
index 4e48868dc26e3c8e9cb0fea7909f96683923f565..5ccbf8c8dec0d9e377e60d71375a875c3e49de13 100644
--- a/internal/client/client.go
+++ b/internal/client/client.go
@@ -8,6 +8,7 @@ 	"context"
 	"crypto/tls"
 	"errors"
 	"fmt"
+	"log/slog"
 	"net"
 	"net/url"
 	"os"
@@ -19,7 +20,6 @@ 	"git.sr.ht/~mpldr/uniview/internal/client/api"
 	"git.sr.ht/~mpldr/uniview/internal/player"
 	"git.sr.ht/~mpldr/uniview/internal/player/mpv"
 	"git.sr.ht/~mpldr/uniview/protocol"
-	"git.sr.ht/~poldi1405/glog"
 	"google.golang.org/grpc"
 	"google.golang.org/grpc/credentials"
 	"google.golang.org/grpc/credentials/insecure"
@@ -38,7 +38,7 @@ 	sigs := make(chan os.Signal, 8)
 	go serverShutdown(ctx, cancel, sigs, waitForExit)
 	signal.Notify(sigs, os.Interrupt)
 
-	glog.Debug("starting player…")
+	slog.Debug("starting player…")
 	p, err = mpv.New()
 	if err != nil {
 		return fmt.Errorf("failed to start mpv: %w", err)
@@ -48,7 +48,7 @@
 	status := api.StatusConnectionConnecting
 	go StartRestServer(context.Background(), p, &status, u)
 
-	glog.Debugf("loading file %q…", u.Query().Get("file"))
+	slog.Debug("loading file", "file", u.Query().Get("file"))
 	err = p.LoadFile(u.Query().Get("file"))
 	if err != nil {
 		return fmt.Errorf("failed to load file: %w", err)
@@ -66,7 +66,7 @@ 	} else {
 		opts = append(opts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})))
 	}
 
-	glog.Debugf("connecting to remote…")
+	slog.Debug("connecting to remote", "host", u.Host, "insecure_explicit", u.Query().Has("insecure"), "insecure_ip", insecureByDefault(u.Hostname()))
 	dialCtx, dialCancel := context.WithTimeout(context.Background(), 5*time.Second)
 	gconn, err := grpc.DialContext(dialCtx, u.Host, opts...)
 	dialCancel()
@@ -77,7 +77,7 @@ 	defer gconn.Close()
 
 	status = api.StatusConnectionOk
 
-	glog.Debug("requesting handle…")
+	slog.Debug("requesting handle")
 	cl := protocol.NewUniViewClient(gconn)
 	stream, err := cl.Room(context.Background())
 	if err != nil {
@@ -94,7 +94,7 @@ 	if len(room) == 0 {
 		return errors.New("no room provided")
 	}
 
-	glog.Debugf("Joining room %q", room)
+	slog.Debug("joining room", "room", room)
 	err = stream.Send(&protocol.RoomEvent{
 		Type: protocol.EventType_EVENT_JOIN,
 		Event: &protocol.RoomEvent_Join{
@@ -109,7 +109,7 @@ 	if err != nil {
 		return fmt.Errorf("failed to join room: %w", err)
 	}
 
-	glog.Debug("waiting for remote events…")
+	slog.Debug("waiting for remote events")
 	go func() {
 		receiveEvents(ctx, p, stream)
 		select {
@@ -127,21 +127,21 @@ 			cancel()
 		}
 	}()
 
-	glog.Debug("waiting for shutdown")
+	slog.Debug("waiting for shutdown")
 	<-waitForExit
-	glog.Debug("completed shutdown")
+	slog.Debug("completed shutdown")
 
 	return nil
 }
 
 func sendPlayerEvents(ctx context.Context, p player.Interface, cl protocol.UniView_RoomClient) {
-	glog.Debug("waiting for player events…")
+	slog.Debug("waiting for player events")
 
 loop:
 	for {
 		select {
 		case timestamp := <-p.NotifySeek():
-			glog.Debugf("local: seek to %s detected", timestamp)
+			slog.Debug("seek detected", "origin", "local", "seek_to", timestamp)
 			cl.Send(&protocol.RoomEvent{
 				Type: protocol.EventType_EVENT_JUMP,
 				Event: &protocol.RoomEvent_JumpEvent{
@@ -151,13 +151,13 @@ 					},
 				},
 			})
 		case pause := <-p.NotifyPause():
-			glog.Debugf("local: pause state change to %t detected", pause)
+			slog.Debug("pause state change detected", "origin", "local", "state", pause)
 			pos, err := p.GetPlaybackPos()
 			if err != nil {
-				glog.Warnf("failed to get playback position: %v", err)
+				slog.Warn("failed to get playback position", "error", err)
 				break
 			}
-			glog.Debugf("local: pause state triggered at %s", pos)
+			slog.Debug("sending pause state update", "state", pos, "timestamp", pos)
 			cl.Send(&protocol.RoomEvent{
 				Type: protocol.EventType_EVENT_PAUSE,
 				Event: &protocol.RoomEvent_PauseEvent{
@@ -186,7 +186,7 @@ 		defer close(events)
 		for {
 			ev, err := cl.Recv()
 			if err != nil {
-				glog.Errorf("receive failed: %v", err)
+				slog.Error("receive failed", "error", err)
 				return
 			}
 			events <- ev
@@ -201,35 +201,35 @@ 		case ev, open := <-events:
 			if !open {
 				return
 			}
-			glog.Debugf("received %s", ev.Type)
+			slog.Debug("received event", "type", ev.Type)
 
 			<-p.PlayerReady()
 			switch ev.Type {
 			case protocol.EventType_EVENT_PAUSE:
 				pauseEv := ev.GetPauseEvent()
 				if pauseEv == nil {
-					glog.Warn("received empty pause event")
+					slog.Warn("received empty pause event")
 					continue
 				}
 
-				glog.Debugf("remote: pause %t", pauseEv.Pause)
+				slog.Debug("pause state change detected", "origin", "remote", "state", pauseEv.Pause)
 				p.Pause(pauseEv.Pause)
-				glog.Debugf("remote: pause jump to %s", pauseEv.Timestamp.AsDuration())
+				slog.Debug("seek detected", "origin", "remote", "seek_to", pauseEv.Timestamp.AsDuration())
 				p.Seek(pauseEv.Timestamp.AsDuration())
 			case protocol.EventType_EVENT_JUMP:
 				jumpEv := ev.GetJumpEvent()
 				if jumpEv == nil {
-					glog.Warn("received empty jump event")
+					slog.Warn("received empty jump event")
 					continue
 				}
 
-				glog.Debugf("remote: jump to %s", jumpEv.Timestamp.AsDuration())
+				slog.Debug("seek detected", "origin", "remote", "seek_to", jumpEv.Timestamp.AsDuration())
 				p.Seek(jumpEv.Timestamp.AsDuration())
 			case protocol.EventType_EVENT_SERVER_CLOSE:
-				glog.Info("received shutdown notification from the server. Disconnecting.")
+				slog.Info("received shutdown notification from the server. Disconnecting.")
 			case protocol.EventType_EVENT_SERVER_PING: // ignore
 			default:
-				glog.Warnf("received unknown event: %s", ev.Type)
+				slog.Warn("received unknown event", "type", ev.Type)
 			}
 		}
 	}
diff --git a/internal/client/restapi.go b/internal/client/restapi.go
index 0871adacc149612f377f409e601b1321cd37908d..5076c6104d772fb14ba53d2b3cdedb9901368773 100644
--- a/internal/client/restapi.go
+++ b/internal/client/restapi.go
@@ -6,6 +6,7 @@
 import (
 	"context"
 	"fmt"
+	"log/slog"
 	"net/http"
 	"net/url"
 	"os"
@@ -21,7 +22,6 @@ 	"git.sr.ht/~mpldr/uniview/internal/buildinfo"
 	"git.sr.ht/~mpldr/uniview/internal/client/api"
 	"git.sr.ht/~mpldr/uniview/internal/config"
 	"git.sr.ht/~mpldr/uniview/internal/player"
-	"git.sr.ht/~poldi1405/glog"
 	"github.com/ogen-go/ogen/ogenerrors"
 )
 
@@ -232,7 +232,7 @@ // Set the player into the given pause state.
 //
 // PUT /player/pause
 func (r *restServer) PutPlayerPause(_ context.Context, req bool) error {
-	glog.Debugf("api: setting pause state to %t", req)
+	slog.Debug("setting pause state", "state", req)
 	return r.p.Pause(req)
 }
 
@@ -242,6 +242,6 @@ // Seek to the specified position.
 //
 // PUT /player/position
 func (r *restServer) PutPlayerPosition(_ context.Context, req api.PlaybackPosition) error {
-	glog.Debugf("api: seek to %s", time.Duration(req)*time.Millisecond)
+	slog.Debug("seek", "seek_to", time.Duration(req)*time.Millisecond)
 	return r.p.Seek(time.Duration(req * api.PlaybackPosition(time.Second)))
 }
diff --git a/internal/client/signal.go b/internal/client/signal.go
index 31b38c2e31bdf19d1506697ac3477d8453de4aac..38d1e7327c3b1ebd9a6878604eaeb3a4cf4821a9 100644
--- a/internal/client/signal.go
+++ b/internal/client/signal.go
@@ -5,11 +5,10 @@ // SPDX-License-Identifier: AGPL-3.0-or-later
 
 import (
 	"context"
+	"log/slog"
 	"os"
 	"sync"
 	"time"
-
-	"git.sr.ht/~poldi1405/glog"
 )
 
 var shutdownFuncs []func(context.Context) error
@@ -20,7 +19,7 @@
 	select {
 	case sig := <-signals:
 		cancel()
-		glog.Infof("received %s, shutting down", sig)
+		slog.Info("received signal. shutting down…", "signal", sig)
 	case <-ctx.Done():
 	}
 
@@ -33,14 +32,14 @@ 		wg.Add(1)
 		go func(ctx context.Context, id int, f func(context.Context) error) {
 			defer wg.Done()
 
-			glog.Debugf("shutting down %d", id)
+			slog.Debug("shutting down", "id", id)
 			awaitStop := make(chan struct{})
 			go func() {
 				defer close(awaitStop)
 
 				err := f(ctx)
 				if err != nil {
-					glog.Warnf("failed to cleanly shutdown: %v", err)
+					slog.Warn("failed to shutdown gracefully", "error", err)
 				}
 			}()
 			select {
@@ -48,10 +47,10 @@ 			case <-awaitStop:
 			case <-ctx.Done():
 				return
 			}
-			glog.Debugf("completed shutdown of %d", id)
+			slog.Debug("completed shutdown", "id", id)
 		}(waitCtx, i, f)
 	}
 
 	wg.Wait()
-	glog.Debug("unlocking quit")
+	slog.Debug("unlocking quit")
 }
diff --git a/internal/conman/keys.go b/internal/conman/keys.go
new file mode 100644
index 0000000000000000000000000000000000000000..c1b951b624d2db9d38d9aea90dc954785783a8a3
--- /dev/null
+++ b/internal/conman/keys.go
@@ -0,0 +1,10 @@
+package conman
+
+// SPDX-FileCopyrightText: © Moritz Poldrack & AUTHORS
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+type key uint8
+
+const (
+	keyLogger key = iota
+)
diff --git a/internal/conman/logger.go b/internal/conman/logger.go
new file mode 100644
index 0000000000000000000000000000000000000000..1eb41bd9e3ae964651c713645b84b51da2878bb3
--- /dev/null
+++ b/internal/conman/logger.go
@@ -0,0 +1,22 @@
+package conman
+
+// SPDX-FileCopyrightText: © Moritz Poldrack & AUTHORS
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import (
+	"context"
+	"fmt"
+	"log/slog"
+)
+
+func SetLogger(ctx context.Context, logger *slog.Logger) context.Context {
+	return context.WithValue(ctx, keyLogger, logger)
+}
+
+func GetLogger(ctx context.Context) *slog.Logger {
+	logger, ok := ctx.Value(keyLogger).(*slog.Logger)
+	if !ok {
+		return slog.With("internal_error", "context error", "context_key", keyLogger, "context_value", ctx.Value(keyLogger), "context_type", fmt.Sprintf("%T", ctx.Value(keyLogger)))
+	}
+	return logger
+}
diff --git a/internal/mansion/room.go b/internal/mansion/room.go
index cc31429136558357bc79e08921e0cb6bc093bdb1..8d8d2a6aa95e3381467e1e9357a1c95aa02a4262 100644
--- a/internal/mansion/room.go
+++ b/internal/mansion/room.go
@@ -5,11 +5,11 @@ // SPDX-License-Identifier: AGPL-3.0-or-later
 
 import (
 	"context"
+	"log/slog"
 	"sync"
 	"time"
 
 	"git.sr.ht/~mpldr/uniview/protocol"
-	"git.sr.ht/~poldi1405/glog"
 )
 
 type room struct {
@@ -42,12 +42,12 @@ func (r *room) Broadcast(ev *protocol.RoomEvent, id uint64) {
 	r.clientFeedMtx.Lock()
 	defer r.clientFeedMtx.Unlock()
 
-	glog.Debugf("broadcasting message to %d clients", len(r.clientFeed))
+	slog.Debug("broadcasting message to clients", "count", len(r.clientFeed))
 
 	max := len(r.clientFeed)
 	for i := 0; i < max; i++ {
 		for r.clientFeed[i].Dead() && ev.Type != protocol.EventType_EVENT_SERVER_CLOSE {
-			glog.Trace("removing client")
+			slog.Debug("removing client", "client_id", r.clientFeed[i].id)
 			r.clientFeed[i] = r.clientFeed[len(r.clientFeed)-1]
 			r.clientFeed[len(r.clientFeed)-1] = nil
 			r.clientFeed = r.clientFeed[:len(r.clientFeed)-1]
@@ -57,13 +57,13 @@ 				return
 			}
 		}
 		if r.clientFeed[i].id == id {
-			glog.Debugf("skipping client %d as the originator", id)
+			slog.Debug("skipping client sender", "client_id", id)
 			continue
 		}
-		glog.Tracef("sending %s to client %d", ev.Type, r.clientFeed[i].id)
+		slog.Debug("sending event to client", "event_type", ev.Type, "client_id", r.clientFeed[i].id)
 		err := r.clientFeed[i].Send(ev)
 		if err != nil {
-			glog.Warnf("failed to send to client %d: %v", i, err)
+			slog.Warn("failed to send to client", "client_id", r.clientFeed[i].id, "error", err)
 		}
 	}
 }
diff --git a/internal/mansion/type.go b/internal/mansion/type.go
index 06de485c21a9291e189b934576efa0d95dbd50ff..080690409814c7767647e7e7b63f22499525cc0a 100644
--- a/internal/mansion/type.go
+++ b/internal/mansion/type.go
@@ -5,12 +5,12 @@ // SPDX-License-Identifier: AGPL-3.0-or-later
 
 import (
 	"context"
+	"log/slog"
 	"sync"
 	"sync/atomic"
 	"time"
 
 	"git.sr.ht/~mpldr/uniview/protocol"
-	"git.sr.ht/~poldi1405/glog"
 )
 
 type Mansion struct {
@@ -39,13 +39,13 @@ 	for {
 		select {
 		case <-m.ctx.Done():
 			m.roomsMtx.Lock()
-			glog.Debugf("evacuating %d rooms", len(m.rooms))
+			slog.Debug("evacuating rooms", "count", len(m.rooms))
 			var wg sync.WaitGroup
 			for n, r := range m.rooms {
 				wg.Add(1)
 				go func(r *room, name string) {
 					defer wg.Done()
-					defer glog.Debugf("cleared room %s", name)
+					defer slog.Debug("cleared room", "id", name)
 
 					r.Broadcast(&protocol.RoomEvent{
 						Type: protocol.EventType_EVENT_SERVER_CLOSE,
@@ -56,14 +56,14 @@ 			wg.Wait()
 			close(m.shutDown)
 			return
 		case <-time.After(5 * time.Minute):
-			glog.Debug("running housekeeper")
+			slog.Debug("running housekeeper")
 			m.roomsMtx.RLock()
 			var wg sync.WaitGroup
 			for n, r := range m.rooms {
 				wg.Add(1)
 				go func(r *room, name string) {
 					defer wg.Done()
-					defer glog.Tracef("pinging room %s", name)
+					defer slog.Debug("pinging room", "id", name)
 
 					r.Broadcast(&protocol.RoomEvent{
 						Type: protocol.EventType_EVENT_SERVER_PING,
@@ -71,24 +71,24 @@ 					}, 0)
 				}(r, n)
 			}
 			wg.Wait()
-			glog.Debug("finished pinging")
+			slog.Debug("finished pinging")
 			m.roomsMtx.RUnlock()
 
 			m.roomsMtx.Lock()
 			for n, r := range m.rooms {
 				if len(r.clientFeed) == 0 {
-					glog.Debugf("deleted room %s", n)
+					slog.Debug("deleted room", "id", n)
 					delete(m.rooms, n)
 				}
 			}
-			glog.Debug("housekeeper finished")
+			slog.Debug("housekeeper finished")
 			m.roomsMtx.Unlock()
 		}
 	}
 }
 
 func (m *Mansion) GetRoom(name string) (*room, uint64) {
-	glog.Tracef("requested room: %s", name)
+	slog.Debug("requested room", "id", name)
 	m.roomsMtx.RLock()
 	if r, exists := m.rooms[name]; exists {
 		m.roomsMtx.RUnlock()
@@ -96,7 +96,7 @@ 		id := m.clientID.Add(1)
 		return r, id
 	}
 
-	glog.Tracef("creating new room %q", name)
+	slog.Debug("creating new room", "id", name)
 	m.roomsMtx.RUnlock()
 	m.roomsMtx.Lock()
 	r := newRoom(m.ctx)
@@ -108,7 +108,7 @@ 	return r, id
 }
 
 func (m *Mansion) Close() {
-	glog.Debug("closing mansion and evicting tenants")
+	slog.Debug("closing mansion and evicting tenants")
 	m.cancel()
 	select {
 	case <-m.shutDown:
diff --git a/internal/player/mpv/actions.go b/internal/player/mpv/actions.go
index 6f4a687df0f7b36262238816d51e75acb8558ed9..7ee8934cf089f2647db5c518320583394cbcf918 100644
--- a/internal/player/mpv/actions.go
+++ b/internal/player/mpv/actions.go
@@ -6,11 +6,11 @@
 import (
 	"errors"
 	"fmt"
+	"log/slog"
 	"math/rand"
 	"time"
 
 	"git.sr.ht/~mpldr/uniview/internal/player"
-	"git.sr.ht/~poldi1405/glog"
 )
 
 func (p *MPV) Pause(state bool) error {
@@ -18,14 +18,14 @@ 	if p.dead.Load() {
 		return player.ErrPlayerDead
 	}
 	req := rand.Int()
-	glog.Tracef("sending command to set pause to %t", state)
+	slog.Debug("sending pause command", "desired_state", state)
 	p.dropPause.Store(true)
 	p.send(command{
 		Command:   []any{"set_property", "pause", state},
 		RequestID: req,
 	})
 	res := p.getResponse(req)
-	glog.Tracef("received response %#v", res)
+	slog.Debug("received response", "response", res)
 	if res.Error != "" && res.Error != "success" {
 		return errors.New(res.Error)
 	}
@@ -37,13 +37,13 @@ 	if p.dead.Load() {
 		return player.ErrPlayerDead
 	}
 	req := rand.Int()
-	glog.Tracef("sending command to load %q", path)
+	slog.Debug("sending command to load file", "file", path)
 	p.send(command{
 		Command:   []any{"loadfile", path},
 		RequestID: req,
 	})
 	res := p.getResponse(req)
-	glog.Tracef("received response %#v", res)
+	slog.Debug("received response", "response", res)
 	if res.Error != "" && res.Error != "success" {
 		return errors.New(res.Error)
 	}
@@ -55,14 +55,14 @@ 	if p.dead.Load() {
 		return player.ErrPlayerDead
 	}
 	req := rand.Int()
-	glog.Tracef("sending command to seek to %s", ts)
+	slog.Debug("sending command to seek", "seek_to", ts)
 	p.dropSeek.Store(true)
 	p.send(command{
 		Command:   []any{"set_property", "time-pos", float64(ts/time.Millisecond) / 1000},
 		RequestID: req,
 	})
 	res := p.getResponse(req)
-	glog.Tracef("received response %#v", res)
+	slog.Debug("received response", "response", res)
 	if res.Error != "" && res.Error != "success" {
 		return errors.New(res.Error)
 	}
@@ -78,13 +78,13 @@ 	if p.dead.Load() {
 		return 0, player.ErrPlayerDead
 	}
 	req := rand.Int()
-	glog.Trace("sending command to query playback position")
+	slog.Debug("sending command to query playback position")
 	p.send(command{
 		Command:   []any{"get_property", "time-pos"},
 		RequestID: req,
 	})
 	res := p.getResponse(req)
-	glog.Tracef("received response %#v", res)
+	slog.Debug("received response", "response", res)
 	if pos, ok := res.Data.(float64); ok {
 		ts := time.Duration(pos*1000) * time.Millisecond
 		return ts, nil
diff --git a/internal/player/mpv/command.go b/internal/player/mpv/command.go
index c66d9ab02ae6373845d648be89add67b6581ee65..012aa837a70e6b659ee465e43b7e06922d3d8cfc 100644
--- a/internal/player/mpv/command.go
+++ b/internal/player/mpv/command.go
@@ -6,8 +6,7 @@
 import (
 	"encoding/json"
 	"fmt"
-
-	"git.sr.ht/~poldi1405/glog"
+	"log/slog"
 )
 
 func (p *MPV) send(cmd command) {
@@ -16,7 +15,7 @@ 		return
 	}
 	cmdJSON, _ := json.Marshal(cmd)
 	_, err := fmt.Fprintf(p.conn, "%s\n", cmdJSON)
-	glog.Tracef("sent: %s: %v", cmdJSON, err)
+	slog.Debug("sent command", "command", cmdJSON, "error", err)
 }
 
 func (p *MPV) getResponse(id int) response {
diff --git a/internal/player/mpv/monitor.go b/internal/player/mpv/monitor.go
index f935caa15c6dfe8d7bd8aa7e4f2cec4ef7532926..ffbdf3916d1174129f43f222e3a4f582d74a4ef5 100644
--- a/internal/player/mpv/monitor.go
+++ b/internal/player/mpv/monitor.go
@@ -7,10 +7,9 @@ import (
 	"bufio"
 	"encoding/json"
 	"io"
+	"log/slog"
 	"math/rand"
 	"time"
-
-	"git.sr.ht/~poldi1405/glog"
 )
 
 func (p *MPV) monitor() {
@@ -29,16 +28,16 @@ 			return
 		}
 		var res response
 		err = json.Unmarshal(message, &res)
-		glog.Tracef("received message: %s", message)
+		slog.Debug("received message", "message", message)
 		if err != nil {
-			glog.Warnf("received non-understood message %q", message)
+			slog.Warn("received non-understood message", "message", message)
 			continue
 		}
 
 		switch {
 		case res.Event == "seek":
 			if p.dropSeek.Load() {
-				glog.Trace("dropped seek")
+				slog.Debug("dropped seek")
 				p.dropSeek.Store(false)
 				continue
 			}
diff --git a/internal/player/mpv/type.go b/internal/player/mpv/type.go
index f86f991ea48b26fc57faabfaf77187ebf270f9c7..0e91359ac2f279fca62e8a2fbb21ce6a65093079 100644
--- a/internal/player/mpv/type.go
+++ b/internal/player/mpv/type.go
@@ -5,6 +5,7 @@ // SPDX-License-Identifier: AGPL-3.0-or-later
 
 import (
 	"fmt"
+	"log/slog"
 	"net"
 	"os"
 	"os/exec"
@@ -14,7 +15,6 @@ 	"sync/atomic"
 	"time"
 
 	"git.sr.ht/~mpldr/uniview/internal/player"
-	"git.sr.ht/~poldi1405/glog"
 	"github.com/adrg/xdg"
 	"github.com/fsnotify/fsnotify"
 )
@@ -96,7 +96,7 @@ outer:
 	for {
 		select {
 		case ev := <-watcher.Events:
-			glog.Debugf("received: %#v", ev)
+			slog.Debug("filewatcher received event", "event", ev)
 			if ev.Has(fsnotify.Create) {
 				watcher.Close()
 				break outer
@@ -116,7 +116,7 @@
 	go p.monitor()
 
 	<-p.notifyIdle
-	glog.Trace("confirmed player idle state")
+	slog.Debug("confirmed player idle state")
 
 	go p.pollPause()
 	go p.handleSeekEvents()
diff --git a/internal/server/http/serve.go b/internal/server/http/serve.go
index da04e00df3d2973938cfb8c366dc9bc43cbde915..94b6adaf35d7389db9f25e5e5427811de659f5a5 100644
--- a/internal/server/http/serve.go
+++ b/internal/server/http/serve.go
@@ -1,37 +1,49 @@
 package http
 
+// SPDX-FileCopyrightText: © Moritz Poldrack & AUTHORS
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
 import (
+	"log/slog"
 	"mime"
 	"net/http"
 	"path"
 	"strings"
 	templates "webinterface"
 
-	"git.sr.ht/~poldi1405/glog"
+	"git.sr.ht/~mpldr/uniview/internal/conman"
 )
 
 func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
-	if r.ProtoMajor == 2 && strings.Contains(r.Header.Get("Content-Type"), "application/grpc") {
-		glog.Debug("handling as gRPC request")
-		s.grpc.ServeHTTP(w, r)
+	id := s.requestID.Add(1)
+	ip := r.RemoteAddr
+	if forwardedFor := r.Header.Get("X-Forwarded-For"); forwardedFor != "" {
+		ip = forwardedFor
+	}
+	log := slog.With("connection_id", id, "from", ip)
+	log.Debug("incoming request", "headers", r.Header, "method", r.Method, "protocol", r.Proto)
+
+	if r.ProtoMajor == 2 && strings.HasPrefix(r.Header.Get("Content-Type"), "application/grpc") {
+		ctx := conman.SetLogger(r.Context(), log)
+		log.Debug("handling as gRPC request")
+		s.grpc.ServeHTTP(w, r.WithContext(ctx))
 		return
 	}
 
-	glog.Tracef("path: %q", r.URL.Path)
 	switch r.URL.Path {
 	case "/":
-		glog.Debug("serving index")
+		log.Debug("serving index")
 		s.templates[TemplateIndex].Execute(w, nil)
 	default:
 		data, err := templates.Templates.ReadFile(path.Join("dist", r.URL.Path))
 		if err == nil {
-			glog.Debug("static asset found")
+			log.Debug("static asset found", "file", r.URL.Path)
 			w.Header().Add("Content-Type", mime.TypeByExtension(path.Ext(r.URL.Path)))
 			w.Write(data)
 			return
 		}
 
-		glog.Debug("serving room interface")
+		log.Debug("serving room interface")
 		s.templates[TemplateRoom].Execute(w, nil)
 	}
 }
diff --git a/internal/server/http/wrapper.go b/internal/server/http/wrapper.go
index eb4dbd4ef563e631eeafddcb5479142466226bd4..1f73a14fe3becb76778350395363d741a83249db 100644
--- a/internal/server/http/wrapper.go
+++ b/internal/server/http/wrapper.go
@@ -1,15 +1,21 @@
 package http
 
+// SPDX-FileCopyrightText: © Moritz Poldrack & AUTHORS
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
 import (
 	"fmt"
 	"html/template"
+	"log/slog"
 	"net/http"
+	"sync/atomic"
 	templates "webinterface"
 )
 
 type Server struct {
 	grpc      http.Handler
 	templates []*template.Template
+	requestID *atomic.Uint64
 }
 
 const (
@@ -24,15 +30,22 @@ }
 
 func NewServer(g http.Handler) (*Server, error) {
 	srv := &Server{
-		grpc: g,
+		grpc:      g,
+		requestID: &atomic.Uint64{},
 	}
 
+	var templateError bool
 	for _, tmpl := range templateList {
 		parsed, err := template.ParseFS(templates.Templates, tmpl)
 		if err != nil {
-			return nil, fmt.Errorf("failed to parse %q: %w", tmpl, err)
+			slog.Error("failed to parse template", "path", tmpl, "error", err)
+			templateError = true
+			continue
 		}
 		srv.templates = append(srv.templates, parsed)
+	}
+	if templateError {
+		return nil, fmt.Errorf("failed to parse templates")
 	}
 
 	return srv, nil
diff --git a/internal/server/server.go b/internal/server/server.go
index 7ea40c0ebf5d9f617b20a9d3348b5ed9269e1423..ecaae8b88bf5b60038466585cd988a0738d5890c 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -5,23 +5,25 @@ // SPDX-License-Identifier: AGPL-3.0-or-later
 
 import (
 	"io"
+	"log/slog"
 
+	"git.sr.ht/~mpldr/uniview/internal/conman"
 	"git.sr.ht/~mpldr/uniview/protocol"
-	"git.sr.ht/~poldi1405/glog"
 	"google.golang.org/grpc/codes"
 	"google.golang.org/grpc/status"
 	"google.golang.org/protobuf/types/known/durationpb"
 )
 
 func (s *Server) Room(feed protocol.UniView_RoomServer) error {
-	glog.Trace("new connection initialized. waiting for join event…")
+	log := conman.GetLogger(feed.Context())
+	log.Debug("new connection initialized. waiting for join event…")
 	ev, err := feed.Recv()
 	if err != nil {
-		glog.Warnf("failed to receive initial message: %v", err)
+		log.Warn("failed to receive initial message", "error", err)
 		return status.Errorf(codes.Internal, "failed to receive join event: %v", err)
 	}
 	if ev.Type != protocol.EventType_EVENT_JOIN {
-		glog.Warnf("received unexpected join event: %s", ev.Type)
+		log.Warn("received unexpected join event", "type", ev.Type)
 		return status.Errorf(codes.FailedPrecondition, "received unexpected join event: %s", ev.Type)
 	}
 
@@ -35,17 +37,21 @@ 		return status.Error(codes.Unavailable, "the server is shutting down")
 	}
 
 	room, id := s.Rooms.GetRoom(joinEv.Name)
-	glog.Debugf("client has been assigned id %d", id)
+	log = slog.With("grpc_client_id", id)
+	log.Debug("client connected")
 	room.Client(feed, id)
 	defer room.Disconnect(id)
 	if room.GetPosition() < 0 {
+		log.Debug("unitialized room")
 		if joinEv.Timestamp.AsDuration() < 0 {
+			log.Debug("no timestamp provided")
 			joinEv.Timestamp = durationpb.New(0)
 		}
+		log.Debug("initialized room", "timestamp", joinEv.Timestamp.AsDuration())
 		room.SetPosition(joinEv.Timestamp.AsDuration())
 		room.SetPause(false)
 	} else {
-		feed.Send(&protocol.RoomEvent{
+		ev := &protocol.RoomEvent{
 			Type: protocol.EventType_EVENT_PAUSE,
 			Event: &protocol.RoomEvent_PauseEvent{
 				PauseEvent: &protocol.PlayPause{
@@ -53,21 +59,23 @@ 					Pause:     room.GetPause(),
 					Timestamp: durationpb.New(room.GetPosition()),
 				},
 			},
-		})
+		}
+		log.Debug("sending initial state to client", "state", ev)
+		feed.Send(ev)
 	}
 
 	for {
 		ev, err = feed.Recv()
 		switch {
 		case err == io.EOF:
-			glog.Debugf("closed connection")
+			log.Debug("closed connection")
 			return nil
 		case err != nil:
 			select {
 			case <-feed.Context().Done():
 				return nil
 			default:
-				glog.Errorf("feed: failed to read value: %v", err)
+				log.Error("failed to read value", "error", err)
 				return status.Errorf(codes.Internal, "failed to receive event: %v", err)
 			}
 		}
@@ -81,10 +89,10 @@ 			room.SetPosition(ev.GetJoin().GetTimestamp().AsDuration())
 		case protocol.EventType_EVENT_JUMP:
 			room.SetPosition(ev.GetJumpEvent().GetTimestamp().AsDuration())
 		case protocol.EventType_EVENT_CLIENT_DISCONNECT:
-			glog.Debugf("client %d disconnected", id)
+			log.Debug("client disconnected")
 			return nil
 		}
-		glog.Debugf("received %s from %d", ev.Type, id)
+		log.Debug("received event", "type", ev.Type)
 		room.Broadcast(ev, id)
 	}
 }
diff --git a/main.go b/main.go
index 5b15c915d74f4e1854fab135d4e6b993f87fa1f2..d76bb762716673f78d6c15bd028378f10414a08e 100644
--- a/main.go
+++ b/main.go
@@ -5,6 +5,7 @@ // SPDX-License-Identifier: AGPL-3.0-or-later
 
 import (
 	"fmt"
+	"log/slog"
 	"net/url"
 	"os"
 	"path/filepath"
@@ -16,32 +17,48 @@ 	"git.sr.ht/~poldi1405/glog"
 	cli "github.com/jawher/mow.cli"
 )
 
+var levels = map[string]slog.Level{
+	"debug": slog.LevelDebug,
+	"info":  slog.LevelInfo,
+	"warn":  slog.LevelWarn,
+	"error": slog.LevelError,
+}
+
 func main() {
 	defer glog.PanicHandler()
-	glog.SetLevel(glog.INFO)
+
+	loglevel, ok := os.LookupEnv("LOG_LEVEL")
+	if !ok {
+		loglevel = "info"
+	}
+	slog.SetDefault(slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
+		AddSource: loglevel == "debug",
+		Level:     levels[loglevel],
+	})))
 
 	if filepath.Base(os.Args[0]) == "univiewd" {
-		glog.Debug("starting in server mode")
+		slog.Debug("starting in server mode")
 
 		err := config.Load(&config.Server, config.ServerPaths)
 		if err != nil {
-			glog.Warnf("no config loaded: %v", err)
+			slog.Warn("no config loaded", "error", err)
 		}
 
 		err = startServer()
 		if err != nil {
-			glog.Errorf("failed to start server: %v", err)
+			slog.Error("failed to start server", "error", err)
 			os.Exit(1)
 		}
-		glog.Debug("server has shut down")
+		slog.Debug("server has shut down")
 		return
 	}
 
 	app := cli.App("uniview", "synchronise video playback")
-	app.Spec = "([--insecure] SERVER ROOM FILE) | URL | --version"
+	app.Spec = "[--log-level] (([--insecure] SERVER ROOM FILE) | URL | --version)"
 
 	var server, room, file, rawurl string
 	var insecure, ver bool
+	app.StringOptPtr(&loglevel, "l log-level", loglevel, "sets the loglevel between debug, info, warn, and error")
 	app.StringArgPtr(&server, "SERVER", "", "the server to connect to")
 	app.StringArgPtr(&room, "ROOM", "", "the room to join")
 	app.StringArgPtr(&file, "FILE", "", "the file to open")
@@ -55,12 +72,17 @@ 			fmt.Println(buildinfo.BugReportVersion())
 			return
 		}
 
+		slog.SetDefault(slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
+			AddSource: loglevel == "debug",
+			Level:     levels[loglevel],
+		})))
+
 		err := config.Load(&config.Client, config.ClientPaths)
 		if err != nil {
-			glog.Warnf("no config loaded: %v", err)
+			slog.Warn("no config loaded", "error", err)
 		}
 
-		glog.Infof("starting uniview version %s", buildinfo.VersionString())
+		slog.Info("starting uniview", "version", buildinfo.VersionString())
 
 		var u *url.URL
 		if len(rawurl) == 0 {
@@ -76,14 +98,14 @@ 		} else {
 			u, err = url.Parse(rawurl)
 		}
 		if err != nil {
-			glog.Errorf("failed to parse URL: %v", err)
+			slog.Error("failed to parse URL", "url", u, "error", err)
 			os.Exit(1)
 		}
 
-		glog.Debugf("connecting to %s", u)
+		slog.Debug("connecting", "url", u)
 		err = client.StartClient(u)
 		if err != nil {
-			glog.Errorf("failed to start server: %v", err)
+			slog.Error("failed to start server", "error", err)
 			os.Exit(1)
 		}
 	}
diff --git a/server.go b/server.go
index 17a2af6b4f0fd49c8270d151226fe7ec1aece761..4b13d707a3449fedbf6061092b0a75fc4d54ad17 100644
--- a/server.go
+++ b/server.go
@@ -7,6 +7,7 @@ import (
 	"context"
 	"errors"
 	"fmt"
+	"log/slog"
 	"net"
 	"net/http"
 	"os"
@@ -19,7 +20,8 @@ 	"git.sr.ht/~mpldr/uniview/internal/mansion"
 	"git.sr.ht/~mpldr/uniview/internal/server"
 	wraphttp "git.sr.ht/~mpldr/uniview/internal/server/http"
 	"git.sr.ht/~mpldr/uniview/protocol"
-	"git.sr.ht/~poldi1405/glog"
+	"golang.org/x/net/http2"
+	"golang.org/x/net/http2/h2c"
 	"google.golang.org/grpc"
 )
 
@@ -27,7 +29,7 @@ var shutdown []func()
 
 func serverShutdown(signals <-chan os.Signal) {
 	sig := <-signals
-	glog.Infof("received %s, shutting down", sig)
+	slog.Info("signal received. shutting down", "signal", sig)
 	var wg sync.WaitGroup
 
 	for _, f := range shutdown {
@@ -53,13 +55,14 @@ 		Rooms: roomMan,
 	})
 	shutdown = append(shutdown, grpcShutdown(grpcsrv))
 
-	glog.Debugf("starting listener on %s", config.Server.General.Bind)
+	slog.Debug("starting listener", "bind_to", config.Server.General.Bind)
 	lis, err := net.Listen("tcp", config.Server.General.Bind)
 	if err != nil {
 		return fmt.Errorf("failed to start listener: %w", err)
 	}
 
-	handler, err := wraphttp.NewServer(grpcsrv)
+	var handler http.Handler
+	handler, err = wraphttp.NewServer(grpcsrv)
 	if err != nil {
 		return fmt.Errorf("failed to wrap gRPC: %w", err)
 	}
@@ -67,10 +70,12 @@
 	go serverShutdown(sigs)
 	signal.Notify(sigs, os.Interrupt)
 
+	handler = h2c.NewHandler(handler, &http2.Server{})
 	srv := &http.Server{
 		Addr:    config.Server.General.Bind,
 		Handler: handler,
 	}
+
 	shutdown = append(shutdown, httpShutdown(srv.Shutdown))
 
 	err = srv.Serve(lis)
@@ -98,6 +103,7 @@ 		}()
 		select {
 		case <-awaitStop:
 		case <-time.After(5 * time.Second):
+			slog.Debug("force-stopping gRPC")
 			srv.Stop()
 		}
 	}