@compas/stdlib
Advanced tools
Comparing version 0.0.132 to 0.0.133
136
index.d.ts
@@ -1,2 +0,1 @@ | ||
import { Logger } from "@compas/insight"; | ||
import { ExecOptions, SpawnOptions } from "child_process"; | ||
@@ -334,1 +333,136 @@ | ||
export function isStaging(): boolean; | ||
/** | ||
* The logger only has two severities: | ||
* - info | ||
* - error | ||
* | ||
* Either a log line is innocent enough and only provides debug information if needed, or | ||
* someone should be paged because something goes wrong. For example handled 500 errors | ||
* don't need any ones attention, but unhandled 500 errors do. | ||
* | ||
* The log functions {@ee Logger#info} only accepts a single parameter. This prevents magic | ||
* outputs like automatic concatenating strings in to a single message, or always having a top | ||
* level array as a message. | ||
*/ | ||
export interface Logger { | ||
info(arg: any): void; | ||
error(arg: any): void; | ||
} | ||
/** | ||
* Context that should be logged in all log lines. e.g | ||
* a common request id. | ||
*/ | ||
interface LoggerContext { | ||
type?: string; | ||
} | ||
export interface LoggerOptions<T extends LoggerContext> { | ||
/** | ||
* Replaces log.info with a 'noop'.Defaults to 'false'. | ||
*/ | ||
disableInfoLogger?: true | undefined; | ||
/** | ||
* Replaces log.error with a 'noop'.Defaults to 'false'. | ||
*/ | ||
disableErrorLogger?: true | undefined; | ||
/** | ||
* Set the printer to be used. Defaults to "pretty" when 'NODE_ENV===development', | ||
* "github-actions" when 'GITHUB_ACTIONS===true' and "ndjson" by default. | ||
*/ | ||
printer?: "pretty" | "ndjson" | "github-actions" | undefined; | ||
/** | ||
* The stream to write the logs to | ||
*/ | ||
stream?: NodeJS.WriteStream; | ||
/** | ||
* Context that should be logged in all log lines. e.g | ||
* a common request id. | ||
*/ | ||
ctx?: T; | ||
} | ||
/** | ||
* Create a new logger | ||
* | ||
*/ | ||
export function newLogger<T extends LoggerContext>( | ||
options?: LoggerOptions<T>, | ||
): Logger; | ||
/** | ||
* Format bytes, with up to 2 digits after the decimal point, in a more human readable way | ||
* Support up to a pebibyte | ||
*/ | ||
export function bytesToHumanReadable(bytes?: number): string; | ||
/** | ||
* Prints the memory usage of the current process to the provided logger | ||
* For more info on the printed properties see: | ||
* https://nodejs.org/dist/latest-v13.x/docs/api/process.html#process_process_memoryusage | ||
*/ | ||
export function printProcessMemoryUsage(logger: Logger): void; | ||
/** | ||
* Basic timing and call information | ||
*/ | ||
export type InsightEventCall = | ||
| { | ||
type: "start" | "stop"; | ||
name: string; | ||
/** | ||
* Time in milliseconds since some kind of epoch, this may be unix epoch or process start | ||
*/ | ||
time: number; | ||
} | ||
| InsightEventCall[]; | ||
/** | ||
* Encapsulate the base information needed to dispatch events | ||
*/ | ||
export interface InsightEvent { | ||
log: Logger; | ||
signal?: AbortSignal; | ||
/** | ||
* If event is first event dispatched in chain | ||
*/ | ||
root: boolean; | ||
name?: string; | ||
callStack: InsightEventCall[]; | ||
} | ||
/** | ||
* Create a new event from a single logger | ||
*/ | ||
export function newEvent(logger: Logger, signal?: AbortSignal): InsightEvent; | ||
/** | ||
* Create a 'child' event, reuses the logger, adds callstack to the passed event | ||
*/ | ||
export function newEventFromEvent(event: InsightEvent): InsightEvent; | ||
/** | ||
* Track event start times and set a name | ||
*/ | ||
export function eventStart(event: InsightEvent, name: string): void; | ||
/** | ||
* Rename event, can only be done if `eventStop` is not called yet. | ||
*/ | ||
export function eventRename(event: InsightEvent, name: string): void; | ||
/** | ||
* Track event stop, and log callStack if event#root === true | ||
*/ | ||
export function eventStop(event: InsightEvent): void; |
12
index.js
@@ -40,1 +40,13 @@ export { uuid } from "./src/datatypes.js"; | ||
} from "./src/utils.js"; | ||
export { newLogger } from "./src/logger/logger.js"; | ||
export { bytesToHumanReadable, printProcessMemoryUsage } from "./src/memory.js"; | ||
export { | ||
newEvent, | ||
eventStart, | ||
eventRename, | ||
eventStop, | ||
newEventFromEvent, | ||
} from "./src/events.js"; |
{ | ||
"name": "@compas/stdlib", | ||
"version": "0.0.132", | ||
"version": "0.0.133", | ||
"description": "All kinds of utility functions", | ||
@@ -12,9 +12,9 @@ "main": "./index.js", | ||
"stdlib", | ||
"standard" | ||
"standard", | ||
"logger" | ||
], | ||
"license": "MIT", | ||
"dependencies": { | ||
"@compas/insight": "0.0.132", | ||
"@types/node": "15.0.2", | ||
"dotenv": "8.4.0", | ||
"dotenv": "9.0.0", | ||
"lodash.merge": "4.6.2" | ||
@@ -43,3 +43,3 @@ }, | ||
}, | ||
"gitHead": "049d95d965630ecf2d38c69df0e375a27f058ee3" | ||
"gitHead": "44a7cf7b76fb0c1f572adcda9565b3dd8f324058" | ||
} |
@@ -51,10 +51,2 @@ # @compas/stdlib | ||
**@compas/insight**: | ||
- A structured logger | ||
- Writing newline delimited JSON in production | ||
- Pretty printing for development | ||
- Various utilities to get insight in the running process | ||
- A manual event system | ||
**@compas/stdlib**: | ||
@@ -67,2 +59,7 @@ | ||
- Replacements for CommonJS `__dirname` and `__filename` | ||
- A structured logger | ||
- Writing newline delimited JSON in production | ||
- Pretty printing for development | ||
- Various utilities to get insight in the running process | ||
- A manual event system | ||
@@ -69,0 +66,0 @@ **@compas/server**: |
@@ -6,3 +6,3 @@ import { lstatSync, realpathSync } from "fs"; | ||
import { runInNewContext } from "vm"; | ||
import { newLogger } from "@compas/insight"; | ||
import { newLogger } from "@compas/stdlib"; | ||
import dotenv from "dotenv"; | ||
@@ -9,0 +9,0 @@ import { refreshEnvironmentCache } from "./env.js"; |
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
51714
3
19
1780
122
6
+ Addeddotenv@9.0.0(transitive)
- Removed@compas/insight@0.0.132
- Removed@compas/insight@0.0.132(transitive)
- Removeddotenv@8.4.0(transitive)
Updateddotenv@9.0.0