@logtail/core
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -15,2 +15,3 @@ import { ILogLevel, ILogtailLog, ILogtailOptions, Context, Middleware, Sync } from "@logtail/types"; | ||
private _countSynced; | ||
private _countDropped; | ||
/** | ||
@@ -41,2 +42,8 @@ * Initializes a new Logtail instance | ||
/** | ||
* Number of entries dropped | ||
* | ||
* @returns number | ||
*/ | ||
get dropped(): number; | ||
/** | ||
* Log an entry, to be synced with Logtail.com | ||
@@ -43,0 +50,0 @@ * |
@@ -13,6 +13,13 @@ "use strict"; | ||
batchInterval: 1000, | ||
// Maximum number of times to retry a failed sync request | ||
retryCount: 3, | ||
// Minimum number of milliseconds to wait before retrying a failed sync request | ||
retryBackoff: 100, | ||
// Maximum number of sync requests to make concurrently | ||
syncMax: 5, | ||
// If true, errors/failed logs should be ignored | ||
ignoreExceptions: true, | ||
// If true, errors when sending logs will be ignored | ||
// Has precedence over throwExceptions | ||
ignoreExceptions: false, | ||
// If true, errors when sending logs will result in a thrown exception | ||
throwExceptions: false, | ||
// maximum depth (number of attribute levels) of a context object | ||
@@ -43,2 +50,4 @@ contextObjectMaxDepth: 50, | ||
this._countSynced = 0; | ||
// Number of logs that failed to be synced to Logtail | ||
this._countDropped = 0; | ||
// First, check we have a valid source token | ||
@@ -59,3 +68,3 @@ if (typeof sourceToken !== "string" || sourceToken === "") { | ||
// Create a batcher, for aggregating logs by buffer size/interval | ||
const batcher = tools_1.makeBatch(this._options.batchSize, this._options.batchInterval); | ||
const batcher = tools_1.makeBatch(this._options.batchSize, this._options.batchInterval, this._options.retryCount, this._options.retryBackoff); | ||
this._batch = batcher.initPusher((logs) => { | ||
@@ -96,2 +105,10 @@ return throttler(logs); | ||
/** | ||
* Number of entries dropped | ||
* | ||
* @returns number | ||
*/ | ||
get dropped() { | ||
return this._countDropped; | ||
} | ||
/** | ||
* Log an entry, to be synced with Logtail.com | ||
@@ -145,9 +162,14 @@ * | ||
catch (e) { | ||
// Increment dropped count | ||
this._countDropped++; | ||
// Catch any errors - re-throw if `ignoreExceptions` == false | ||
if (!this._options.ignoreExceptions) { | ||
throw e; | ||
if (this._options.throwExceptions) { | ||
throw e; | ||
} | ||
else { | ||
// Output to console | ||
console.error(e); | ||
} | ||
} | ||
else { | ||
console.error(e); | ||
} | ||
} | ||
@@ -154,0 +176,0 @@ // Return the resulting log |
@@ -40,2 +40,6 @@ "use strict"; | ||
}); | ||
it("should default dropped count to zero", () => { | ||
const base = new base_1.default("testing"); | ||
expect(base.dropped).toEqual(0); | ||
}); | ||
it("should increment log count on `.log()`", async () => { | ||
@@ -191,7 +195,7 @@ const base = new base_1.default("testing"); | ||
}); | ||
it("should not ignore exceptions if `ignoreExceptions` opt == false", async () => { | ||
it("should not ignore exceptions if `ignoreExceptions` opt == false and `throwExceptions` opt == true", async () => { | ||
// Fixtures | ||
const message = "Testing exceptions"; | ||
const e = new Error("Should NOT be ignored!"); | ||
const base = new base_1.default("testing", { ignoreExceptions: false }); | ||
const base = new base_1.default("testing", { ignoreExceptions: false, throwExceptions: true }); | ||
// Add a mock sync method which throws an error | ||
@@ -198,0 +202,0 @@ base.setSync(async () => { |
@@ -15,2 +15,3 @@ import { ILogLevel, ILogtailLog, ILogtailOptions, Context, Middleware, Sync } from "@logtail/types"; | ||
private _countSynced; | ||
private _countDropped; | ||
/** | ||
@@ -41,2 +42,8 @@ * Initializes a new Logtail instance | ||
/** | ||
* Number of entries dropped | ||
* | ||
* @returns number | ||
*/ | ||
get dropped(): number; | ||
/** | ||
* Log an entry, to be synced with Logtail.com | ||
@@ -43,0 +50,0 @@ * |
@@ -11,6 +11,13 @@ import { LogLevel } from "@logtail/types"; | ||
batchInterval: 1000, | ||
// Maximum number of times to retry a failed sync request | ||
retryCount: 3, | ||
// Minimum number of milliseconds to wait before retrying a failed sync request | ||
retryBackoff: 100, | ||
// Maximum number of sync requests to make concurrently | ||
syncMax: 5, | ||
// If true, errors/failed logs should be ignored | ||
ignoreExceptions: true, | ||
// If true, errors when sending logs will be ignored | ||
// Has precedence over throwExceptions | ||
ignoreExceptions: false, | ||
// If true, errors when sending logs will result in a thrown exception | ||
throwExceptions: false, | ||
// maximum depth (number of attribute levels) of a context object | ||
@@ -41,2 +48,4 @@ contextObjectMaxDepth: 50, | ||
this._countSynced = 0; | ||
// Number of logs that failed to be synced to Logtail | ||
this._countDropped = 0; | ||
// First, check we have a valid source token | ||
@@ -57,3 +66,3 @@ if (typeof sourceToken !== "string" || sourceToken === "") { | ||
// Create a batcher, for aggregating logs by buffer size/interval | ||
const batcher = makeBatch(this._options.batchSize, this._options.batchInterval); | ||
const batcher = makeBatch(this._options.batchSize, this._options.batchInterval, this._options.retryCount, this._options.retryBackoff); | ||
this._batch = batcher.initPusher((logs) => { | ||
@@ -94,2 +103,10 @@ return throttler(logs); | ||
/** | ||
* Number of entries dropped | ||
* | ||
* @returns number | ||
*/ | ||
get dropped() { | ||
return this._countDropped; | ||
} | ||
/** | ||
* Log an entry, to be synced with Logtail.com | ||
@@ -143,9 +160,14 @@ * | ||
catch (e) { | ||
// Increment dropped count | ||
this._countDropped++; | ||
// Catch any errors - re-throw if `ignoreExceptions` == false | ||
if (!this._options.ignoreExceptions) { | ||
throw e; | ||
if (this._options.throwExceptions) { | ||
throw e; | ||
} | ||
else { | ||
// Output to console | ||
console.error(e); | ||
} | ||
} | ||
else { | ||
console.error(e); | ||
} | ||
} | ||
@@ -152,0 +174,0 @@ // Return the resulting log |
@@ -35,2 +35,6 @@ import Base from "./base"; | ||
}); | ||
it("should default dropped count to zero", () => { | ||
const base = new Base("testing"); | ||
expect(base.dropped).toEqual(0); | ||
}); | ||
it("should increment log count on `.log()`", async () => { | ||
@@ -186,7 +190,7 @@ const base = new Base("testing"); | ||
}); | ||
it("should not ignore exceptions if `ignoreExceptions` opt == false", async () => { | ||
it("should not ignore exceptions if `ignoreExceptions` opt == false and `throwExceptions` opt == true", async () => { | ||
// Fixtures | ||
const message = "Testing exceptions"; | ||
const e = new Error("Should NOT be ignored!"); | ||
const base = new Base("testing", { ignoreExceptions: false }); | ||
const base = new Base("testing", { ignoreExceptions: false, throwExceptions: true }); | ||
// Add a mock sync method which throws an error | ||
@@ -193,0 +197,0 @@ base.setSync(async () => { |
{ | ||
"name": "@logtail/core", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Logtail.com - logging core", | ||
@@ -43,6 +43,6 @@ "keywords": [ | ||
"dependencies": { | ||
"@logtail/tools": "^0.3.0", | ||
"@logtail/types": "^0.3.0" | ||
"@logtail/tools": "^0.4.0", | ||
"@logtail/types": "^0.4.0" | ||
}, | ||
"gitHead": "86cb9542d2a1c12dcaa3104afb8df5c2c4a21ff5" | ||
"gitHead": "a082eb0e7f83763a3f81d42736dd14d40e19d128" | ||
} |
@@ -49,2 +49,8 @@ import Base from "./base"; | ||
it("should default dropped count to zero", () => { | ||
const base = new Base("testing"); | ||
expect(base.dropped).toEqual(0); | ||
}); | ||
it("should increment log count on `.log()`", async () => { | ||
@@ -258,7 +264,7 @@ const base = new Base("testing"); | ||
it("should not ignore exceptions if `ignoreExceptions` opt == false", async () => { | ||
it("should not ignore exceptions if `ignoreExceptions` opt == false and `throwExceptions` opt == true", async () => { | ||
// Fixtures | ||
const message = "Testing exceptions"; | ||
const e = new Error("Should NOT be ignored!"); | ||
const base = new Base("testing", { ignoreExceptions: false }); | ||
const base = new Base("testing", { ignoreExceptions: false, throwExceptions: true }); | ||
@@ -265,0 +271,0 @@ // Add a mock sync method which throws an error |
@@ -26,8 +26,18 @@ import { | ||
// Maximum number of times to retry a failed sync request | ||
retryCount: 3, | ||
// Minimum number of milliseconds to wait before retrying a failed sync request | ||
retryBackoff: 100, | ||
// Maximum number of sync requests to make concurrently | ||
syncMax: 5, | ||
// If true, errors/failed logs should be ignored | ||
ignoreExceptions: true, | ||
// If true, errors when sending logs will be ignored | ||
// Has precedence over throwExceptions | ||
ignoreExceptions: false, | ||
// If true, errors when sending logs will result in a thrown exception | ||
throwExceptions: false, | ||
// maximum depth (number of attribute levels) of a context object | ||
@@ -71,2 +81,5 @@ contextObjectMaxDepth: 50, | ||
// Number of logs that failed to be synced to Logtail | ||
private _countDropped = 0; | ||
/* CONSTRUCTOR */ | ||
@@ -106,3 +119,5 @@ | ||
this._options.batchSize, | ||
this._options.batchInterval | ||
this._options.batchInterval, | ||
this._options.retryCount, | ||
this._options.retryBackoff | ||
); | ||
@@ -152,2 +167,11 @@ | ||
/** | ||
* Number of entries dropped | ||
* | ||
* @returns number | ||
*/ | ||
public get dropped(): number { | ||
return this._countDropped; | ||
} | ||
/** | ||
* Log an entry, to be synced with Logtail.com | ||
@@ -226,7 +250,13 @@ * | ||
} catch (e) { | ||
// Increment dropped count | ||
this._countDropped++; | ||
// Catch any errors - re-throw if `ignoreExceptions` == false | ||
if (!this._options.ignoreExceptions) { | ||
throw e; | ||
} else { | ||
console.error(e); | ||
if (this._options.throwExceptions) { | ||
throw e; | ||
} else { | ||
// Output to console | ||
console.error(e); | ||
} | ||
} | ||
@@ -233,0 +263,0 @@ } |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
90522
1703
+ Added@logtail/tools@0.4.21(transitive)
+ Added@logtail/types@0.4.20(transitive)
- Removed@logtail/tools@0.3.0(transitive)
- Removed@logtail/types@0.3.0(transitive)
- Removedcommander@1.1.1(transitive)
- Removedjs@0.1.0(transitive)
- Removedkeypress@0.1.0(transitive)
Updated@logtail/tools@^0.4.0
Updated@logtail/types@^0.4.0