
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
@vscode-logging/logger
Advanced tools
A Logging Library for VSCode Extension which supports the following features:
With npm:
npm install @vscode-logging/logger --saveWith Yarn:
yarn add @vscode-logging/loggerPlease see the TypeScript Definitions for full API details.
Runnable and documented usage examples can be found in the examples folder. It is recommended to review these examples as integrating @vscode-logging/logger into a VSCode Extension necessitates multiple changes, mainly around managing the configuration options as user exposed settings.
The only function exposed (directly) by @vscode-logging/logger is getExtensionLogger which
should be invoked by a VSCode extension's activate() function.
const { getExtensionLogger } = require("@vscode-logging/logger");
function activate(context) {
const extLogger = getExtensionLogger({
extName: "MyExtName",
level: "info", // See LogLevel type in @vscode-logging/types for possible logLevels
logPath: context.logPath, // The logPath is only available from the `vscode.ExtensionContext`
logOutputChannel: logOutputChannel, // OutputChannel for the logger
sourceLocationTracking: false,
logConsol: false // define if messages should be logged to the consol
});
extLogger.warn("Hello World");
// Will Log The following entry to **both**
// - To outputChannel `logOutputChannel`
// - To log files in `logPath`
// {
// "label": "MyExtName",
// "level": "warn",
// "message": "Hello World",
// "time": "2020-01-10 15:29:52.038Z"
// }
}
The getChildLogger API is available on the interface returned by getExtensionLogger.
This can be used to obtain sub logger which log to the same targets (outChannel/files) as
the root logger, but with a more specific label.
const { getExtensionLogger } = require("@vscode-logging/logger");
const extLogger = getExtensionLogger({ extName: "MyExtName" /* ... */ });
const childLogger = extLogger.getChildLogger({ label: "MyClass" });
childLogger.warn("Hello World");
// Will Log to the same targets as extLogger but with a suffix added to the `label`
// {
// "label": "MyExtName.MyClass", // Note the `.MyClass` suffix in the label
// "level": "warn",
// "message": "Hello World",
// "time": "2020-01-10 15:29:52.038Z"
// }
const grandChildLogger = childLogger.getChildLogger({ label: "MyMethod" });
grandChildLogger.warn("Hip Hip Hurray");
// {
// "label": "MyExtName.MyClass.MyMethod", // Note the `.MyMethod` suffix in the label
// "level": "warn",
// "message": "Hello World",
// "time": "2020-01-10 15:30:52.038Z"
// }
Important notes on child loggers:
label property would simply
expend with the additional suffixes.getChildLogger
using the same label on the same Logger object would return the same childLogger object.sourceLocationTrackingWhen enabled the sourceLocationTracking will augment the log entries with the function
name and location (file/line/column) where the log method was invoked, e.g:
{
"label": "osem",
"level": "error",
"message": "Hip Hip Hurray, the <Hello World> Command was executed! counter: <1>",
"source": {
"function": "registerCalback",
"location": "c:\\workspace\\vscode-logging\\examples\\extension\\lib\\commands.js:21:19"
},
"time": "2020-01-11 11:51:48.659Z"
}
Important things to note on sourceLocationTracking
This functionality is not guaranteed to always work.
e.g anonymous functions have no name...
Obtaining the source location information is very slow.
Processes which manipulate the source code such as bundling or compilation (TypeScript/Babel) may make the information produced less relevant due to the lack of sourceMaps support. Therefore this feature may be more useful during development flows rather then productive flows.
Please open issues on github.
See CONTRIBUTING.md.
Copyright (c) 2021 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file.
2.0.0 (2024-01-05)
getConfigurations and onDidChangeConfiguration properties
were removed from the configureLogger public APIFAQs
Logger Library for VSCode Extensions
We found that @vscode-logging/logger demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.