Skip to content

Commit

Permalink
Purge it with fire (#1255)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf authored Mar 31, 2024
1 parent a21c4f2 commit 6d665db
Showing 1 changed file with 2 additions and 53 deletions.
55 changes: 2 additions & 53 deletions src/FsAutoComplete.Logging/FsLibLog.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,45 +48,9 @@ module Types =
abstract member Log: Logger
abstract member MappedContext: MappedContext

#if FABLE_COMPILER
// Fable doesn't support System.Collections.Generic.Stack, so this implementation (from FCS)
// is used instead.
type Stack<'a>() =
let mutable contents = Array.zeroCreate<'a> (2)
let mutable count = 0

member buf.Ensure newSize =
let oldSize = contents.Length

if newSize > oldSize then
let old = contents
contents <- Array.zeroCreate (max newSize (oldSize * 2))
Array.blit old 0 contents 0 count

member buf.Count = count

member buf.Pop() =
let item = contents.[count - 1]
count <- count - 1
item

member buf.Peep() = contents.[count - 1]

member buf.Top(n) = [ for x in contents.[max 0 (count - n) .. count - 1] -> x ] |> List.rev

member buf.Push(x) =
buf.Ensure(count + 1)
contents.[count] <- x
count <- count + 1

member buf.IsEmpty = (count = 0)
#endif

[<AutoOpen>]
module Inner =
#if !FABLE_COMPILER
open System.Collections.Generic
#endif

/// <summary>
/// DisposableStack on Dispose will call dispose on items appended to its stack in Last In First Out.
Expand Down Expand Up @@ -310,8 +274,6 @@ module Types =
/// <returns>The amended log.</returns>
let setLogLevel (logLevel: LogLevel) (log: Log) = { log with LogLevel = logLevel }

#if !FABLE_COMPILER

let private formatterRegex =
Regex(@"(?<!{){(?<number>\d+)(?<columnFormat>:(?<format>[^}]+))?}(?!})", RegexOptions.Compiled)

Expand Down Expand Up @@ -377,7 +339,6 @@ module Types =
/// <param name="log">The log to amend.</param>
/// <returns>The amended log.</returns>
let setMessageI (message: FormattableString) (log: Log) = setMessageInterpolated message log
#endif

/// Provides operators to make writing logs more streamlined.
module Operators =
Expand Down Expand Up @@ -431,8 +392,6 @@ module Operators =
/// <returns>The amended log with the parameter added.</returns>
let (>>!!) log e = log >> Log.addException e


#if !FABLE_COMPILER
module Providers =
module SerilogProvider =
open System
Expand Down Expand Up @@ -904,27 +863,20 @@ module Providers =

let create () = MicrosoftProvider() :> ILogProvider

#endif


module LogProvider =
open System
open Types
#if !FABLE_COMPILER
open Providers
#endif
open System.Diagnostics
open Microsoft.FSharp.Quotations.Patterns

let mutable private currentLogProvider = None

let private knownProviders =
[
#if !FABLE_COMPILER
(SerilogProvider.isAvailable, SerilogProvider.create)
(MicrosoftExtensionsLoggingProvider.isAvailable, MicrosoftExtensionsLoggingProvider.create)
#endif
]
[ (SerilogProvider.isAvailable, SerilogProvider.create)
(MicrosoftExtensionsLoggingProvider.isAvailable, MicrosoftExtensionsLoggingProvider.create) ]

/// Greedy search for first available LogProvider. Order of known providers matters.
let private resolvedLogger =
Expand Down Expand Up @@ -1024,7 +976,6 @@ module LogProvider =
/// <returns></returns>
let inline getLoggerFor<'a> () = getLoggerByType (typeof<'a>)

#if !FABLE_COMPILER
let rec private getModuleType =
function
| PropertyGet(_, propertyInfo, _) -> propertyInfo.DeclaringType
Expand Down Expand Up @@ -1065,5 +1016,3 @@ type LogProvider =
mi.DeclaringType.FullName.Split('+') |> Seq.tryHead |> Option.defaultValue ""

sprintf "%s.%s" location memberName.Value |> LogProvider.getLoggerByName

#endif

0 comments on commit 6d665db

Please sign in to comment.