Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions vsintegration/src/FSharp.Editor/Common/Logging.fs
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ type Logger [<ImportingConstructor>] ([<Import(typeof<SVsServiceProvider>)>] ser
match self.FSharpLoggingPane, msgType with
| None, _ -> ()
| Some pane, LogType.Message ->
String.Format("[F#][{0}{1}] {2}{3}", "", time, msg, Environment.NewLine)
String.Format("[{0}{1}] {2}{3}", "", time, msg, Environment.NewLine)
|> pane.OutputString
|> ignore
| Some pane, LogType.Info ->
String.Format("[F#][{0}{1}] {2}{3}", "INFO ", time, msg, Environment.NewLine)
String.Format("[{0}{1}] {2}{3}", "INFO ", time, msg, Environment.NewLine)
|> pane.OutputString
|> ignore
| Some pane, LogType.Warn ->
String.Format("[F#][{0}{1}] {2}{3}", "WARN ", time, msg, Environment.NewLine)
String.Format("[{0}{1}] {2}{3}", "WARN ", time, msg, Environment.NewLine)
|> pane.OutputString
|> ignore
| Some pane, LogType.Error ->
String.Format("[F#][{0}{1}] {2}{3}", "ERROR ", time, msg, Environment.NewLine)
String.Format("[{0}{1}] {2}{3}", "ERROR ", time, msg, Environment.NewLine)
|> pane.OutputString
|> ignore

Expand Down Expand Up @@ -112,3 +112,34 @@ module Logging =

let logExceptionWithContext (ex: Exception, context) =
logErrorf "Context: %s\nException Message: %s\nStack Trace: %s" context ex.Message ex.StackTrace

module Activity =
let listen filter =
let indent (activity: Activity) =
let rec loop (activity: Activity) n =
if activity.Parent <> null then
loop (activity.Parent) (n + 1)
else
n

String.replicate (loop activity 0) " "

let collectTags (activity: Activity) =
[ for tag in activity.Tags -> $"{tag.Key}: %A{tag.Value}" ]
|> String.concat ", "

let listener =
new ActivityListener(
ShouldListenTo = (fun source -> source.Name = FSharp.Compiler.Diagnostics.ActivityNames.FscSourceName),
Sample =
(fun context ->
if context.Name.Contains(filter) then
ActivitySamplingResult.AllDataAndRecorded
else
ActivitySamplingResult.None),
ActivityStarted = (fun a -> logMsg $"{indent a}{a.OperationName} {collectTags a}")
)

ActivitySource.AddActivityListener(listener)

let listenToAll () = listen ""
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ type internal FSharpPackage() as this =

let mutable solutionEventsOpt = None

#if DEBUG
let _logger = Logging.Activity.listenToAll ()
// Logging.Activity.listen "IncrementalBuild"
#endif

// FSI-LINKAGE-POINT: unsited init
do Microsoft.VisualStudio.FSharp.Interactive.Hooks.fsiConsoleWindowPackageCtorUnsited (this :> Package)

Expand Down