Skip to content

Commit 8f0f642

Browse files
SchlenkRSchlenkR
authored andcommitted
Add promotional logging for PXL-JAM 2024 on first debug log initialization
1 parent 773a897 commit 8f0f642

File tree

4 files changed

+42
-27
lines changed

4 files changed

+42
-27
lines changed

fiddle/pxlClockFsiMessage.fsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
#r "../src/FsHttp/bin/debug/net6.0/FsHttp.dll"
3+
4+
open FsHttp
5+
open FsHttp.Operators
6+
7+
8+
http {
9+
GET "https://www.wikipedia.de"
10+
}
11+
|> Request.send
12+
|> ignore

src/FsHttp/Dsl.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module internal HeaderContext =
2626
// TODO: I really(!!) have to code the URL stuff on type level;
2727
// this makes problems all over the place; feels like C# :D
2828

29-
let create () =
29+
let create () =
3030
// FSI init HACK
3131
FsiInit.init ()
3232

src/FsHttp/FsiInit.fs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,39 @@ type InitResult =
1313

1414
let mutable private state = Uninitialized
1515

16+
let private logPxlClockOnFirstSend =
17+
let mutable firstSend = true
18+
fun () ->
19+
if firstSend then
20+
firstSend <- false
21+
let msg = @"
22+
23+
**************************************************************
24+
25+
+---------+
26+
| | PXL-JAM 2024
27+
| PXL | - github.com/CuminAndPotato/PXL-JAM
28+
| CLOCK | - WIN a PXL-Clock MK1
29+
| | - until 8th of January 2025
30+
+---------+
31+
32+
**************************************************************
33+
34+
"
35+
printfn "%s" msg
36+
1637
// This seems like a HACK, but there shouldn't be the requirement of referencing FCS in FSI.
1738
let doInit () =
1839
if state <> Uninitialized then
1940
state
2041
else
21-
2242
let fsiAssemblyName = "FSI-ASSEMBLY"
23-
2443
let isInteractive =
2544
// This hack is indeed one (see https://fsharp.github.io/fsharp-compiler-docs/fsi-emit.html)
2645
AppDomain.CurrentDomain.GetAssemblies()
27-
|> Array.exists (fun asm -> (*asm.IsDynamic &&*)
28-
asm.GetName().Name.StartsWith(fsiAssemblyName, StringComparison.Ordinal)
29-
)
46+
|> Array.map (fun asm -> asm.GetName().Name)
47+
|> Array.exists (fun asmName -> (*asm.IsDynamic &&*)
48+
asmName.StartsWith(fsiAssemblyName, StringComparison.Ordinal))
3049

3150
state <-
3251
try
@@ -51,7 +70,9 @@ let doInit () =
5170
// see #121: It's important to not touch the logDebugMessages
5271
// value when it was already set before this init function was called.
5372
match Fsi.logDebugMessages with
54-
| None -> Fsi.enableDebugLogs ()
73+
| None ->
74+
do logPxlClockOnFirstSend ()
75+
Fsi.enableDebugLogs ()
5576
| _ -> ()
5677

5778
let addPrinter (f: 'a -> string) =
@@ -80,4 +101,5 @@ let doInit () =
80101

81102
state
82103

83-
let init () = doInit () |> ignore
104+
let init () =
105+
doInit () |> ignore

src/FsHttp/Request.fs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -131,29 +131,10 @@ let toRequestAndMessage (request: IToRequest) : Request * HttpRequestMessage =
131131
let toRequest request = request |> toRequestAndMessage |> fst
132132
let toHttpRequestMessage request = request |> toRequestAndMessage |> snd
133133

134-
let logPxlClockOnFirstSend =
135-
let mutable firstSend = true
136-
fun () ->
137-
if firstSend then
138-
firstSend <- false
139-
let msg = @"
140-
141-
+---------+
142-
| | PXL-JAM 2024
143-
| PXL | - github.com/CuminAndPotato/PXL-JAM
144-
| CLOCK | - WIN a PXL-Clock MK1
145-
| | - until 8th of January 2025
146-
+---------+
147-
148-
"
149-
Fsi.logfn "%s" msg
150-
151134
/// Builds an asynchronous request, without sending it.
152135
let toAsync cancellationTokenOverride (context: IToRequest) =
153136
async {
154137
let request, requestMessage = toRequestAndMessage context
155-
156-
do logPxlClockOnFirstSend ()
157138
do Fsi.logfn $"Sending request {addressToString request} ..."
158139

159140
use finalRequestMessage =

0 commit comments

Comments
 (0)