Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@logtail/core

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@logtail/core - npm Package Compare versions

Comparing version 0.4.2 to 0.4.3

22

dist/cjs/base.js

@@ -24,8 +24,12 @@ "use strict";

throwExceptions: false,
// maximum depth (number of attribute levels) of a context object
// Maximum depth (number of attribute levels) of a context object
contextObjectMaxDepth: 50,
// produce a warn log when context object max depth is reached
// Produce a warn log when context object max depth is reached
contextObjectMaxDepthWarn: true,
// produce a warning when circular reference is found in context object
// Produce a warning when circular reference is found in context object
contextObjectCircularRefWarn: true,
// If true, all logs will be sent to standard console output functions (console.info, console.warn, ...)
sendLogsToConsoleOutput: false,
// If true, all logs will be sent to Better Stack
sendLogsToBetterStack: true,
};

@@ -119,2 +123,10 @@ /**

async log(message, level = types_1.LogLevel.Info, context = {}) {
if (this._options.sendLogsToConsoleOutput) {
if (["debug", "info", "warn", "error"].indexOf(level) !== -1) {
console[level](message, context);
}
else {
console.log(`[${level.toUpperCase()}]`, message, context);
}
}
// Check that we have a sync function

@@ -153,2 +165,6 @@ if (typeof this._sync !== "function") {

}
if (!this._options.sendLogsToBetterStack) {
// Return the resulting log before sending it
return transformedLog;
}
try {

@@ -155,0 +171,0 @@ // Push the log through the batcher, and sync

@@ -220,3 +220,63 @@ "use strict";

});
it("should not send any logs to Better Stack when sendLogsToBetterStack=false", async () => {
// Fixtures
const message = "Testing logging";
const base = new base_1.default("testing", {
sendLogsToBetterStack: false
});
// Add a mock sync method which counts synced logs
let logsSynced = 0;
base.setSync(async (log) => {
logsSynced++;
return log;
});
await base.debug(message);
await base.info(message);
await base.warn(message);
await base.error(message);
await base.log(message, "fatal");
await base.log(message, "http");
await base.log(message, "verbose");
await base.log(message, "silly");
// await base.log(message, "trace");
// Should sync no logs
expect(logsSynced).toBe(0);
});
it("should send all logs to console output when sendLogsToConsoleOutput=true", async () => {
// Fixtures
const message = "Testing logging";
const base = new base_1.default("testing", {
sendLogsToConsoleOutput: true,
batchInterval: 10,
});
// Add a mock sync method
base.setSync(async (log) => log);
// Mock console methods
const originalConsole = console;
const consoleOutputs = [];
console = Object.assign(Object.assign({}, console), { debug: (...args) => consoleOutputs.push(["debug", ...args]), info: (...args) => consoleOutputs.push(["info", ...args]), warn: (...args) => consoleOutputs.push(["warn", ...args]), error: (...args) => consoleOutputs.push(["error", ...args]), log: (...args) => consoleOutputs.push(["log", ...args]) });
await base.debug(message);
await base.info(message);
await base.warn(message);
await base.error(message);
await base.log(message, "fatal");
await base.log(message, "http");
await base.log(message, "verbose");
await base.log(message, "silly");
await base.log(message, "trace");
// Should sync no logs
expect(consoleOutputs).toEqual([
["debug", "Testing logging", {}],
["info", "Testing logging", {}],
["warn", "Testing logging", {}],
["error", "Testing logging", {}],
["log", "[FATAL]", "Testing logging", {}],
["log", "[HTTP]", "Testing logging", {}],
["log", "[VERBOSE]", "Testing logging", {}],
["log", "[SILLY]", "Testing logging", {}],
["log", "[TRACE]", "Testing logging", {}],
]);
console = originalConsole;
});
});
//# sourceMappingURL=base.test.js.map

@@ -22,8 +22,12 @@ import { LogLevel } from "@logtail/types";

throwExceptions: false,
// maximum depth (number of attribute levels) of a context object
// Maximum depth (number of attribute levels) of a context object
contextObjectMaxDepth: 50,
// produce a warn log when context object max depth is reached
// Produce a warn log when context object max depth is reached
contextObjectMaxDepthWarn: true,
// produce a warning when circular reference is found in context object
// Produce a warning when circular reference is found in context object
contextObjectCircularRefWarn: true,
// If true, all logs will be sent to standard console output functions (console.info, console.warn, ...)
sendLogsToConsoleOutput: false,
// If true, all logs will be sent to Better Stack
sendLogsToBetterStack: true,
};

@@ -117,2 +121,10 @@ /**

async log(message, level = LogLevel.Info, context = {}) {
if (this._options.sendLogsToConsoleOutput) {
if (["debug", "info", "warn", "error"].indexOf(level) !== -1) {
console[level](message, context);
}
else {
console.log(`[${level.toUpperCase()}]`, message, context);
}
}
// Check that we have a sync function

@@ -151,2 +163,6 @@ if (typeof this._sync !== "function") {

}
if (!this._options.sendLogsToBetterStack) {
// Return the resulting log before sending it
return transformedLog;
}
try {

@@ -153,0 +169,0 @@ // Push the log through the batcher, and sync

@@ -215,3 +215,63 @@ import Base from "./base";

});
it("should not send any logs to Better Stack when sendLogsToBetterStack=false", async () => {
// Fixtures
const message = "Testing logging";
const base = new Base("testing", {
sendLogsToBetterStack: false
});
// Add a mock sync method which counts synced logs
let logsSynced = 0;
base.setSync(async (log) => {
logsSynced++;
return log;
});
await base.debug(message);
await base.info(message);
await base.warn(message);
await base.error(message);
await base.log(message, "fatal");
await base.log(message, "http");
await base.log(message, "verbose");
await base.log(message, "silly");
// await base.log(message, "trace");
// Should sync no logs
expect(logsSynced).toBe(0);
});
it("should send all logs to console output when sendLogsToConsoleOutput=true", async () => {
// Fixtures
const message = "Testing logging";
const base = new Base("testing", {
sendLogsToConsoleOutput: true,
batchInterval: 10,
});
// Add a mock sync method
base.setSync(async (log) => log);
// Mock console methods
const originalConsole = console;
const consoleOutputs = [];
console = Object.assign(Object.assign({}, console), { debug: (...args) => consoleOutputs.push(["debug", ...args]), info: (...args) => consoleOutputs.push(["info", ...args]), warn: (...args) => consoleOutputs.push(["warn", ...args]), error: (...args) => consoleOutputs.push(["error", ...args]), log: (...args) => consoleOutputs.push(["log", ...args]) });
await base.debug(message);
await base.info(message);
await base.warn(message);
await base.error(message);
await base.log(message, "fatal");
await base.log(message, "http");
await base.log(message, "verbose");
await base.log(message, "silly");
await base.log(message, "trace");
// Should sync no logs
expect(consoleOutputs).toEqual([
["debug", "Testing logging", {}],
["info", "Testing logging", {}],
["warn", "Testing logging", {}],
["error", "Testing logging", {}],
["log", "[FATAL]", "Testing logging", {}],
["log", "[HTTP]", "Testing logging", {}],
["log", "[VERBOSE]", "Testing logging", {}],
["log", "[SILLY]", "Testing logging", {}],
["log", "[TRACE]", "Testing logging", {}],
]);
console = originalConsole;
});
});
//# sourceMappingURL=base.test.js.map

8

package.json
{
"name": "@logtail/core",
"version": "0.4.2",
"version": "0.4.3",
"description": "Logtail.com - logging core",

@@ -43,6 +43,6 @@ "keywords": [

"dependencies": {
"@logtail/tools": "^0.4.2",
"@logtail/types": "^0.4.2"
"@logtail/tools": "^0.4.3",
"@logtail/types": "^0.4.3"
},
"gitHead": "75161d956af3eed472917b6fd3a5d89face8961d"
"gitHead": "0f816cacc21b352576a5707741f9151aa1481041"
}

@@ -295,2 +295,79 @@ import Base from "./base";

});
it("should not send any logs to Better Stack when sendLogsToBetterStack=false", async () => {
// Fixtures
const message = "Testing logging";
const base = new Base("testing", {
sendLogsToBetterStack: false
});
// Add a mock sync method which counts synced logs
let logsSynced = 0
base.setSync(async (log) => {
logsSynced++;
return log;
});
await base.debug(message);
await base.info(message);
await base.warn(message);
await base.error(message);
await base.log(message, "fatal");
await base.log(message, "http");
await base.log(message, "verbose");
await base.log(message, "silly");
// await base.log(message, "trace");
// Should sync no logs
expect(logsSynced).toBe(0);
});
it("should send all logs to console output when sendLogsToConsoleOutput=true", async () => {
// Fixtures
const message = "Testing logging";
const base = new Base("testing", {
sendLogsToConsoleOutput: true,
batchInterval: 10,
});
// Add a mock sync method
base.setSync(async log => log);
// Mock console methods
const originalConsole = console
const consoleOutputs:any = []
console = {
...console,
debug: (...args: any) => consoleOutputs.push(["debug", ...args]),
info: (...args: any) => consoleOutputs.push(["info", ...args]),
warn: (...args: any) => consoleOutputs.push(["warn", ...args]),
error: (...args: any) => consoleOutputs.push(["error", ...args]),
log: (...args: any) => consoleOutputs.push(["log", ...args]),
}
await base.debug(message);
await base.info(message);
await base.warn(message);
await base.error(message);
await base.log(message, "fatal");
await base.log(message, "http");
await base.log(message, "verbose");
await base.log(message, "silly");
await base.log(message, "trace");
// Should sync no logs
expect(consoleOutputs).toEqual([
["debug", "Testing logging", {}],
["info", "Testing logging", {}],
["warn", "Testing logging", {}],
["error", "Testing logging", {}],
["log", "[FATAL]", "Testing logging", {}],
["log", "[HTTP]", "Testing logging", {}],
["log", "[VERBOSE]", "Testing logging", {}],
["log", "[SILLY]", "Testing logging", {}],
["log", "[TRACE]", "Testing logging", {}],
]);
console = originalConsole
});
});

@@ -42,10 +42,16 @@ import {

// maximum depth (number of attribute levels) of a context object
// Maximum depth (number of attribute levels) of a context object
contextObjectMaxDepth: 50,
// produce a warn log when context object max depth is reached
// Produce a warn log when context object max depth is reached
contextObjectMaxDepthWarn: true,
// produce a warning when circular reference is found in context object
// Produce a warning when circular reference is found in context object
contextObjectCircularRefWarn: true,
// If true, all logs will be sent to standard console output functions (console.info, console.warn, ...)
sendLogsToConsoleOutput: false,
// If true, all logs will be sent to Better Stack
sendLogsToBetterStack: true,
};

@@ -186,2 +192,10 @@

): Promise<ILogtailLog & TContext> {
if (this._options.sendLogsToConsoleOutput) {
if (["debug", "info", "warn", "error"].indexOf(level) !== -1) {
console[level as keyof typeof console](message, context)
} else {
console.log(`[${level.toUpperCase()}]`, message, context)
}
}
// Check that we have a sync function

@@ -241,2 +255,7 @@ if (typeof this._sync !== "function") {

if (!this._options.sendLogsToBetterStack) {
// Return the resulting log before sending it
return transformedLog as ILogtailLog & TContext;
}
try {

@@ -243,0 +262,0 @@ // Push the log through the batcher, and sync

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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