|
17 | 17 | #r "FSharp.Formatting.CodeFormat.dll" |
18 | 18 | #r "FSharp.Formatting.ApiDocs.dll" |
19 | 19 |
|
20 | | -// Setup Logging for FSharp.Formatting and FSharp.Formatting.Internal |
21 | | -module Logging = FSharp.Formatting.Common.Log |
22 | | -type TraceOptions = System.Diagnostics.TraceOptions |
23 | | - |
24 | | -// By default, we log to console only. Other modes are enabled by setting |
25 | | -// the `FSHARP_FORMATTING_LOG` environment variable. |
26 | | -let logToFile, logToConsole = |
27 | | - match System.Environment.GetEnvironmentVariable("FSHARP_FORMATTING_LOG") with |
28 | | - | "ALL" -> true, true |
29 | | - | "NONE" -> false, false |
30 | | - | "FILE_ONLY" -> true, false |
31 | | - | _ -> false, true |
32 | | - |
33 | | -try |
34 | | - let allTraceOptions = |
35 | | - TraceOptions.Callstack ||| TraceOptions.DateTime ||| TraceOptions.LogicalOperationStack ||| |
36 | | - TraceOptions.ProcessId ||| TraceOptions.ThreadId ||| TraceOptions.Timestamp |
37 | | - let noTraceOptions = TraceOptions.None |
38 | | - let svclogFile = "FSharp.Formatting.svclog" |
39 | | - System.Diagnostics.Trace.AutoFlush <- true |
40 | | - |
41 | | - let setupListener listener = |
42 | | - [ FSharp.Formatting.Common.Log.source |
43 | | - FSharp.Formatting.Internal.Log.source ] |
44 | | - |> Seq.iter (fun source -> |
45 | | - source.Switch.Level <- System.Diagnostics.SourceLevels.All |
46 | | - Logging.AddListener listener source) |
47 | | - |
48 | | - if logToConsole then |
49 | | - Logging.ConsoleListener() |
50 | | - |> Logging.SetupListener noTraceOptions System.Diagnostics.SourceLevels.Verbose |
51 | | - |> setupListener |
52 | | - |
53 | | - // Test that everything works |
54 | | - Logging.infof "FSharp.Formatting Logging setup!" |
55 | | - FSharp.Formatting.Internal.Log.infof "FSharp.Formatting.Internal Logging setup!" |
56 | | -with e -> |
57 | | - printfn "FSharp.Formatting Logging setup failed: %A" e |
0 commit comments