My though on the logging in the VS Code extension


This is an article for Visual Studio Codeのカレンダー | Advent Calendar 2022 - Qiita.

I’m a creator and maintainer of mshr-h/vscode-verilog-hdl-support, VS Code extension for hardware developers. I created it when the VS Code was released in 2015. So it’s been 7 years of maintaining.

In this article, I’ll summarize the lack of a standard way of logging implementation on the VS Code extension even in 2022!

Logging is an act of taking application information, system information, or use activities. A log is useful for such as debugging, error recovery, and improving the application. For VS Code extension, logging is also important.

When we want to output logs in the VS Code extension, we create a vscode.OutputChannel using vscode.createOutputChannel(name: string). Then we send a message to it by OutputChannel.append(message: string) for example. It only accepts a string as the message. No log severity setting, no hierarchy, and no JSONifying. We have to implement it by ourselves.

The creator of VS Code, Microsoft, is developing many great extensions such as microsoft/vscode-python and microsoft/vscode-cpptools. They both output logs to the OutputChannel. I wanted to improve my logging implementation so I’ve looked at those code bases. Surprisingly, they implement logging classes their own way. They don’t share any implementation. vscode-cpptools has a single file implementation in 141 LoC w/o comments. vscode-python has a 6 files implementation in 322 LoC w/o comments. Those have rich features, but I don’t need them. I want a more simple, and standard way.

So I’ve googled “logging vscode extension” and found a library called @vscode-logging/logger! But it hasn’t been updated since 2021/9. Looks like not maintained actively.

I’ve looked at some other extensions. prettier-vscode has nice and yet simple logging implementation with only 74 LoC! Yeah! So I’m planning to utilize the implementation in my extension.

To summarize my article, logging is one of the fundamental functions of VS Code extensions. But there’s no standard way of it. Looked at some famous extensions and they implement them in their own ways. There’s a logging library called @vscode-logging/logger but hasn’t been updated since 2021/9. prettier-vscode has a nice and simple 74 LoC logging implementation. I’m planning to use it in my extension.

Thanks for reading.