@likec4/log 1.55.1 → 1.57.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/libs/is-error-instance.mjs +1 -0
- package/dist/chunks/libs/is-plain-obj.mjs +1 -0
- package/dist/chunks/libs/merge-error-cause.mjs +2 -0
- package/dist/chunks/libs/safe-stringify.mjs +1 -0
- package/dist/chunks/rolldown-runtime.mjs +1 -0
- package/dist/formatters.d.mts +46 -0
- package/dist/formatters.mjs +6 -0
- package/dist/index.d.mts +8 -97
- package/dist/index.mjs +1 -268
- package/dist/sink.d.mts +19 -0
- package/dist/sink.mjs +1 -0
- package/dist/utils.d.mts +59 -0
- package/dist/utils.mjs +5 -0
- package/package.json +6 -6
- package/src/formatters.ts +8 -0
- package/dist/THIRD-PARTY-LICENSES.md +0 -76
- package/dist/_chunks/libs/is-error-instance.mjs +0 -22
- package/dist/_chunks/libs/is-plain-obj.mjs +0 -6
- package/dist/_chunks/libs/merge-error-cause.mjs +0 -642
- package/dist/_chunks/libs/safe-stringify.mjs +0 -19
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"../rolldown-runtime.mjs";const isErrorInstance=e=>isInstanceOfError(e)||hasErrorTag(e),isInstanceOfError=e=>{try{return e instanceof Error}catch{return!1}},hasErrorTag=t=>{try{return e.has(Object.prototype.toString.call(t))}catch{return!1}},e=new Set([`[object Error]`,`[object DOMException]`,`[object DOMError]`,`[object Exception]`]);export{isErrorInstance as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"../rolldown-runtime.mjs";function isPlainObject(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}export{isPlainObject as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{t as e}from"../rolldown-runtime.mjs";import{t}from"./is-error-instance.mjs";import{t as n}from"./is-plain-obj.mjs";const normalizeDescriptors=e=>{r.forEach(t=>{i(e,t)})},r=[`name`,`message`,`stack`,`cause`,`errors`],i=e((e,t)=>{let n=getDescriptor(e,t);if(n!==void 0){if(isReadonlyGetter(n)){a(e,t,e[t]);return}isInvalidDescriptor(n)&&setErrorDescriptor(e,t,n)}},`normalizeDescriptor`),getDescriptor=(e,t)=>{let n=Object.getOwnPropertyDescriptor(e,t);if(n!==void 0)return n;let r=Object.getPrototypeOf(e);return r===null?void 0:getDescriptor(r,t)},isReadonlyGetter=({get:e,set:t})=>e!==void 0&&t===void 0,isInvalidDescriptor=({enumerable:e,writable:t})=>e||!t,a=e((e,t,n)=>{setErrorDescriptor(e,t,{value:n})},`setErrorProperty`),setErrorDescriptor=(e,t,n)=>{Object.defineProperty(e,t,{...n,...`get`in n||`set`in n?{}:{writable:!0},enumerable:!1,configurable:!0})},normalizeAggregate=(e,t)=>{Array.isArray(e.errors)?a(e,`errors`,e.errors.filter(isDefined).map(t).filter(Boolean)):isAggregateError(e)?a(e,`errors`,[]):e.errors!==void 0&&deleteAggregateErrors(e)},isDefined=e=>e!==void 0,isAggregateError=e=>`AggregateError`in globalThis&&(e.name===`AggregateError`||e instanceof AggregateError),deleteAggregateErrors=e=>{delete e.errors,e.errors!==void 0&&a(e,`errors`,[])},normalizeCause=(e,t)=>{if(!(`cause`in e))return;let n=e.cause===void 0?e.cause:t(e.cause);n===void 0?delete e.cause:a(e,`cause`,n)},isNonModifiableError=e=>!Object.isExtensible(e)||r.some(t=>isNonConfigurableProp(e,t)||isThrowingProp(e,t)),isNonConfigurableProp=(e,t)=>{let n=Object.getOwnPropertyDescriptor(e,t);return n!==void 0&&!n.configurable},isThrowingProp=(e,t)=>{try{return e[t],!1}catch{return!0}},setStack=e=>{a(e,`stack`,o(e.message,e.name))},o=e((e=``,t=`Error`)=>{let{stack:n}=new(getErrorClass(t))(e);return typeof n==`string`&&n!==``?n:`${t}: ${e}`},`getStack`),getErrorClass=e=>{let t={value:e,enumerable:!1,writable:!0,configurable:!0},n=Object.defineProperty(class extends Error{},"name",t);return Object.defineProperty(n.prototype,"name",t),n},copyObject=e=>{let t={};for(let n of getPropsToCopy(e))try{let r=e[n],{enumerable:i,configurable:a,writable:o=!0}=getDescriptor(e,n);Object.defineProperty(t,n,{value:r,enumerable:i,configurable:a,writable:o})}catch{}return t},getPropsToCopy=e=>{let t=getOwnKeys(e);for(let n of r)isInheritedProp(e,n)&&t.push(n);return t},getOwnKeys=e=>{try{return Reflect.ownKeys(e)}catch{return[]}},isInheritedProp=(e,t)=>{try{return t in e&&!Object.hasOwn(e,t)}catch{return!1}},objectifyError=e=>{let{name:t,message:n,stack:r,cause:i,errors:a,...o}=copyObject(e),c=s(n,o),l=newError(t,c);return n===c&&assignObjectProps(l,o),Object.entries({name:t,stack:r,cause:i,errors:a}).forEach(([e,t])=>{setNewErrorProperty(l,e,t)}),r===void 0&&setStack(l),l},s=e((e,t)=>typeof e==`string`&&e!==``?e:truncateMessage(safeJsonStringify(t)),`getMessage`),safeJsonStringify=e=>{try{return JSON.stringify(e)}catch{return safeStringify(e)}},safeStringify=e=>{try{return String(e)}catch{return`Invalid error`}},truncateMessage=e=>e.length<c?e:`${e.slice(0,c)}...`,c=1e3,newError=(e,t)=>e===`AggregateError`&&`AggregateError`in globalThis?AggregateError([],t):e in l?new l[e](t):Error(t),l={Error,ReferenceError,TypeError,SyntaxError,RangeError,URIError,EvalError},assignObjectProps=(e,t)=>{for(let n in t)n in e||(e[n]=t[n])},setNewErrorProperty=(e,t,n)=>{n!==void 0&&a(e,t,n)},stringifyError=e=>{try{let t=Error(String(e));return setStack(t),t}catch(e){return e}},{toString:u}=Object.prototype,createError=e=>isErrorPlainObj(e)?objectifyError(e):t(e)?isInvalidError(e)?objectifyError(e):e:stringifyError(e),isErrorPlainObj=e=>{try{return n(e)}catch{return!1}},isInvalidError=e=>isProxy(e)||isNonModifiableError(e)||hasInvalidConstructor(e),isProxy=e=>{try{return u.call(e)===`[object Object]`}catch{return!0}},hasInvalidConstructor=e=>typeof e.constructor!=`function`||typeof e.constructor.name!=`string`||e.constructor.name===``||e.constructor.prototype!==Object.getPrototypeOf(e),normalizeException=(e,{shallow:t=!1}={})=>recurseException(e,[],t),recurseException=(e,t,n)=>{if(t.includes(e))return;let r=n?identity:r=>recurseException(r,[...t,e],n),i=createError(e);return normalizeProps(i,r),i},identity=e=>e,normalizeProps=(e,t)=>{normalizeName(e),normalizeMessage(e),normalizeStack(e),normalizeCause(e,t),normalizeAggregate(e,t),normalizeDescriptors(e)},normalizeName=e=>{if(d(e.name))return;let t=Object.getPrototypeOf(e).name;a(e,`name`,d(t)?t:e.constructor.name)},normalizeMessage=e=>{d(e.message)||a(e,`message`,``)},normalizeStack=e=>{d(e.stack)||setStack(e)},d=e(e=>typeof e==`string`&&e!==``,`isDefinedString`),f=e((e,t,n=e.name)=>{if(validateErrorClass(t),typeof n!=`string`)throw TypeError(`currentName must be a string: ${n}`);return n},`normalizeArgs`),validateErrorClass=e=>{if(!isClass(e))throw TypeError(`ErrorClass must be a class: ${e}`);if(!isErrorClass(e.prototype))throw TypeError(`ErrorClass must inherit from Error: ${e}`);if(!hasConstructor(e))throw TypeError(`ErrorClass must be have a valid constructor: ${e}`)},isClass=e=>typeof e==`function`&&typeof e.prototype==`object`&&e.prototype!==null,isErrorClass=e=>e!==null&&(e.name===`Error`||isErrorClass(Object.getPrototypeOf(e))),hasConstructor=e=>typeof e.prototype.constructor==`function`,p=e((e,t,n)=>{Object.defineProperty(e,t,{value:n,enumerable:!1,writable:!0,configurable:!0})},`setNonEnumProp`),updatePrototype=(e,t)=>{Object.getPrototypeOf(e)!==t.prototype&&(setPrototype(e,t),deleteOwnProperty(e,`constructor`),fixName(e,t))},setPrototype=(e,t)=>{Object.setPrototypeOf(e,t.prototype)},fixName=(e,t)=>{deleteOwnProperty(e,`name`);let n=getClassName(t.prototype);e.name!==n&&p(e,`name`,n)},getClassName=e=>getPrototypeName(e)??getConstructorName(e)??getClassName(Object.getPrototypeOf(e)),getPrototypeName=e=>Object.hasOwn(e,`name`)&&isDefinedString(e.name)?e.name:void 0,getConstructorName=e=>typeof e.constructor==`function`&&isDefinedString(e.constructor.name)?e.constructor.name:void 0,isDefinedString=e=>typeof e==`string`&&e!==``,deleteOwnProperty=(e,t)=>{Object.hasOwn(e,t)&&delete e[t]},m=e((e,t)=>{shouldUpdateStack(e,t)&&p(e,`stack`,g(e,t))},`updateStack`),shouldUpdateStack=(e,t)=>t!==e.name&&t!==``&&e.stack.includes(t)&&stackIncludesName(),stackIncludesName=()=>{class StackError extends Error{}let e={value:h,enumerable:!1,writable:!0,configurable:!0};Object.defineProperty(StackError,"name",e),Object.defineProperty(StackError.prototype,"name",e);let{stack:t}=new StackError(``);return typeof t==`string`&&t.includes(h)},h=`SetErrorClassError`,g=e(({name:e,stack:t},n)=>{if(t.startsWith(`${n}: `))return t.replace(n,e);let[r,i]=_(n,e).find(([e])=>t.includes(e));return t.replace(r,i)},`getStack`),_=e((e,t)=>[[`\n${e}: `,`\n${t}: `],[`${e}: `,`${t}: `],[`${e} `,`${t} `],[e,t]],`getReplacers`),setErrorClass=(e,t,n)=>{let r=normalizeException(e),i=f(r,t,n);return updatePrototype(r,t),m(r,i),r},mergeDescriptors=(e,t)=>t.configurable===!1?mergeNonConfig(e,t):mergeConfig(e,t),mergeNonConfig=(e,t)=>({...t,...getNonConfigWritable(e,t),...getNonConfigValue(e,t)}),getNonConfigWritable=(e,t)=>t.writable===!0&&e.writable===!1?{writable:!1}:{},getNonConfigValue=(e,t)=>e.hasValue&&`value`in t&&t.writable===!0?{value:e.value}:{},mergeConfig=(e,t)=>{let n=mergeDescriptor(e.enumerable,t.enumerable,!0),r=mergeDescriptor(e.writable,t.writable,!0),i=mergeDescriptor(e.configurable,t.configurable,!0);return{...mergeValue(e,t,r),enumerable:n,configurable:i}},mergeValue=(e,t,n)=>e.hasValue?{value:e.value,writable:n}:!hasGetSet(e)&&!hasGetSet(t)?{value:t.value,writable:n}:{get:mergeDescriptor(e.get,t.get),set:mergeDescriptor(e.set,t.set)},hasGetSet=({get:e,set:t})=>e!==void 0||t!==void 0,mergeDescriptor=(e,t,n)=>e??t??n,normalizeInput=(e,t,n)=>{if(!isAnyObj(e))throw TypeError(`Argument must be an object: ${e}`);if(!isValidKey(t))throw TypeError(`Property key must be a string, a symbol or an integer: ${t}`);return normalizeDescriptor(n)},isAnyObj=e=>typeof e==`object`&&!!e,isValidKey=e=>{let t=typeof e;return t===`string`||t===`symbol`||t===`number`},normalizeDescriptor=e=>{if(!n(e))throw TypeError(`Descriptor must be a plain object: ${e}`);let{enumerable:t,writable:r,configurable:i,value:a,get:o,set:s,...c}=e,l=`value`in e;return validateDescriptor({enumerable:t,writable:r,configurable:i,get:o,set:s,unknownProps:c,hasValue:l}),{enumerable:t,writable:r,configurable:i,value:a,get:o,set:s,hasValue:l}},validateDescriptor=({enumerable:e,writable:t,configurable:n,get:r,set:i,unknownProps:a,hasValue:o})=>{validateGetSet(o,r,`get`),validateGetSet(o,i,`set`),validateBoolean(e,`enumerable`),validateBoolean(t,`writable`),validateBoolean(n,`configurable`),validateUnknownProps(a)},validateGetSet=(e,t,n)=>{if(validateFunction(t,n),e&&t!==void 0)throw TypeError(`Descriptor property "value" and "${n}" must not both be defined: ${t}`)},validateFunction=(e,t)=>{if(e!==void 0&&typeof e!=`function`)throw TypeError(`Descriptor property "${t}" must be a function: ${e}`)},validateBoolean=(e,t)=>{if(e!==void 0&&typeof e!=`boolean`)throw TypeError(`Descriptor property "${t}" must be a boolean: ${e}`)},validateUnknownProps=e=>{let[t]=Object.keys(e);if(t!==void 0)throw TypeError(`Unknown descriptor property "${t}": ${e[t]}`)},redefineProperty=(e,t,n)=>(setProperty(e,t,mergeDescriptors(normalizeInput(e,t,n),getCurrentDescriptor(e,t))),e),getCurrentDescriptor=(e,t)=>{let n=Object.getOwnPropertyDescriptor(e,t);if(n!==void 0)return n;let r=Object.getPrototypeOf(e);return r===null?{}:getCurrentDescriptor(r,t)},setProperty=(e,t,n)=>{try{Object.defineProperty(e,t,n)}catch{}},assignProp=(e,t,n)=>{if(n!==void 0)return setProp(e,t,n);try{delete e[t]}catch{}if(e[t]!==void 0)return setProp(e,t)},setProp=(e,t,n)=>{redefineProperty(e,t,{value:n,...getNonEnum(t)})},getNonEnum=e=>typeof e==`string`&&e.startsWith(`_`)?{enumerable:!1}:{},normalizeOptions=(e,t,r={})=>{if(validateErrorOrObject(e,`First argument`),validateErrorOrObject(t,`Second argument`),!n(r))throw TypeError(`Options must be a plain object: ${r}`);let{soft:i=!1}=r;if(typeof i!=`boolean`)throw TypeError(`Option "soft" must be a boolean: ${i}`);return{soft:i}},validateErrorOrObject=(e,t)=>{if(e===void 0)throw TypeError(`${t} is required.`);if(!isErrorOrObject(e))throw TypeError(`${t} must be a plain object or an error: ${e}`)},isErrorOrObject=e=>n(e)||t(e),shouldSkipProp=({error:e,props:t,propName:n,soft:r})=>isIgnoredPropName(n)||!b.call(t,n)||r&&e[n]!==void 0,isIgnoredPropName=e=>e in v||y.has(e),v=Error(`check`),y=new Set([`prototype`,`errors`,`cause`]),{propertyIsEnumerable:b}=Object.prototype,setErrorProps=(e,t,n)=>{let{soft:r}=normalizeOptions(e,t,n);for(let n of Reflect.ownKeys(t))setErrorProp({error:e,props:t,propName:n,soft:r});return e},setErrorProp=({error:e,props:t,propName:n,soft:r})=>{shouldSkipProp({error:e,props:t,propName:n,soft:r})||assignProp(e,n,t[n])},setErrorProperty=(e,t,n)=>{Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!1,configurable:!0})},mergeAggregateCauses=(e,t)=>{e.errors!==void 0&&setErrorProperty(e,`errors`,e.errors.map(e=>t(e).error).filter(Boolean))},mergeAggregateErrors=({target:e,source:t,parent:n,child:r})=>{if(!hasErrors(e)){mergeSourceErrors(e,t);return}hasErrors(t)&&setErrorProperty(e,`errors`,[...r.errors,...n.errors])},mergeSourceErrors=(e,t)=>{t.errors!==void 0&&setErrorProperty(e,`errors`,t.errors)},hasErrors=e=>e.errors!==void 0&&e.errors.length!==0,normalizeArgs=(e,t,n=e.message)=>{if(typeof t!=`string`)throw TypeError(`newMessage must be a string: ${t}`);if(typeof n!=`string`)throw TypeError(`currentMessage must be a string: ${n}`);return n},x=e(({name:e,stack:t},n,r)=>r!==``&&t.includes(r)?replaceMessage({name:e,stack:t,newMessage:n,currentMessage:r}):insertMessage(e,t,n),`getStack`),replaceMessage=({name:e,stack:t,newMessage:n,currentMessage:r})=>{let[i,a]=getReplacers(e,n,r).find(([e])=>t.includes(e));return t.replace(i,a)},getReplacers=(e,t,n)=>[[`${e}: ${n}`,`${e}: ${t}`],[`: ${n}`,`: ${t}`],[`\n${n}`,`\n${t}`],[` ${n}`,` ${t}`],[n,t]],insertMessage=(e,t,n)=>{let r=`${e}: `,i=n.trimEnd();return t===e||t.startsWith(`${e}\n`)?t.replace(e,`${r}${i}`):t.startsWith(r)?t.replace(r,`${r}${i}\n`):`${r}${i}\n${t}`},setErrorMessage=(e,t,n)=>{let r=normalizeException(e),i=normalizeArgs(r,t,n);return setNonEnumProp(r,`message`,t),updateStack(r,t,i),r},updateStack=(e,t,n)=>{t===n||!stackIncludesMessage()||setNonEnumProp(e,`stack`,x(e,t,n))},stackIncludesMessage=()=>{let{stack:e}=Error(S);return typeof e==`string`&&e.includes(S)},S=`set-error-message test message`,setNonEnumProp=(e,t,n)=>{Object.defineProperty(e,t,{value:n,enumerable:!1,writable:!0,configurable:!0})},wrapErrorMessage=(e,t,n)=>{if(typeof t!=`string`)throw TypeError(`Second argument must be a message string: ${t}`);let r=normalizeException(e);return setErrorMessage(r,getMessage(t,r.message),n)},getMessage=(e,t)=>{let n=e.trim(),r=t.trim();return n===``?r:r===``?n:concatMessages(n,r,e)},concatMessages=(e,t,n)=>e.endsWith(C)?n.endsWith(w)?`${e}\n${t}`:`${e} ${t}`:`${t}\n${e}`,C=`:`,w=`
|
|
2
|
+
`,mergeMessage=({parent:e,child:t,target:n,stackError:r})=>{let i=e.message,a=r.message;return n.message=t.message,wrapErrorMessage(n,i,a)},hasStack=(e,t)=>getStack(e)===t,getStack=e=>typeof e==`object`&&e?e.stack:void 0,mergeStack=({wrap:e,target:t,source:n,childHasStack:r})=>e===r?t:(setErrorProperty(t,`stack`,n.stack),n),getWrap=e=>{let{wrap:t,name:n}=e;return typeof t==`boolean`?(Object.hasOwn(e,`wrap`)&&delete e.wrap,t):n===`Error`},mergeErrorCause=e=>mergeError(e,[]).error,mergeError=(e,t)=>{if(t.includes(e))return{};let recurse=n=>mergeError(n,[...t,e]),n=getStack(e),r=normalizeException(e,{shallow:!0}),i=hasStack(r,n);mergeAggregateCauses(r,recurse);let{parent:a,childHasStack:o}=mergeCause(r,recurse);return{error:a,errorHasStack:i||o}},mergeCause=(e,t)=>{let n=getWrap(e);if(e.cause===void 0)return{parent:e,childHasStack:!1};let{error:r,errorHasStack:i}=t(e.cause);return delete e.cause,{parent:mergeChild({parent:e,child:r,childHasStack:i,wrap:n}),childHasStack:i}},mergeChild=({parent:e,child:t,childHasStack:n,wrap:r})=>{if(t===void 0)return e;let[i,a]=r?[t,e]:[e,t],o=mergeStack({wrap:r,target:i,source:a,childHasStack:n}),s=mergeMessage({parent:e,child:t,target:setErrorClass(i,i.constructor,o.name),stackError:o});return mergeAggregateErrors({target:s,source:a,parent:e,child:t}),setErrorProps(s,a,{soft:!r})};export{wrapErrorMessage as n,mergeErrorCause as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"../rolldown-runtime.mjs";function serializeValue(e,t,n,r){if(typeof e?.toJSON==`function`&&(e=e.toJSON()),!(typeof e==`object`&&e))return e;if(t.has(e)){if(!n)return`[Circular]`;let r=t.get(e);return`[Circular ${r===``?`*`:`*${r}`}]`}t.set(e,r);let i=Array.isArray(e)?[]:{};for(let[a,o]of Object.entries(e))i[a]=serializeValue(o,t,n,r===``?a:`${r}.${a}`);return t.delete(e),i}function safeStringify(e,{indentation:t,trace:n}={}){let r=serializeValue(e,new WeakMap,n,``);return JSON.stringify(r,void 0,t)}export{safeStringify as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.defineProperty,__name=(t,n)=>e(t,`name`,{value:n,configurable:!0});export{__name as t};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { t as __name } from "./chunks/rolldown-runtime.mjs";
|
|
2
|
+
import { AnsiColorFormatterOptions, ConsoleFormatter, FormattedValues, LogRecord, TextFormatter, TextFormatterOptions } from "@logtape/logtape";
|
|
3
|
+
|
|
4
|
+
//#region src/formatters.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Extract a single Error from a log record (from properties or rawMessage).
|
|
7
|
+
* @param record - Log record that may contain error in properties or rawMessage
|
|
8
|
+
* @returns Merged/wrapped Error or null if none found
|
|
9
|
+
*/
|
|
10
|
+
declare function errorFromLogRecord(record: LogRecord): Error | null;
|
|
11
|
+
/**
|
|
12
|
+
* Append error from record properties to the formatted message (optionally colored).
|
|
13
|
+
* @param values - Formatted values (record + message)
|
|
14
|
+
* @param color - When true, wrap error text in ANSI red
|
|
15
|
+
* @returns Updated FormattedValues with error appended to message
|
|
16
|
+
*/
|
|
17
|
+
declare function appendErrorToMessage(values: FormattedValues, color?: boolean): FormattedValues;
|
|
18
|
+
/**
|
|
19
|
+
* Formatter that outputs only the log message (no timestamp/level/category).
|
|
20
|
+
* @returns TextFormatter that returns just the message string
|
|
21
|
+
*/
|
|
22
|
+
declare function getMessageOnlyFormatter(): TextFormatter;
|
|
23
|
+
/**
|
|
24
|
+
* Build a text formatter with optional custom format; appends error from record.
|
|
25
|
+
* @param options - Optional format and logtape options
|
|
26
|
+
* @returns TextFormatter
|
|
27
|
+
*/
|
|
28
|
+
declare function getTextFormatter(options?: TextFormatterOptions): TextFormatter;
|
|
29
|
+
/**
|
|
30
|
+
* Build an ANSI-colored text formatter (level/category colors); appends error in red.
|
|
31
|
+
* @param options - Optional format and logtape ANSI options
|
|
32
|
+
* @returns TextFormatter with ANSI colors
|
|
33
|
+
*/
|
|
34
|
+
declare function getAnsiColorFormatter(options?: AnsiColorFormatterOptions): TextFormatter;
|
|
35
|
+
/**
|
|
36
|
+
* The formatter returns an array where:
|
|
37
|
+
* - First element is the formatted message string
|
|
38
|
+
* - Second element is the record properties object
|
|
39
|
+
* @param options - Optional messageFormatter (TextFormatter)
|
|
40
|
+
* @returns ConsoleFormatter for console.log/error
|
|
41
|
+
*/
|
|
42
|
+
declare function getConsoleFormatter(options?: {
|
|
43
|
+
messageFormatter?: TextFormatter;
|
|
44
|
+
}): ConsoleFormatter;
|
|
45
|
+
//#endregion
|
|
46
|
+
export { appendErrorToMessage, errorFromLogRecord, getAnsiColorFormatter, getConsoleFormatter, getMessageOnlyFormatter, getTextFormatter };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import"./chunks/rolldown-runtime.mjs";import{n as e,t}from"./chunks/libs/merge-error-cause.mjs";import{indent as n,loggable as r,parseStack as i}from"./utils.mjs";import{getAnsiColorFormatter as a,getTextFormatter as o}from"@logtape/logtape";function getErrorFromLogRecord(e){let n=Object.entries(e.properties).flatMap(([e,n])=>{if(n instanceof Error){let e=t(n);return e.stack&&=i(e.stack).join(`
|
|
2
|
+
`),[e]}return e===`error`||e===`err`?[Error(r(n))]:[]});return n.length===0?null:n.length===1?n[0]:AggregateError(n)}function errorFromLogRecord(t){let n=getErrorFromLogRecord(t);return n&&typeof t.rawMessage==`string`?e(n,t.rawMessage+`
|
|
3
|
+
`):n}function appendErrorToMessage(e,t=!1){let r=getErrorFromLogRecord(e.record);if(r){let i=r.message;return r.stack&&(i=i+`
|
|
4
|
+
`+n(r.stack.split(`
|
|
5
|
+
`).slice(1))),t&&(i=`${l.red}${i}${c}`),{...e,message:e.message+`
|
|
6
|
+
`+n(i)}}return e}const s={trace:`TRACE`,debug:`DEBUG`,info:`INFO `,warning:`WARN `,error:`ERROR`,fatal:`FATAL`};function getMessageOnlyFormatter(){return getTextFormatter({format:({message:e})=>e})}const level=e=>s[e];function getTextFormatter(e){let t=e?.format??(({timestamp:e,level:t,category:n,message:r})=>`${e} ${t} ${n} ${r}`);return o({timestamp:`time`,level,category:`.`,...e,format:e=>t(appendErrorToMessage(e))})}const c=`\x1B[0m`,l={red:`\x1B[31m`};function getAnsiColorFormatter(e){let t=e?.format??(({timestamp:e,level:t,category:n,message:r})=>`${e} ${t} ${n} ${r}`);return a({timestamp:`time`,level,categoryStyle:`bold`,categoryColor:`cyan`,category:`.`,levelColors:{trace:`black`,debug:`blue`,info:`green`,warning:`yellow`,error:`red`,fatal:`magenta`},...e,format:e=>t(appendErrorToMessage(e,!0))})}function getConsoleFormatter(e){let t=e?.messageFormatter;return t?e=>{let{properties:n}=e;return n&&Object.keys(n).length>0?[t(e),n]:[t(e)]}:e=>{let{message:t,properties:n}=e;return n&&Object.keys(n).length>0?[...t,n]:t}}export{appendErrorToMessage,errorFromLogRecord,getAnsiColorFormatter,getConsoleFormatter,getMessageOnlyFormatter,getTextFormatter};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,108 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { t as __name } from "./chunks/rolldown-runtime.mjs";
|
|
2
|
+
import { errorFromLogRecord, getAnsiColorFormatter, getConsoleFormatter, getMessageOnlyFormatter, getTextFormatter } from "./formatters.mjs";
|
|
3
|
+
import { getConsoleSink, getConsoleStderrSink } from "./sink.mjs";
|
|
4
|
+
import { loggable, wrapError } from "./utils.mjs";
|
|
5
|
+
import * as _$_logtape_logtape0 from "@logtape/logtape";
|
|
6
|
+
import { Config, Filter, LogLevel, LogRecord, Logger, Sink, TextFormatter, withFilter } from "@logtape/logtape";
|
|
3
7
|
|
|
4
|
-
//#region src/formatters.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Extract a single Error from a log record (from properties or rawMessage).
|
|
7
|
-
* @param record - Log record that may contain error in properties or rawMessage
|
|
8
|
-
* @returns Merged/wrapped Error or null if none found
|
|
9
|
-
*/
|
|
10
|
-
declare function errorFromLogRecord(record: LogRecord$1): Error | null;
|
|
11
|
-
/**
|
|
12
|
-
* Formatter that outputs only the log message (no timestamp/level/category).
|
|
13
|
-
* @returns TextFormatter that returns just the message string
|
|
14
|
-
*/
|
|
15
|
-
declare function getMessageOnlyFormatter(): TextFormatter$1;
|
|
16
|
-
/**
|
|
17
|
-
* Build a text formatter with optional custom format; appends error from record.
|
|
18
|
-
* @param options - Optional format and logtape options
|
|
19
|
-
* @returns TextFormatter
|
|
20
|
-
*/
|
|
21
|
-
declare function getTextFormatter(options?: TextFormatterOptions): TextFormatter$1;
|
|
22
|
-
/**
|
|
23
|
-
* Build an ANSI-colored text formatter (level/category colors); appends error in red.
|
|
24
|
-
* @param options - Optional format and logtape ANSI options
|
|
25
|
-
* @returns TextFormatter with ANSI colors
|
|
26
|
-
*/
|
|
27
|
-
declare function getAnsiColorFormatter(options?: AnsiColorFormatterOptions): TextFormatter$1;
|
|
28
|
-
/**
|
|
29
|
-
* The formatter returns an array where:
|
|
30
|
-
* - First element is the formatted message string
|
|
31
|
-
* - Second element is the record properties object
|
|
32
|
-
* @param options - Optional messageFormatter (TextFormatter)
|
|
33
|
-
* @returns ConsoleFormatter for console.log/error
|
|
34
|
-
*/
|
|
35
|
-
declare function getConsoleFormatter(options?: {
|
|
36
|
-
messageFormatter?: TextFormatter$1;
|
|
37
|
-
}): ConsoleFormatter;
|
|
38
|
-
//#endregion
|
|
39
|
-
//#region src/sink.d.ts
|
|
40
|
-
/**
|
|
41
|
-
* Create a sink that writes formatted log records to stdout (default formatter).
|
|
42
|
-
* @param options - Optional console sink options (e.g. custom formatter)
|
|
43
|
-
* @returns Sink that writes to stdout
|
|
44
|
-
*/
|
|
45
|
-
declare function getConsoleSink(options?: ConsoleSinkOptions): Sink$1;
|
|
46
|
-
/**
|
|
47
|
-
* Creates a console sink that writes to stderr.
|
|
48
|
-
* (MCP protocol requires stderr to be used for logging)
|
|
49
|
-
* @param options - Optional console sink options (e.g. custom formatter)
|
|
50
|
-
* @returns Sink that writes to stderr
|
|
51
|
-
*/
|
|
52
|
-
declare function getConsoleStderrSink(options?: ConsoleSinkOptions): Sink$1;
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/utils.d.ts
|
|
55
|
-
/**
|
|
56
|
-
* Serialize unknown to a string (Error → message + stack; else safe-stringify).
|
|
57
|
-
* @param error - Caught value (Error, string, or arbitrary object)
|
|
58
|
-
* @returns Human-readable string for logging
|
|
59
|
-
*/
|
|
60
|
-
declare function loggable(error: unknown): string;
|
|
61
|
-
type NormalizeError<ErrorArg> = ErrorArg extends Error ? ErrorArg : Error;
|
|
62
|
-
/**
|
|
63
|
-
* Appends `message` to `error.message`. If `message` ends with `:` or `:\n`,
|
|
64
|
-
* prepends it instead.
|
|
65
|
-
*
|
|
66
|
-
* Returns `error`. If `error` is not an `Error` instance, it is converted to
|
|
67
|
-
* one.
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```js
|
|
71
|
-
* wrapErrorMessage(new Error('Message.'), 'Additional message.')
|
|
72
|
-
* // Error: Message.
|
|
73
|
-
* // Additional message.
|
|
74
|
-
*
|
|
75
|
-
* wrapErrorMessage(new Error('Message.'), 'Additional message:')
|
|
76
|
-
* // Error: Additional message: Message.
|
|
77
|
-
*
|
|
78
|
-
* wrapErrorMessage(new Error('Message.'), 'Additional message:\n')
|
|
79
|
-
* // Error: Additional message:
|
|
80
|
-
* // Message.
|
|
81
|
-
*
|
|
82
|
-
* wrapErrorMessage(new Error('Message.'), '')
|
|
83
|
-
* // Error: Message.
|
|
84
|
-
*
|
|
85
|
-
* const invalidError = 'Message.'
|
|
86
|
-
* wrapErrorMessage(invalidError, 'Additional message.')
|
|
87
|
-
* // Error: Message.
|
|
88
|
-
* // Additional message.
|
|
89
|
-
*
|
|
90
|
-
* wrapErrorMessage(new Error(' Message with spaces '), ' Additional message ')
|
|
91
|
-
* // Error: Message with spaces
|
|
92
|
-
* // Additional message
|
|
93
|
-
* ```
|
|
94
|
-
*/
|
|
95
|
-
declare function wrapError<ErrorArg>(error: ErrorArg, newMessage: string): NormalizeError<ErrorArg>;
|
|
96
|
-
//#endregion
|
|
97
8
|
//#region src/index.d.ts
|
|
98
|
-
declare const logger: _logtape_logtape0.Logger;
|
|
9
|
+
declare const logger: _$_logtape_logtape0.Logger;
|
|
99
10
|
/**
|
|
100
11
|
* Get a child logger with the given subcategory.
|
|
101
12
|
*
|
|
102
13
|
* @param subcategory The subcategory.
|
|
103
14
|
* @returns The child logger.
|
|
104
15
|
*/
|
|
105
|
-
declare function createLogger(subcategory: string | readonly [string] | readonly [string, ...string[]]): _logtape_logtape0.Logger;
|
|
16
|
+
declare function createLogger(subcategory: string | readonly [string] | readonly [string, ...string[]]): _$_logtape_logtape0.Logger;
|
|
106
17
|
/**
|
|
107
18
|
* Configure the global logger: sinks, loggers, and lowest level per category.
|
|
108
19
|
* @param config - Optional partial config (sinks, loggers). Merged with defaults.
|
package/dist/index.mjs
CHANGED
|
@@ -1,268 +1 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import "./_chunks/libs/is-error-instance.mjs";
|
|
3
|
-
import "./_chunks/libs/is-plain-obj.mjs";
|
|
4
|
-
import { t as safeStringify } from "./_chunks/libs/safe-stringify.mjs";
|
|
5
|
-
import { configureSync, getAnsiColorFormatter as getAnsiColorFormatter$1, getConsoleSink as getConsoleSink$1, getLogger, getTextFormatter as getTextFormatter$1, withFilter } from "@logtape/logtape";
|
|
6
|
-
/**
|
|
7
|
-
* Split stack string into lines and normalize (e.g. strip file://).
|
|
8
|
-
* @param stack - Error stack string
|
|
9
|
-
* @returns Array of normalized lines
|
|
10
|
-
*/
|
|
11
|
-
const parseStack = (stack) => {
|
|
12
|
-
return stack.split("\n").map((l) => {
|
|
13
|
-
return l.trim().replace("file://", "");
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Indent each line of value by the given number of spaces.
|
|
18
|
-
* @param value - String or array of lines to indent
|
|
19
|
-
* @param indentation - Number of spaces (default 2)
|
|
20
|
-
* @returns Indented string
|
|
21
|
-
*/
|
|
22
|
-
function indent(value, indentation = 2) {
|
|
23
|
-
value = Array.isArray(value) ? value : value.split("\n");
|
|
24
|
-
const prefix = " ".repeat(indentation);
|
|
25
|
-
return value.map((l) => `${prefix}${l}`).join("\n");
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Serialize unknown to a string (Error → message + stack; else safe-stringify).
|
|
29
|
-
* @param error - Caught value (Error, string, or arbitrary object)
|
|
30
|
-
* @returns Human-readable string for logging
|
|
31
|
-
*/
|
|
32
|
-
function loggable(error) {
|
|
33
|
-
if (typeof error === "string") return error;
|
|
34
|
-
if (error instanceof Error) {
|
|
35
|
-
const mergedErr = mergeErrorCause(error);
|
|
36
|
-
if (mergedErr.stack) {
|
|
37
|
-
const stack = parseStack(mergedErr.stack);
|
|
38
|
-
return mergedErr.message + "\n" + indent(stack.slice(1));
|
|
39
|
-
}
|
|
40
|
-
return mergedErr.message;
|
|
41
|
-
}
|
|
42
|
-
return safeStringify(error, { indentation: " " });
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Appends `message` to `error.message`. If `message` ends with `:` or `:\n`,
|
|
46
|
-
* prepends it instead.
|
|
47
|
-
*
|
|
48
|
-
* Returns `error`. If `error` is not an `Error` instance, it is converted to
|
|
49
|
-
* one.
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```js
|
|
53
|
-
* wrapErrorMessage(new Error('Message.'), 'Additional message.')
|
|
54
|
-
* // Error: Message.
|
|
55
|
-
* // Additional message.
|
|
56
|
-
*
|
|
57
|
-
* wrapErrorMessage(new Error('Message.'), 'Additional message:')
|
|
58
|
-
* // Error: Additional message: Message.
|
|
59
|
-
*
|
|
60
|
-
* wrapErrorMessage(new Error('Message.'), 'Additional message:\n')
|
|
61
|
-
* // Error: Additional message:
|
|
62
|
-
* // Message.
|
|
63
|
-
*
|
|
64
|
-
* wrapErrorMessage(new Error('Message.'), '')
|
|
65
|
-
* // Error: Message.
|
|
66
|
-
*
|
|
67
|
-
* const invalidError = 'Message.'
|
|
68
|
-
* wrapErrorMessage(invalidError, 'Additional message.')
|
|
69
|
-
* // Error: Message.
|
|
70
|
-
* // Additional message.
|
|
71
|
-
*
|
|
72
|
-
* wrapErrorMessage(new Error(' Message with spaces '), ' Additional message ')
|
|
73
|
-
* // Error: Message with spaces
|
|
74
|
-
* // Additional message
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
function wrapError(error, newMessage) {
|
|
78
|
-
return wrapErrorMessage(error, newMessage);
|
|
79
|
-
}
|
|
80
|
-
function getErrorFromLogRecord(record) {
|
|
81
|
-
const errors = Object.entries(record.properties).flatMap(([k, err]) => {
|
|
82
|
-
if (err instanceof Error) {
|
|
83
|
-
const mergedErr = mergeErrorCause(err);
|
|
84
|
-
if (mergedErr.stack) mergedErr.stack = parseStack(mergedErr.stack).join("\n");
|
|
85
|
-
return [mergedErr];
|
|
86
|
-
}
|
|
87
|
-
if (k === "error" || k === "err") return [new Error(loggable(err))];
|
|
88
|
-
return [];
|
|
89
|
-
});
|
|
90
|
-
if (errors.length === 0) return null;
|
|
91
|
-
return errors.length === 1 ? errors[0] : new AggregateError(errors);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Extract a single Error from a log record (from properties or rawMessage).
|
|
95
|
-
* @param record - Log record that may contain error in properties or rawMessage
|
|
96
|
-
* @returns Merged/wrapped Error or null if none found
|
|
97
|
-
*/
|
|
98
|
-
function errorFromLogRecord(record) {
|
|
99
|
-
const error = getErrorFromLogRecord(record);
|
|
100
|
-
if (error && typeof record.rawMessage === "string") return wrapErrorMessage(error, record.rawMessage + "\n");
|
|
101
|
-
return error;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Append error from record properties to the formatted message (optionally colored).
|
|
105
|
-
* @param values - Formatted values (record + message)
|
|
106
|
-
* @param color - When true, wrap error text in ANSI red
|
|
107
|
-
* @returns Updated FormattedValues with error appended to message
|
|
108
|
-
*/
|
|
109
|
-
function appendErrorToMessage(values, color = false) {
|
|
110
|
-
const error = getErrorFromLogRecord(values.record);
|
|
111
|
-
if (error) {
|
|
112
|
-
let errorMessage = error.message;
|
|
113
|
-
if (error.stack) errorMessage = errorMessage + "\n" + indent(error.stack.split("\n").slice(1));
|
|
114
|
-
if (color) errorMessage = `${ansiColors.red}${errorMessage}${RESET}`;
|
|
115
|
-
return {
|
|
116
|
-
...values,
|
|
117
|
-
message: values.message + "\n" + indent(errorMessage)
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
return values;
|
|
121
|
-
}
|
|
122
|
-
const levelAbbreviations = {
|
|
123
|
-
"trace": "TRACE",
|
|
124
|
-
"debug": "DEBUG",
|
|
125
|
-
"info": "INFO ",
|
|
126
|
-
"warning": "WARN ",
|
|
127
|
-
"error": "ERROR",
|
|
128
|
-
"fatal": "FATAL"
|
|
129
|
-
};
|
|
130
|
-
/**
|
|
131
|
-
* Formatter that outputs only the log message (no timestamp/level/category).
|
|
132
|
-
* @returns TextFormatter that returns just the message string
|
|
133
|
-
*/
|
|
134
|
-
function getMessageOnlyFormatter() {
|
|
135
|
-
return getTextFormatter({ format: ({ message }) => {
|
|
136
|
-
return message;
|
|
137
|
-
} });
|
|
138
|
-
}
|
|
139
|
-
const level = (l) => levelAbbreviations[l];
|
|
140
|
-
/**
|
|
141
|
-
* Build a text formatter with optional custom format; appends error from record.
|
|
142
|
-
* @param options - Optional format and logtape options
|
|
143
|
-
* @returns TextFormatter
|
|
144
|
-
*/
|
|
145
|
-
function getTextFormatter(options) {
|
|
146
|
-
const _format = options?.format ?? (({ timestamp, level, category, message }) => {
|
|
147
|
-
return `${timestamp} ${level} ${category} ${message}`;
|
|
148
|
-
});
|
|
149
|
-
return getTextFormatter$1({
|
|
150
|
-
timestamp: "time",
|
|
151
|
-
level,
|
|
152
|
-
category: ".",
|
|
153
|
-
...options,
|
|
154
|
-
format: (values) => {
|
|
155
|
-
return _format(appendErrorToMessage(values));
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
const RESET = "\x1B[0m";
|
|
160
|
-
const ansiColors = { red: "\x1B[31m" };
|
|
161
|
-
/**
|
|
162
|
-
* Build an ANSI-colored text formatter (level/category colors); appends error in red.
|
|
163
|
-
* @param options - Optional format and logtape ANSI options
|
|
164
|
-
* @returns TextFormatter with ANSI colors
|
|
165
|
-
*/
|
|
166
|
-
function getAnsiColorFormatter(options) {
|
|
167
|
-
const _format = options?.format ?? (({ timestamp, level, category, message }) => {
|
|
168
|
-
return `${timestamp} ${level} ${category} ${message}`;
|
|
169
|
-
});
|
|
170
|
-
return getAnsiColorFormatter$1({
|
|
171
|
-
timestamp: "time",
|
|
172
|
-
level,
|
|
173
|
-
categoryStyle: "bold",
|
|
174
|
-
categoryColor: "cyan",
|
|
175
|
-
category: ".",
|
|
176
|
-
...options,
|
|
177
|
-
format: (values) => {
|
|
178
|
-
return _format(appendErrorToMessage(values, true));
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* The formatter returns an array where:
|
|
184
|
-
* - First element is the formatted message string
|
|
185
|
-
* - Second element is the record properties object
|
|
186
|
-
* @param options - Optional messageFormatter (TextFormatter)
|
|
187
|
-
* @returns ConsoleFormatter for console.log/error
|
|
188
|
-
*/
|
|
189
|
-
function getConsoleFormatter(options) {
|
|
190
|
-
const formatter = options?.messageFormatter;
|
|
191
|
-
if (formatter) return (record) => {
|
|
192
|
-
const { properties } = record;
|
|
193
|
-
if (properties && Object.keys(properties).length > 0) return [formatter(record), properties];
|
|
194
|
-
return [formatter(record)];
|
|
195
|
-
};
|
|
196
|
-
return (record) => {
|
|
197
|
-
const { message, properties } = record;
|
|
198
|
-
if (properties && Object.keys(properties).length > 0) return [...message, properties];
|
|
199
|
-
return message;
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Create a sink that writes formatted log records to stdout (default formatter).
|
|
204
|
-
* @param options - Optional console sink options (e.g. custom formatter)
|
|
205
|
-
* @returns Sink that writes to stdout
|
|
206
|
-
*/
|
|
207
|
-
function getConsoleSink(options) {
|
|
208
|
-
return getConsoleSink$1({
|
|
209
|
-
formatter: getConsoleFormatter(),
|
|
210
|
-
...options
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Creates a console sink that writes to stderr.
|
|
215
|
-
* (MCP protocol requires stderr to be used for logging)
|
|
216
|
-
* @param options - Optional console sink options (e.g. custom formatter)
|
|
217
|
-
* @returns Sink that writes to stderr
|
|
218
|
-
*/
|
|
219
|
-
function getConsoleStderrSink(options) {
|
|
220
|
-
const formatter = options?.formatter ?? getConsoleFormatter();
|
|
221
|
-
return (record) => {
|
|
222
|
-
const args = formatter(record);
|
|
223
|
-
if (typeof args === "string") {
|
|
224
|
-
const msg = args.replace(/\r?\n$/, "");
|
|
225
|
-
console.error(msg);
|
|
226
|
-
} else console.error(...args);
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
const logger = getLogger("likec4");
|
|
230
|
-
/**
|
|
231
|
-
* Get a child logger with the given subcategory.
|
|
232
|
-
*
|
|
233
|
-
* @param subcategory The subcategory.
|
|
234
|
-
* @returns The child logger.
|
|
235
|
-
*/
|
|
236
|
-
function createLogger(subcategory) {
|
|
237
|
-
return logger.getChild(subcategory);
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Configure the global logger: sinks, loggers, and lowest level per category.
|
|
241
|
-
* @param config - Optional partial config (sinks, loggers). Merged with defaults.
|
|
242
|
-
*/
|
|
243
|
-
function configureLogger(config) {
|
|
244
|
-
try {
|
|
245
|
-
const { sinks = {}, loggers: _loggers, ...restConfig } = config ?? {};
|
|
246
|
-
const sinksWithConsole = {
|
|
247
|
-
console: getConsoleSink(),
|
|
248
|
-
...sinks
|
|
249
|
-
};
|
|
250
|
-
configureSync({
|
|
251
|
-
reset: true,
|
|
252
|
-
...restConfig,
|
|
253
|
-
sinks: sinksWithConsole,
|
|
254
|
-
loggers: [{
|
|
255
|
-
category: ["logtape", "meta"],
|
|
256
|
-
sinks: ["console"],
|
|
257
|
-
lowestLevel: "warning"
|
|
258
|
-
}, ...config?.loggers ?? [{
|
|
259
|
-
category: "likec4",
|
|
260
|
-
sinks: ["console"],
|
|
261
|
-
lowestLevel: "debug"
|
|
262
|
-
}]]
|
|
263
|
-
});
|
|
264
|
-
} catch (e) {
|
|
265
|
-
console.error(e);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
export { configureLogger, logger as consola, logger, logger as rootLogger, createLogger, errorFromLogRecord, getAnsiColorFormatter, getConsoleFormatter, getConsoleSink, getConsoleStderrSink, getMessageOnlyFormatter, getTextFormatter, loggable, withFilter, wrapError };
|
|
1
|
+
import"./chunks/rolldown-runtime.mjs";import{loggable as e,wrapError as t}from"./utils.mjs";import{errorFromLogRecord as n,getAnsiColorFormatter as r,getConsoleFormatter as i,getMessageOnlyFormatter as a,getTextFormatter as o}from"./formatters.mjs";import{getConsoleSink as s,getConsoleStderrSink as c}from"./sink.mjs";import{configureSync as l,getLogger as u,withFilter as d}from"@logtape/logtape";const f=u(`likec4`);function createLogger(e){return f.getChild(e)}function configureLogger(e){try{let{sinks:t={},loggers:n,...r}=e??{},i={console:s(),...t};l({reset:!0,...r,sinks:i,loggers:[{category:[`logtape`,`meta`],sinks:[`console`],lowestLevel:`warning`},...e?.loggers??[{category:`likec4`,sinks:[`console`],lowestLevel:`debug`}]]})}catch(e){console.error(e)}}export{configureLogger,f as consola,f as logger,f as rootLogger,createLogger,n as errorFromLogRecord,r as getAnsiColorFormatter,i as getConsoleFormatter,s as getConsoleSink,c as getConsoleStderrSink,a as getMessageOnlyFormatter,o as getTextFormatter,e as loggable,d as withFilter,t as wrapError};
|
package/dist/sink.d.mts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { t as __name } from "./chunks/rolldown-runtime.mjs";
|
|
2
|
+
import { ConsoleSinkOptions, Sink } from "@logtape/logtape";
|
|
3
|
+
|
|
4
|
+
//#region src/sink.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Create a sink that writes formatted log records to stdout (default formatter).
|
|
7
|
+
* @param options - Optional console sink options (e.g. custom formatter)
|
|
8
|
+
* @returns Sink that writes to stdout
|
|
9
|
+
*/
|
|
10
|
+
declare function getConsoleSink(options?: ConsoleSinkOptions): Sink;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a console sink that writes to stderr.
|
|
13
|
+
* (MCP protocol requires stderr to be used for logging)
|
|
14
|
+
* @param options - Optional console sink options (e.g. custom formatter)
|
|
15
|
+
* @returns Sink that writes to stderr
|
|
16
|
+
*/
|
|
17
|
+
declare function getConsoleStderrSink(options?: ConsoleSinkOptions): Sink;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { getConsoleSink, getConsoleStderrSink };
|
package/dist/sink.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./chunks/rolldown-runtime.mjs";import{getConsoleFormatter as e}from"./formatters.mjs";import{getConsoleSink as t}from"@logtape/logtape";function getConsoleSink(n){return t({formatter:e(),...n})}function getConsoleStderrSink(t){let n=t?.formatter??e();return e=>{let t=n(e);if(typeof t==`string`){let e=t.replace(/\r?\n$/,``);console.error(e)}else console.error(...t)}}export{getConsoleSink,getConsoleStderrSink};
|
package/dist/utils.d.mts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { t as __name } from "./chunks/rolldown-runtime.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/utils.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Split stack string into lines and normalize (e.g. strip file://).
|
|
6
|
+
* @param stack - Error stack string
|
|
7
|
+
* @returns Array of normalized lines
|
|
8
|
+
*/
|
|
9
|
+
declare const parseStack: (stack: string) => string[];
|
|
10
|
+
/**
|
|
11
|
+
* Indent each line of value by the given number of spaces.
|
|
12
|
+
* @param value - String or array of lines to indent
|
|
13
|
+
* @param indentation - Number of spaces (default 2)
|
|
14
|
+
* @returns Indented string
|
|
15
|
+
*/
|
|
16
|
+
declare function indent(value: string | string[], indentation?: number): string;
|
|
17
|
+
/**
|
|
18
|
+
* Serialize unknown to a string (Error → message + stack; else safe-stringify).
|
|
19
|
+
* @param error - Caught value (Error, string, or arbitrary object)
|
|
20
|
+
* @returns Human-readable string for logging
|
|
21
|
+
*/
|
|
22
|
+
declare function loggable(error: unknown): string;
|
|
23
|
+
type NormalizeError<ErrorArg> = ErrorArg extends Error ? ErrorArg : Error;
|
|
24
|
+
/**
|
|
25
|
+
* Appends `message` to `error.message`. If `message` ends with `:` or `:\n`,
|
|
26
|
+
* prepends it instead.
|
|
27
|
+
*
|
|
28
|
+
* Returns `error`. If `error` is not an `Error` instance, it is converted to
|
|
29
|
+
* one.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```js
|
|
33
|
+
* wrapErrorMessage(new Error('Message.'), 'Additional message.')
|
|
34
|
+
* // Error: Message.
|
|
35
|
+
* // Additional message.
|
|
36
|
+
*
|
|
37
|
+
* wrapErrorMessage(new Error('Message.'), 'Additional message:')
|
|
38
|
+
* // Error: Additional message: Message.
|
|
39
|
+
*
|
|
40
|
+
* wrapErrorMessage(new Error('Message.'), 'Additional message:\n')
|
|
41
|
+
* // Error: Additional message:
|
|
42
|
+
* // Message.
|
|
43
|
+
*
|
|
44
|
+
* wrapErrorMessage(new Error('Message.'), '')
|
|
45
|
+
* // Error: Message.
|
|
46
|
+
*
|
|
47
|
+
* const invalidError = 'Message.'
|
|
48
|
+
* wrapErrorMessage(invalidError, 'Additional message.')
|
|
49
|
+
* // Error: Message.
|
|
50
|
+
* // Additional message.
|
|
51
|
+
*
|
|
52
|
+
* wrapErrorMessage(new Error(' Message with spaces '), ' Additional message ')
|
|
53
|
+
* // Error: Message with spaces
|
|
54
|
+
* // Additional message
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare function wrapError<ErrorArg>(error: ErrorArg, newMessage: string): NormalizeError<ErrorArg>;
|
|
58
|
+
//#endregion
|
|
59
|
+
export { indent, loggable, parseStack, wrapError };
|
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import"./chunks/rolldown-runtime.mjs";import{n as e,t}from"./chunks/libs/merge-error-cause.mjs";import{t as n}from"./chunks/libs/safe-stringify.mjs";const parseStack=e=>e.split(`
|
|
2
|
+
`).map(e=>e.trim().replace(`file://`,``));function indent(e,t=2){e=Array.isArray(e)?e:e.split(`
|
|
3
|
+
`);let n=` `.repeat(t);return e.map(e=>`${n}${e}`).join(`
|
|
4
|
+
`)}function loggable(e){if(typeof e==`string`)return e;if(e instanceof Error){let n=t(e);if(n.stack){let e=parseStack(n.stack);return n.message+`
|
|
5
|
+
`+indent(e.slice(1))}return n.message}return n(e,{indentation:` `})}function wrapError(t,n){return e(t,n)}export{indent,loggable,parseStack,wrapError};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@likec4/log",
|
|
3
3
|
"description": "Shared interface for logging",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.57.0",
|
|
6
6
|
"bugs": "https://github.com/likec4/likec4/issues",
|
|
7
7
|
"homepage": "https://likec4.dev",
|
|
8
8
|
"author": "Denis Davydkov <denis@davydkov.com>",
|
|
@@ -35,18 +35,18 @@
|
|
|
35
35
|
"@logtape/logtape": "^2.0.5"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@types/node": "~22.19.
|
|
38
|
+
"@types/node": "~22.19.19",
|
|
39
39
|
"merge-error-cause": "^5.0.2",
|
|
40
40
|
"safe-stringify": "^1.3.0",
|
|
41
41
|
"typescript": "5.9.3",
|
|
42
|
-
"
|
|
42
|
+
"tsdown": "^0.22.0",
|
|
43
43
|
"wrap-error-message": "^3.0.1",
|
|
44
|
-
"@likec4/tsconfig": "1.
|
|
45
|
-
"@likec4/devops": "1.
|
|
44
|
+
"@likec4/tsconfig": "1.57.0",
|
|
45
|
+
"@likec4/devops": "1.57.0"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"typecheck": "tsc -b --verbose",
|
|
49
|
-
"build": "
|
|
49
|
+
"build": "tsdown",
|
|
50
50
|
"pack": "pnpm pack",
|
|
51
51
|
"lint:package": "pnpx publint ./package.tgz",
|
|
52
52
|
"clean": "likec4ops clean"
|
package/src/formatters.ts
CHANGED
|
@@ -143,6 +143,14 @@ export function getAnsiColorFormatter(options?: AnsiColorFormatterOptions): Text
|
|
|
143
143
|
categoryStyle: 'bold',
|
|
144
144
|
categoryColor: 'cyan',
|
|
145
145
|
category: '.',
|
|
146
|
+
levelColors: {
|
|
147
|
+
trace: 'black',
|
|
148
|
+
debug: 'blue',
|
|
149
|
+
info: 'green',
|
|
150
|
+
warning: 'yellow',
|
|
151
|
+
error: 'red',
|
|
152
|
+
fatal: 'magenta',
|
|
153
|
+
},
|
|
146
154
|
...options,
|
|
147
155
|
format: (values) => {
|
|
148
156
|
return _format(appendErrorToMessage(values, true))
|