npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@vscode-logging/logger

v2.0.0

Published

Logger Library for VSCode Extensions

Downloads

734,579

Readme

@vscode-logging/logger

A Logging Library for VSCode Extension which supports the following features:

  • JSON structure log entries output.
  • Logging to a VSCode outputChannel.
  • Logging to rolling file logs.
  • Source Location Tracking.

Installation

With npm:

  • npm install @vscode-logging/logger --save

With Yarn:

  • yarn add @vscode-logging/logger

Usage

Please 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.

Basic Usage

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"
  // }
}

On ChildLoggers

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:

  • They share the same configuration (e.g logging level) as the root extension logger.
  • Child Loggers cannot change their configuration, all configuration mutation must be done via the root extension logger.
  • Child Loggers can be created from other child loggers, the label property would simply expend with the additional suffixes.
  • Child Loggers are cached using their label as the key, so repeatedly calling getChildLogger using the same label on the same Logger object would return the same childLogger object.

On sourceLocationTracking

When 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.

    • This means that this feature should not be used in productive flows.
    • Therefore A "Fatal" log entry will be logged each time this option is enabled.
  • 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.

Support

Please open issues on github.

Contributing

See CONTRIBUTING.md.

License

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.