Skip to content

Commit

Permalink
fix(telemetry): Resolve issue with color tokens in trace message
Browse files Browse the repository at this point in the history
  • Loading branch information
sullivanpj committed Sep 13, 2024
1 parent 2cf2338 commit 4965637
Show file tree
Hide file tree
Showing 32 changed files with 970 additions and 391 deletions.
27 changes: 13 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@
"adr": "pnpm log4brains adr new",
"adr-preview": "pnpm log4brains preview",
"api-extractor": "pnpm storm-docs api-extractor --outputPath=\"docs/api-reference\" --clean",
"build": "nx affected -t build --parallel=5 --nxBail --exclude=\"@storm-stack/monorepo,web-docs,nx\"",
"build-all": "nx run-many -t build --parallel=5 --nxBail --exclude=\"@storm-stack/monorepo,web-docs,nx\"",
"build": "nx affected -t build --parallel=5 --nxBail --exclude=\"@storm-stack/monorepo,nx\"",
"build-all": "nx run-many -t build --parallel=5 --nxBail --exclude=\"@storm-stack/monorepo,nx\"",
"build-apps": "nx run-many -t build --projects=apps/* --parallel=5",
"build-docs": "nx run-many -t build --projects=docs/* --parallel=5",
"build-libs": "nx run-many -t build --projects=libs/* --parallel=5",
"build-packages": "nx run-many -t build --projects=packages/* --parallel=5",
"build-prod": "nx run-many -t build --all --prod --parallel=5",
"build-tools": "nx run-many -t build --projects=tools/* --parallel=5",
"clean": "pnpm exec rimraf dist",
"clean-apps": "pnpm exec rimraf dist/apps",
"clean-components": "pnpm exec rimraf dist/components",
"clean-docs": "pnpm exec rimraf dist/docs",
"clean-libs": "pnpm exec rimraf dist/libs",
"clean-storybook": "pnpm exec rimraf dist/storybook",
"clean-packages": "pnpm exec rimraf dist/packages",
"clean-tools": "pnpm exec rimraf dist/tools",
"commit": "pnpm storm-git commit",
"dep-graph": "nx dep-graph",
Expand Down Expand Up @@ -100,13 +100,6 @@
"@nx/rollup": "19.7.3",
"@nx/rspack": "^19.7.1",
"@nx/workspace": "19.7.3",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@rslib/core": "^0.0.5",
"@rspack/cli": "^1.0.4",
"@storm-software/build-tools": "latest",
"@storm-software/config": "latest",
"@storm-software/eslint": "latest",
Expand Down Expand Up @@ -135,6 +128,7 @@
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"jest-environment-node": "29.7.0",
"knip": "5.25.2",
"lefthook": "^1.5.6",
"log4brains": "1.0.1",
"ls-lint": "^0.1.2",
Expand All @@ -145,19 +139,24 @@
"react-dom": "19.0.0-rc-f6cce072-20240723",
"react-native": "0.74.1",
"rimraf": "^5.0.5",
"rollup": "^4.21.2",
"sherif": "0.10.0",
"ts-jest": "29.1.2",
"ts-node": "10.9.2",
"tslib": "^2.6.2",
"typescript": "5.6.2",
"unbuild": "^2.0.0",
"verdaccio": "5.29.2"
},
"namespace": "@storm-stack",
"nx": {
"includedScripts": [
"lint-ls",
"lint",
"format"
"format",
"format-readme",
"format-prettier",
"format-toml",
"commit",
"release"
]
},
"pnpm": {
Expand Down
6 changes: 3 additions & 3 deletions packages/errors/src/storm-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function createStormError<TCode extends string = string>({
stack,
data
}: StormErrorOptions & { code?: TCode }): StormError<TCode> {
if (isStormError(cause)) {
if (isStormError<TCode>(cause)) {
return cause;
}

Expand Down Expand Up @@ -273,9 +273,9 @@ export class StormError<TCode extends string = string> extends Error {
return this.message
? `${this.name ? (this.code ? `${this.name} ` : this.name) : EMPTY_STRING} ${
this.code
? (this.code && this.name
? this.code && this.name
? `(${this.code})`
: this.code)
: this.code
: EMPTY_STRING
}${this.code || this.name ? ": " : EMPTY_STRING}${this.message}${
this.cause
Expand Down
17 changes: 17 additions & 0 deletions packages/logging/src/composition/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
/*-------------------------------------------------------------------
⚡ Storm Software - Storm Stack
This code was released as part of the Storm Stack project. Storm Stack
is maintained by Storm Software under the Apache-2.0 License, and is
free for commercial and private use. For more information, please visit
our licensing page.
Website: https://stormsoftware.com
Repository: https://github.com/storm-software/storm-stack
Documentation: https://stormsoftware.com/projects/storm-stack/docs
Contact: https://stormsoftware.com/contact
License: https://stormsoftware.com/projects/storm-stack/license
-------------------------------------------------------------------*/

export * from "./logger-wrapper";
20 changes: 19 additions & 1 deletion packages/logging/src/composition/logger-wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
/*-------------------------------------------------------------------
⚡ Storm Software - Storm Stack
This code was released as part of the Storm Stack project. Storm Stack
is maintained by Storm Software under the Apache-2.0 License, and is
free for commercial and private use. For more information, please visit
our licensing page.
Website: https://stormsoftware.com
Repository: https://github.com/storm-software/storm-stack
Documentation: https://stormsoftware.com/projects/storm-stack/docs
Contact: https://stormsoftware.com/contact
License: https://stormsoftware.com/projects/storm-stack/license
-------------------------------------------------------------------*/

import type { StormConfig } from "@storm-software/config";
import { getCauseFromUnknown } from "@storm-stack/errors";
import { type MaybePromise, isSet, isSetString } from "@storm-stack/types";
import { isSet, isSetString } from "@storm-stack/types/type-checks";
import { type MaybePromise } from "@storm-stack/types/utility-types";
import type { ILogger, ILoggerWrapper } from "../types";

/**
Expand Down
19 changes: 18 additions & 1 deletion packages/logging/src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
import { ErrorCode } from "@storm-stack/errors";
/*-------------------------------------------------------------------
⚡ Storm Software - Storm Stack
This code was released as part of the Storm Stack project. Storm Stack
is maintained by Storm Software under the Apache-2.0 License, and is
free for commercial and private use. For more information, please visit
our licensing page.
Website: https://stormsoftware.com
Repository: https://github.com/storm-software/storm-stack
Documentation: https://stormsoftware.com/projects/storm-stack/docs
Contact: https://stormsoftware.com/contact
License: https://stormsoftware.com/projects/storm-stack/license
-------------------------------------------------------------------*/

import { ErrorCode } from "@storm-stack/errors/errors";

export type LoggingErrorCode = ErrorCode | "logs_uninitialized";
export const LoggingErrorCode = {
Expand Down
17 changes: 17 additions & 0 deletions packages/logging/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*-------------------------------------------------------------------
⚡ Storm Software - Storm Stack
This code was released as part of the Storm Stack project. Storm Stack
is maintained by Storm Software under the Apache-2.0 License, and is
free for commercial and private use. For more information, please visit
our licensing page.
Website: https://stormsoftware.com
Repository: https://github.com/storm-software/storm-stack
Documentation: https://stormsoftware.com/projects/storm-stack/docs
Contact: https://stormsoftware.com/contact
License: https://stormsoftware.com/projects/storm-stack/license
-------------------------------------------------------------------*/

export * from "./composition";
export * from "./errors";
export * from "./storm-log";
Expand Down
24 changes: 23 additions & 1 deletion packages/logging/src/storm-log.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
/*-------------------------------------------------------------------
⚡ Storm Software - Storm Stack
This code was released as part of the Storm Stack project. Storm Stack
is maintained by Storm Software under the Apache-2.0 License, and is
free for commercial and private use. For more information, please visit
our licensing page.
Website: https://stormsoftware.com
Repository: https://github.com/storm-software/storm-stack
Documentation: https://stormsoftware.com/projects/storm-stack/docs
Contact: https://stormsoftware.com/contact
License: https://stormsoftware.com/projects/storm-stack/license
-------------------------------------------------------------------*/

import type { StormConfig } from "@storm-software/config";
import { StormTime, formatSince } from "@storm-stack/date-time";
import { StormTime } from "@storm-stack/date-time/storm-time";
import { formatSince } from "@storm-stack/date-time/utilities/format-since";
import { StormError, getCauseFromUnknown } from "@storm-stack/errors";
import type { Logger, LoggerOptions as PinoLoggerOptions } from "pino";
import pino from "pino";
Expand All @@ -26,7 +44,9 @@ import { getPinoOptions } from "./utilities/get-pino-options";
*/
export class StormLog implements IStormLog {
protected static logger: Logger<PinoLoggerOptions>;

protected static logLevel: LogLevel;

protected static logLevelLabel: LogLevelLabel;

protected static getLoggers = (): Promise<GetLoggersResult> => {
Expand Down Expand Up @@ -69,7 +89,9 @@ export class StormLog implements IStormLog {
};

#logger: Logger<PinoLoggerOptions>;

#logLevel: LogLevel;

#processes: Array<{ name: string; startedAt: StormTime }> = [];

/**
Expand Down
21 changes: 19 additions & 2 deletions packages/logging/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
import type { StormTime } from "@storm-stack/date-time";
import type { MaybePromise } from "@storm-stack/types";
/*-------------------------------------------------------------------
⚡ Storm Software - Storm Stack
This code was released as part of the Storm Stack project. Storm Stack
is maintained by Storm Software under the Apache-2.0 License, and is
free for commercial and private use. For more information, please visit
our licensing page.
Website: https://stormsoftware.com
Repository: https://github.com/storm-software/storm-stack
Documentation: https://stormsoftware.com/projects/storm-stack/docs
Contact: https://stormsoftware.com/contact
License: https://stormsoftware.com/projects/storm-stack/license
-------------------------------------------------------------------*/

import type { StormTime } from "@storm-stack/date-time/storm-time";
import type { MaybePromise } from "@storm-stack/types/utility-types";
import type pino from "pino";
import type { LogLevel, LogLevelLabel } from "./utilities/get-log-level";

Expand Down
34 changes: 30 additions & 4 deletions packages/logging/src/utilities/get-log-level.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
export type LogLevel = 0 | 10 | 20 | 30 | 40 | 60 | 70;
/*-------------------------------------------------------------------
⚡ Storm Software - Storm Stack
This code was released as part of the Storm Stack project. Storm Stack
is maintained by Storm Software under the Apache-2.0 License, and is
free for commercial and private use. For more information, please visit
our licensing page.
Website: https://stormsoftware.com
Repository: https://github.com/storm-software/storm-stack
Documentation: https://stormsoftware.com/projects/storm-stack/docs
Contact: https://stormsoftware.com/contact
License: https://stormsoftware.com/projects/storm-stack/license
-------------------------------------------------------------------*/

export type LogLevel = 0 | 10 | 20 | 30 | 40 | 60 | 70 | 100;
export const LogLevel = {
SILENT: 0 as LogLevel,
FATAL: 10 as LogLevel,
ERROR: 20 as LogLevel,
WARN: 30 as LogLevel,
INFO: 40 as LogLevel,
DEBUG: 60 as LogLevel,
TRACE: 70 as LogLevel
TRACE: 70 as LogLevel,
ALL: 100 as LogLevel
};

export type LogLevelLabel =
Expand All @@ -16,15 +34,17 @@ export type LogLevelLabel =
| "warn"
| "info"
| "debug"
| "trace";
| "trace"
| "all";
export const LogLevelLabel = {
SILENT: "silent" as LogLevelLabel,
FATAL: "fatal" as LogLevelLabel,
ERROR: "error" as LogLevelLabel,
WARN: "warn" as LogLevelLabel,
INFO: "info" as LogLevelLabel,
DEBUG: "debug" as LogLevelLabel,
TRACE: "trace" as LogLevelLabel
TRACE: "trace" as LogLevelLabel,
ALL: "all" as LogLevelLabel
};

/**
Expand All @@ -35,6 +55,9 @@ export const LogLevelLabel = {
*/
export const getLogLevel = (label: string): LogLevel => {
switch (label) {
case "all": {
return LogLevel.ALL;
}
case "trace": {
return LogLevel.TRACE;
}
Expand Down Expand Up @@ -69,6 +92,9 @@ export const getLogLevel = (label: string): LogLevel => {
* @returns The log level label
*/
export const getLogLevelLabel = (logLevel: number): LogLevelLabel => {
if (logLevel >= LogLevel.ALL) {
return LogLevelLabel.ALL;
}
if (logLevel >= LogLevel.TRACE) {
return LogLevelLabel.TRACE;
}
Expand Down
26 changes: 21 additions & 5 deletions packages/logging/src/utilities/get-pino-options.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
/*-------------------------------------------------------------------
⚡ Storm Software - Storm Stack
This code was released as part of the Storm Stack project. Storm Stack
is maintained by Storm Software under the Apache-2.0 License, and is
free for commercial and private use. For more information, please visit
our licensing page.
Website: https://stormsoftware.com
Repository: https://github.com/storm-software/storm-stack
Documentation: https://stormsoftware.com/projects/storm-stack/docs
Contact: https://stormsoftware.com/contact
License: https://stormsoftware.com/projects/storm-stack/license
-------------------------------------------------------------------*/

import type { StormConfig } from "@storm-software/config";
import { isStormError } from "@storm-stack/errors";
import { titleCase } from "@storm-stack/string-fns";
import { isRuntimeServer } from "@storm-stack/utilities";
import { isStormError } from "@storm-stack/errors/storm-error";
import { titleCase } from "@storm-stack/string-fns/title-case";
import { isRuntimeServer } from "@storm-stack/utilities/helper-fns/is-runtime-server";
import type { LoggerOptions as PinoLoggerOptions } from "pino";
import { LogLevel, getLogLevel } from "./get-log-level";
import { createErrorSerializer } from "./log-serializer";
Expand All @@ -20,8 +37,7 @@ export const getPinoOptions = (
): PinoLoggerOptions => {
config.logLevel ??= config.env === "production" ? "info" : "debug";
const _stacktrace =
stacktrace ||
(config?.env === "production" && !isRuntimeServer() ? false : true);
stacktrace || !(config?.env === "production" && !isRuntimeServer());
const errorSerializer = createErrorSerializer(_stacktrace);

const baseOptions: PinoLoggerOptions = {
Expand Down
17 changes: 17 additions & 0 deletions packages/logging/src/utilities/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*-------------------------------------------------------------------
⚡ Storm Software - Storm Stack
This code was released as part of the Storm Stack project. Storm Stack
is maintained by Storm Software under the Apache-2.0 License, and is
free for commercial and private use. For more information, please visit
our licensing page.
Website: https://stormsoftware.com
Repository: https://github.com/storm-software/storm-stack
Documentation: https://stormsoftware.com/projects/storm-stack/docs
Contact: https://stormsoftware.com/contact
License: https://stormsoftware.com/projects/storm-stack/license
-------------------------------------------------------------------*/

export * from "./get-log-level";
export * from "./get-pino-options";
export * from "./log-serializer";
Loading

0 comments on commit 4965637

Please sign in to comment.