core icon indicating copy to clipboard operation
core copied to clipboard

How can I see the logs from `printfn` from WebSharper Interface Generator ?

Open MangelMaxime opened this issue 3 months ago • 4 comments

Hello,

I am trying to adapt/generate a binding using WIG and I see in some projects like Highcharts usage of printfn but when giving it a try I don't see any logs from my code.

How can I see the logs coming from printfn invocation?

I am using WS 9

MangelMaxime avatar Sep 23 '25 16:09 MangelMaxime

My workaround for now is to log to a file:

module Log =

    let private logFile = __SOURCE_DIRECTORY__ + "/HighchartsGenerator.log"

    let write (msg: string) =
        try
            File.AppendAllText(logFile, msg + Environment.NewLine)
        with _ -> ()

It works for debugging purpose but if I wanted to generate warnings of something similar it would be less ideal.

Also, I am thinking there is a way to see printfn log because it is used in some of the official binding but my assumption can be wrong.

MangelMaxime avatar Sep 23 '25 16:09 MangelMaxime

@MangelMaxime Might be because you have the compiler service running. Use "standalone": true in wsconfig.json or WebSharperBuildService=False environment variable.

The compiler-level fix could be is to use System.Console.SetOut with a custom TextWriter in the compiler service, because it needs to send the output lines through a Pipe for the right process waiting on that single compilation.

Jand42 avatar Sep 24 '25 07:09 Jand42

We need to figure out how these messages can be funnelled through the Booster too. @Jooseppi12 any idea why they are lost ATM?

granicz avatar Sep 24 '25 09:09 granicz

@Jand42 After trying your suggestions it seems like only export WebSharperBuildService=false work for me. However, only the logs prefixed with warning: seems to be printed.

So it seems like WS is filtering what to output, there are perhaps support for info, and other categories

Also if I have 3 projects, do I need one wsconfig.json per project? I suspect this is the reason why only when setting the env variable I do get the logs printed.

MangelMaxime avatar Sep 24 '25 11:09 MangelMaxime

In detailed MSBuild output I think you should see normal printed lines too. (but yes, still in standalone mode only, bc booster does not capture what goes to its stdout)

Where the compiler looks for the WS config json file can be configured by project property WebSharperConfigFile (defaults to wsconfig.$(MSBuildProjectName).json first if exists, then to wsconfig.json if exists)

Jand42 avatar Dec 12 '25 14:12 Jand42