MCPcopy
hub / github.com/nukeop/nuclear / formatLogValue

Function formatLogValue

packages/player/src/services/logger.ts:84–121  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

82};
83
84export const formatLogValue = (value: unknown): string => {
85 if (value === null) {
86 return 'null';
87 }
88
89 if (value === undefined) {
90 return 'undefined';
91 }
92
93 if (typeof value === 'string') {
94 return truncateIfNeeded(value);
95 }
96
97 if (typeof value === 'number' || typeof value === 'boolean') {
98 return String(value);
99 }
100
101 if (typeof value === 'function') {
102 const name = value.name || 'anonymous';
103 return `[Function: ${name}]`;
104 }
105
106 if (value instanceof Error) {
107 const parts = [
108 `${value.name}: ${value.message}`,
109 value.stack ? value.stack.split('\n').slice(1).join('\n') : '',
110 ].filter(Boolean);
111 return truncateIfNeeded(parts.join('\n'));
112 }
113
114 try {
115 const json = JSON.stringify(value);
116 return truncateIfNeeded(json);
117 } catch {
118 const preview = getObjectPreview(value as object);
119 return `[Unserializable object: ${preview}]`;
120 }
121};
122
123const getObjectPreview = (obj: object): string => {
124 try {

Callers 2

reportErrorFunction · 0.90
logger.test.tsFile · 0.90

Calls 2

truncateIfNeededFunction · 0.85
getObjectPreviewFunction · 0.85

Tested by

no test coverage detected