Continuously logging in F#

Viewed 258

I'm trying to create 2 logging functions: one is to directly print to stdout, another is to print with an antecedent string [Error].

let log message =
    printfn message

let twError (tw:System.IO.TextWriter) message =
    tw.Write("[Error] {0}", message)

let error (message:Printf.StringFormat<_>) =
    let format = Printf.TextWriterFormat<_>(sprintf "[Error] %A" message)
    log format

let date = System.DateTime.Now
log "%A" twError date
error "%s" <| date.ToString()

As you can see, in the error function I need to make a new string, then convert it to a TextWriterFormat type. But this will be less efficient than writing directly to the stream, how should I change the error function to make it more efficient?

1 Answers
Related