如何将 splunk-logging nodeJs 模块与 typeScript (node v14) 一起使用

How to use splunk-logging nodeJs module with typeScript (node v14)

我正在尝试使用我的打字稿代码 (nodeJS v14) 使 splunk 日志记录 tpo 值得。我找到了提到这个例子的documentation

var SplunkLogger = require("splunk-logging").Logger;

var config = {
    token: "your-token-here",
    url: "https://splunk.local:8088"
};

var Logger = new SplunkLogger(config);

var payload = {
    // Message can be anything; doesn't have to be an object
    message: {
        temperature: "70F",
        chickenCount: 500
    }
};

console.log("Sending payload", payload);
Logger.send(payload, function(err, resp, body) {
    // If successful, body will be { text: 'Success', code: 0 }
    console.log("Response from Splunk", body);
});

我遇到的问题是 1) 我是 JS 和 Typescript 的新手,2 我可以将其“翻译”为我通常使用 import {XXXXX} from "XXXXXX" 和使用 letconst,等等...

任何想法或指南将不胜感激。

您需要添加 @types/splunk-logging

import { Logger as SplunkLogger } from 'splunk-logging';

export const log = () => {

  const config = {
      token: "your-token-here",
      url: "https://splunk.local:8088"
  };

  const Logger = new SplunkLogger(config);

  const payload = {
      // Message can be anything; doesn't have to be an object
      message: {
          temperature: "70F",
          chickenCount: 500
      }
  };

  console.log("Sending payload", payload);
  Logger.send(payload, (err, resp, body)=> {
      // If successful, body will be { text: 'Success', code: 0 }
      console.log("Response from Splunk", body);
  });
};