New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@polywrap/logger-plugin-js

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@polywrap/logger-plugin-js

Logger plugin wrapper, for use with the JS Polywrap client.

  • 0.11.0-pre.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
86
increased by45.76%
Maintainers
2
Weekly downloads
 
Created
Source

@polywrap/logger-plugin-js

The Logger plugin implements the logger-interface @ wrapscan.io/polywrap/logger@1.0.0 (see ./polywrap.graphql). By default, it logs all events using the Javascript console global object. You can circumvent this functionality by setting the logFunc property on the plugin's config (examples below).

Usage

1. Configure Client

When creating your Polywrap JS client, add the logger plugin:

import { PolywrapClient, ClientConfigBuilder } from "@polywrap/client-js";
import { loggerPlugin } from "@polywrap/logger-plugin-js";

const config = new ClientConfigBuilder()
  // 1. Add the plugin package @ an arbitrary URI
  .addPackage(
    "plugin/logger",
    loggerPlugin({ })
  )
  // 2. Register this plugin as an implementation of the interface
  .addInterfaceImplementation(
    "wrapscan.io/polywrap/logger@1.0",
    "plugin/logger"
  )
  // 3. Redirect invocations @ the interface to the plugin (default impl)
  .addRedirect(
    "wrapscan.io/polywrap/logger@1.0",
    "plugin/logger"
  )
  .build();

const client = new PolywrapClient(config));

2. Invoke The Logger

Invocations to the logger plugin can be made via the interface URI (which will get redirected), or the plugin's URI directly:

await client.invoke({
  uri: "wrapscan.io/polywrap/logger@1.0" | "plugin/logger",
  method: "log",
  args: {
    level: "INFO",
    message: "foo bar baz"
  }
});

3. Customize The Logger

When adding the logger to your client, you can add your own custom log function:

const config = new ClientConfigBuilder()
  .addPackage(
    "plugin/logger",
    loggerPlugin({
      logFunc: (level: string, message: string): void => {
        // add your own logic here...
      }
    })
  )
  .build();

const client = new PolywrapClient(config);

4. Add Multiple Loggers

Multiple logger implementations can be added to the client:

const config = new ClientConfigBuilder()
  .addPackage(
    "plugin/logger",
    loggerPlugin({ })
  )
  .addPackage(
    "plugin/custom-logger",
    loggerPlugin({ logFunc: ... })
  )
  .addInterfaceImplementations(
    "wrapscan.io/polywrap/logger@1.0",
    ["plugin/logger", "plugin/custom-logger"]
  )
  .addRedirect(
    "wrapscan.io/polywrap/logger@1.0",
    "plugin/logger"
  )
  .build();

const client = new PolywrapClient(config);

5. Invoke All Logger Implementations

When you'd like to log something to more than one logger, you can invoke all implementations of the logger interface:

const result = await client.getImplementations(
  "wrapscan.io/polywrap/logger@1.0"
);

const implementations: string[] = result.ok ? result.value : [];

for (const impl of implementations) {
  await client.invoke({
    uri: impl,
    method: "log",
    args: {
      level: "INFO",
      message: "message"
    }
  });
}

FAQs

Package last updated on 26 Jul 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc