Suave is a simple web development F# library providing a lightweight web server and a set of combinators to manipulate route flow and task composition.

Download this project as a .zip file Download this project as a tar.gz file
View on GitHub

Getting Hold of Suave’s Logs

Current documentation for configuring Suave is either in this sample or in the Logary readme.

Here is an example of using Logary via Facade adapter 4.0 + with Suave ver. 2.0+

open Logary
open Logary.Configuration
open Logary.Targets
open Logary.Adapters.Facade

//init logger
let logary = 
        withLogaryManager "ExampleLogger" (
            withTargets [
                LiterateConsole.create LiterateConsole.empty "console"
            ]
            >> withRules [ Rule.createForTarget "console"]
            )
        |> Hopac.Hopac.run
        
//get logger for API
let logger = Logging.getLoggerByName("Suave.API")

let webConfig =
  { defaultConfig with
      logger   = LoggerAdapter.createGeneric logger)
  }

The below details how to configure Suave v1.x with Logary v3.x:

When you are using suave you will probably want to funnel all logs from the output to your own log sink. We provide the interface Logger to do that; just set the property logger in the configuration to an instance of your thread-safe logger. An example:

type MyHackLogger(minLevel) =
  interface Logger with
    member x.Log level fLine =
      if level >= minLevel then
        // don't do this for real ;)
        System.Windows.Forms.MessageBox.Show((fLine ()).message)

You can use Logary for integrated logging:

Install-Package Logary.Adapters.Suave

Use the SuaveAdapter type to set the Logger in Suave’s configuration:

open Suave.Logging

use logary =
  withLogary' "logibit.web" (
    withTargets [
      Console.create Console.empty "console"
      Debugger.create Debugger.empty "debugger"
    ] >>
    withMetrics (Duration.FromMilliseconds 5000L) [
      WinPerfCounters.create (WinPerfCounters.Common.cpuTimeConf) "wperf"
(Duration.FromMilliseconds 300L)
      ] >>
      withRules [
        Rule.createForTarget "console"
        Rule.createForTarget "debugger"
      ]
    )

let webConfig =
  { defaultConfig with
      logger   = SuaveAdapter(logary.GetLogger "suave")
  }