@mks2508/better-logger 1.1.0 → 1.2.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.
Files changed (46) hide show
  1. package/.claude/settings.local.json +3 -2
  2. package/CHANGELOG.md +63 -0
  3. package/bun.lock +10 -0
  4. package/dist/Logger.d.ts.map +1 -1
  5. package/dist/chunks/{Logger-Th9SfADL.js → Logger-BynuRJQf.js} +12 -6
  6. package/dist/chunks/{Logger-Th9SfADL.js.map → Logger-BynuRJQf.js.map} +1 -1
  7. package/dist/chunks/{Logger-C9zTFYBh.js → Logger-DMjlVQWi.js} +2 -2
  8. package/dist/chunks/{Logger-C9zTFYBh.js.map → Logger-DMjlVQWi.js.map} +1 -1
  9. package/dist/chunks/{ScopedLogger-uAAeJkfA.js → ScopedLogger-Bl56WovH.js} +2 -2
  10. package/dist/chunks/{ScopedLogger-uAAeJkfA.js.map → ScopedLogger-Bl56WovH.js.map} +1 -1
  11. package/dist/chunks/{ScopedLogger-HgV_J-ug.js → ScopedLogger-D2HzayKH.js} +2 -2
  12. package/dist/chunks/{ScopedLogger-HgV_J-ug.js.map → ScopedLogger-D2HzayKH.js.map} +1 -1
  13. package/dist/chunks/environment--eaTrhRu.js +4 -0
  14. package/dist/chunks/environment--eaTrhRu.js.map +1 -0
  15. package/dist/chunks/{environment-wXLQvk5g.js → environment-BanAyF-K.js} +539 -3
  16. package/dist/chunks/environment-BanAyF-K.js.map +1 -0
  17. package/dist/chunks/{formatting-CiFnwe1I.js → formatting-BSNvAxLK.js} +2 -2
  18. package/dist/chunks/{formatting-CiFnwe1I.js.map → formatting-BSNvAxLK.js.map} +1 -1
  19. package/dist/chunks/{formatting-DIhpRCCk.js → formatting-CgQSWgXR.js} +2 -2
  20. package/dist/chunks/{formatting-DIhpRCCk.js.map → formatting-CgQSWgXR.js.map} +1 -1
  21. package/dist/core.cjs +1 -1
  22. package/dist/core.js +2 -2
  23. package/dist/exports.cjs +1 -1
  24. package/dist/exports.js +2 -2
  25. package/dist/index.cjs +1 -1
  26. package/dist/index.js +6 -6
  27. package/dist/styling.cjs +1 -1
  28. package/dist/styling.js +3 -3
  29. package/dist/terminal/terminal-renderer.d.ts +63 -0
  30. package/dist/terminal/terminal-renderer.d.ts.map +1 -0
  31. package/dist/utils/adapter.d.ts +48 -0
  32. package/dist/utils/adapter.d.ts.map +1 -0
  33. package/dist/utils/environment-detector.d.ts +35 -0
  34. package/dist/utils/environment-detector.d.ts.map +1 -0
  35. package/dist/utils/environment.d.ts +1 -1
  36. package/dist/utils/output.d.ts +7 -2
  37. package/dist/utils/output.d.ts.map +1 -1
  38. package/package.json +10 -2
  39. package/src/Logger.ts +21 -13
  40. package/src/terminal/terminal-renderer.ts +339 -0
  41. package/src/utils/adapter.ts +291 -0
  42. package/src/utils/environment-detector.ts +148 -0
  43. package/src/utils/output.ts +43 -1
  44. package/dist/chunks/environment-5I5unY89.js +0 -4
  45. package/dist/chunks/environment-5I5unY89.js.map +0 -1
  46. package/dist/chunks/environment-wXLQvk5g.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./chunks/Logger-C9zTFYBh.js"),t=require("./chunks/environment-5I5unY89.js"),r=require("./chunks/formatting-CiFnwe1I.js"),o=require("./chunks/RemoteLogHandler-ymkQ97xl.js");let s=null;function getLogger(){return s||(s=new e.Logger),s}const i=getLogger(),a={success:t.StylePresets.success().build(),error:t.StylePresets.error().build(),warning:t.StylePresets.warning().build(),info:t.StylePresets.info().build(),accent:t.StylePresets.accent().build()};exports.BANNER_VARIANTS=e.BANNER_VARIANTS,exports.Logger=e.Logger,exports.THEME_BANNERS=e.THEME_BANNERS,exports.THEME_PRESETS=e.THEME_PRESETS,exports.BUILD_PRESETS=t.BUILD_PRESETS,exports.DEFAULT_CONFIG=t.DEFAULT_CONFIG,exports.ENVIRONMENT_DETECTION=t.ENVIRONMENT_DETECTION,exports.StyleBuilder=t.StyleBuilder,exports.StylePresets=t.StylePresets,exports.detectEnvironmentPreset=t.detectEnvironmentPreset,exports.formatTimestamp=t.formatTimestamp,exports.getOptimalConfig=t.getOptimalConfig,exports.parseStackTrace=t.parseStackTrace,exports.BUILD_FORMATTERS=r.BUILD_FORMATTERS,exports.ansiBackground=r.ansiBackground,exports.ansiBold=r.ansiBold,exports.ansiColor=r.ansiColor,exports.ansiDim=r.ansiDim,exports.ansiStyle=r.ansiStyle,exports.ansiUnderline=r.ansiUnderline,exports.createANSIOutput=r.createANSIOutput,exports.createBuildOutput=r.createBuildOutput,exports.createCIOutput=r.createCIOutput,exports.createOutput=r.createOutput,exports.detectOptimalFormat=r.detectOptimalFormat,exports.formatLogLevelANSI=r.formatLogLevelANSI,exports.formatSuccessANSI=r.formatSuccessANSI,exports.sanitizeEmojis=r.sanitizeEmojis,exports.RemoteLogHandler=o.RemoteLogHandler,exports.AnalyticsLogHandler=class{handle(e,t,r,o){"error"!==e&&"critical"!==e||o.timestamp}},exports.FileLogHandler=class{filename;maxSize;fs;constructor(e="app.log",r){if(this.filename=e,this.maxSize=r,t.isNode)try{this.fs=require("fs")}catch(o){console.warn("FileLogHandler: Unable to load fs module:",o)}}handle(e,o,s,i){const a={timestamp:i.timestamp,level:e.toUpperCase(),prefix:i.prefix,message:o,args:s.slice(1).map(e=>r.safeSerialize(e)),location:i.stackInfo},l=this.formatLogLine(a);t.isNode&&this.fs?this.writeToFileNode(l):t.isBrowser?this.writeToFileLocal(l):console.log(`[FILE-LOG] ${l}`)}formatLogLine(e){let t=[e.timestamp,`[${e.level}]`,e.prefix?`[${e.prefix}]`:"",e.message].filter(Boolean).join(" ");return e.args&&e.args.length>0&&(t+=" "+e.args.map(e=>"object"==typeof e?JSON.stringify(e):String(e)).join(" ")),e.location&&(t+=` (${e.location.file}:${e.location.line}:${e.location.column})`),t}writeToFileNode(e){if(this.fs)try{if(this.maxSize)try{if(this.fs.statSync(this.filename).size>this.maxSize){const e=`${this.filename}.bak`;this.fs.renameSync(this.filename,e)}}catch(t){}this.fs.appendFileSync(this.filename,e+"\n","utf8")}catch(t){console.error("FileLogHandler: Failed to write to file:",t)}}writeToFileLocal(e){try{const t=`logger_${this.filename}`,r=localStorage.getItem(t)||"";let o=r;if(r.length>0&&(o+="\n"),o+=e,this.maxSize||o.split("\n").length>1e3){const e=o.split("\n"),t=this.maxSize?Math.floor(this.maxSize/100):1e3;e.length>t&&(o=e.slice(-t).join("\n"))}localStorage.setItem(t,o)}catch(t){console.error("FileLogHandler: Failed to write to localStorage:",t)}}getLogs(){if(t.isNode&&this.fs)try{return this.fs.readFileSync(this.filename,"utf8")}catch(e){return null}else if(t.isBrowser){const e=`logger_${this.filename}`;return localStorage.getItem(e)}return null}clearLogs(){if(t.isNode&&this.fs)try{this.fs.writeFileSync(this.filename,"","utf8")}catch(e){console.error("FileLogHandler: Failed to clear file:",e)}else if(t.isBrowser){const e=`logger_${this.filename}`;localStorage.removeItem(e)}}},exports.addHandler=e=>getLogger().addHandler(e),exports.cli=e=>getLogger().cli(e),exports.createStyle=()=>new t.StyleBuilder,exports.critical=(...e)=>getLogger().critical(...e),exports.debug=(...e)=>getLogger().debug(...e),exports.default=i,exports.error=(...e)=>getLogger().error(...e),exports.group=(e,t)=>getLogger().group(e,t),exports.groupEnd=()=>getLogger().groupEnd(),exports.info=(...e)=>getLogger().info(...e),exports.logAnimated=(e,t)=>getLogger().logAnimated(e,t),exports.logWithSVG=(e,t,r)=>getLogger().logWithSVG(e,t,r),exports.scope=e=>getLogger().scope(e),exports.setBannerType=e=>getLogger().setBannerType(e),exports.setGlobalPrefix=e=>getLogger().setGlobalPrefix(e),exports.setTheme=e=>getLogger().setTheme(e),exports.setVerbosity=e=>getLogger().setVerbosity(e),exports.showBanner=e=>getLogger().showBanner(e),exports.stylePresets=a,exports.success=(...e)=>getLogger().success(...e),exports.table=(e,t)=>getLogger().table(e,t),exports.time=e=>getLogger().time(e),exports.timeEnd=e=>getLogger().timeEnd(e),exports.trace=(...e)=>getLogger().trace(...e),exports.warn=(...e)=>getLogger().warn(...e);
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./chunks/Logger-DMjlVQWi.js"),t=require("./chunks/environment--eaTrhRu.js"),r=require("./chunks/formatting-BSNvAxLK.js"),o=require("./chunks/RemoteLogHandler-ymkQ97xl.js");let s=null;function getLogger(){return s||(s=new e.Logger),s}const i=getLogger(),a={success:t.StylePresets.success().build(),error:t.StylePresets.error().build(),warning:t.StylePresets.warning().build(),info:t.StylePresets.info().build(),accent:t.StylePresets.accent().build()};exports.BANNER_VARIANTS=e.BANNER_VARIANTS,exports.Logger=e.Logger,exports.THEME_BANNERS=e.THEME_BANNERS,exports.THEME_PRESETS=e.THEME_PRESETS,exports.BUILD_PRESETS=t.BUILD_PRESETS,exports.DEFAULT_CONFIG=t.DEFAULT_CONFIG,exports.ENVIRONMENT_DETECTION=t.ENVIRONMENT_DETECTION,exports.StyleBuilder=t.StyleBuilder,exports.StylePresets=t.StylePresets,exports.detectEnvironmentPreset=t.detectEnvironmentPreset,exports.formatTimestamp=t.formatTimestamp,exports.getOptimalConfig=t.getOptimalConfig,exports.parseStackTrace=t.parseStackTrace,exports.BUILD_FORMATTERS=r.BUILD_FORMATTERS,exports.ansiBackground=r.ansiBackground,exports.ansiBold=r.ansiBold,exports.ansiColor=r.ansiColor,exports.ansiDim=r.ansiDim,exports.ansiStyle=r.ansiStyle,exports.ansiUnderline=r.ansiUnderline,exports.createANSIOutput=r.createANSIOutput,exports.createBuildOutput=r.createBuildOutput,exports.createCIOutput=r.createCIOutput,exports.createOutput=r.createOutput,exports.detectOptimalFormat=r.detectOptimalFormat,exports.formatLogLevelANSI=r.formatLogLevelANSI,exports.formatSuccessANSI=r.formatSuccessANSI,exports.sanitizeEmojis=r.sanitizeEmojis,exports.RemoteLogHandler=o.RemoteLogHandler,exports.AnalyticsLogHandler=class{handle(e,t,r,o){"error"!==e&&"critical"!==e||o.timestamp}},exports.FileLogHandler=class{filename;maxSize;fs;constructor(e="app.log",r){if(this.filename=e,this.maxSize=r,t.isNode)try{this.fs=require("fs")}catch(o){console.warn("FileLogHandler: Unable to load fs module:",o)}}handle(e,o,s,i){const a={timestamp:i.timestamp,level:e.toUpperCase(),prefix:i.prefix,message:o,args:s.slice(1).map(e=>r.safeSerialize(e)),location:i.stackInfo},l=this.formatLogLine(a);t.isNode&&this.fs?this.writeToFileNode(l):t.isBrowser?this.writeToFileLocal(l):console.log(`[FILE-LOG] ${l}`)}formatLogLine(e){let t=[e.timestamp,`[${e.level}]`,e.prefix?`[${e.prefix}]`:"",e.message].filter(Boolean).join(" ");return e.args&&e.args.length>0&&(t+=" "+e.args.map(e=>"object"==typeof e?JSON.stringify(e):String(e)).join(" ")),e.location&&(t+=` (${e.location.file}:${e.location.line}:${e.location.column})`),t}writeToFileNode(e){if(this.fs)try{if(this.maxSize)try{if(this.fs.statSync(this.filename).size>this.maxSize){const e=`${this.filename}.bak`;this.fs.renameSync(this.filename,e)}}catch(t){}this.fs.appendFileSync(this.filename,e+"\n","utf8")}catch(t){console.error("FileLogHandler: Failed to write to file:",t)}}writeToFileLocal(e){try{const t=`logger_${this.filename}`,r=localStorage.getItem(t)||"";let o=r;if(r.length>0&&(o+="\n"),o+=e,this.maxSize||o.split("\n").length>1e3){const e=o.split("\n"),t=this.maxSize?Math.floor(this.maxSize/100):1e3;e.length>t&&(o=e.slice(-t).join("\n"))}localStorage.setItem(t,o)}catch(t){console.error("FileLogHandler: Failed to write to localStorage:",t)}}getLogs(){if(t.isNode&&this.fs)try{return this.fs.readFileSync(this.filename,"utf8")}catch(e){return null}else if(t.isBrowser){const e=`logger_${this.filename}`;return localStorage.getItem(e)}return null}clearLogs(){if(t.isNode&&this.fs)try{this.fs.writeFileSync(this.filename,"","utf8")}catch(e){console.error("FileLogHandler: Failed to clear file:",e)}else if(t.isBrowser){const e=`logger_${this.filename}`;localStorage.removeItem(e)}}},exports.addHandler=e=>getLogger().addHandler(e),exports.cli=e=>getLogger().cli(e),exports.createStyle=()=>new t.StyleBuilder,exports.critical=(...e)=>getLogger().critical(...e),exports.debug=(...e)=>getLogger().debug(...e),exports.default=i,exports.error=(...e)=>getLogger().error(...e),exports.group=(e,t)=>getLogger().group(e,t),exports.groupEnd=()=>getLogger().groupEnd(),exports.info=(...e)=>getLogger().info(...e),exports.logAnimated=(e,t)=>getLogger().logAnimated(e,t),exports.logWithSVG=(e,t,r)=>getLogger().logWithSVG(e,t,r),exports.scope=e=>getLogger().scope(e),exports.setBannerType=e=>getLogger().setBannerType(e),exports.setGlobalPrefix=e=>getLogger().setGlobalPrefix(e),exports.setTheme=e=>getLogger().setTheme(e),exports.setVerbosity=e=>getLogger().setVerbosity(e),exports.showBanner=e=>getLogger().showBanner(e),exports.stylePresets=a,exports.success=(...e)=>getLogger().success(...e),exports.table=(e,t)=>getLogger().table(e,t),exports.time=e=>getLogger().time(e),exports.timeEnd=e=>getLogger().timeEnd(e),exports.trace=(...e)=>getLogger().trace(...e),exports.warn=(...e)=>getLogger().warn(...e);
2
2
  //# sourceMappingURL=index.cjs.map
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import { L as Logger } from "./chunks/Logger-Th9SfADL.js";
2
- import { B, a, T } from "./chunks/Logger-Th9SfADL.js";
3
- import { i as isNode, a as isBrowser, S as StylePresets, b as StyleBuilder } from "./chunks/environment-wXLQvk5g.js";
4
- import { B as B2, D, E, d, f, g, p } from "./chunks/environment-wXLQvk5g.js";
5
- import { s as safeSerialize } from "./chunks/formatting-DIhpRCCk.js";
6
- import { B as B3, h, i, g as g2, j, f as f2, k, a as a2, b, e, c, d as d2, l, m, n } from "./chunks/formatting-DIhpRCCk.js";
1
+ import { L as Logger } from "./chunks/Logger-BynuRJQf.js";
2
+ import { B, a, T } from "./chunks/Logger-BynuRJQf.js";
3
+ import { i as isNode, a as isBrowser, S as StylePresets, b as StyleBuilder } from "./chunks/environment-BanAyF-K.js";
4
+ import { B as B2, D, E, d, f, g, p } from "./chunks/environment-BanAyF-K.js";
5
+ import { s as safeSerialize } from "./chunks/formatting-CgQSWgXR.js";
6
+ import { B as B3, h, i, g as g2, j, f as f2, k, a as a2, b, e, c, d as d2, l, m, n } from "./chunks/formatting-CgQSWgXR.js";
7
7
  import { R } from "./chunks/RemoteLogHandler-CjWpWZGl.js";
8
8
  class FileLogHandler {
9
9
  filename;
package/dist/styling.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./chunks/Logger-C9zTFYBh.js"),t=require("./chunks/environment-5I5unY89.js");class StyledLogger extends e.Logger{logWithSVG(e,t,s={}){super.logWithSVG(e,t,s)}logAnimated(e,t=3){super.logAnimated(e,t)}showBanner(e){super.showBanner(e)}setBannerType(e){super.setBannerType(e)}setTheme(e){super.setTheme(e)}}const s=new StyledLogger,r={success:t.StylePresets.success().build(),error:t.StylePresets.error().build(),warning:t.StylePresets.warning().build(),info:t.StylePresets.info().build(),accent:t.StylePresets.accent().build()},o=Object.keys(e.THEME_PRESETS),n=Object.keys(e.BANNER_VARIANTS);exports.BANNER_VARIANTS=e.BANNER_VARIANTS,exports.THEME_BANNERS=e.THEME_BANNERS,exports.THEME_PRESETS=e.THEME_PRESETS,exports.StyleBuilder=t.StyleBuilder,exports.StylePresets=t.StylePresets,exports.StyledLogger=StyledLogger,exports.bannerTypes=n,exports.createStyle=()=>new t.StyleBuilder,exports.critical=(...e)=>s.critical(...e),exports.debug=(...e)=>s.debug(...e),exports.default=s,exports.error=(...e)=>s.error(...e),exports.group=(e,t)=>s.group(e,t),exports.groupEnd=()=>s.groupEnd(),exports.info=(...e)=>s.info(...e),exports.logAnimated=(e,t)=>s.logAnimated(e,t),exports.logWithSVG=(e,t,r)=>s.logWithSVG(e,t,r),exports.scope=e=>s.scope(e),exports.setBannerType=e=>s.setBannerType(e),exports.setGlobalPrefix=e=>s.setGlobalPrefix(e),exports.setTheme=e=>s.setTheme(e),exports.setVerbosity=e=>s.setVerbosity(e),exports.showBanner=e=>s.showBanner(e),exports.showInitBanner=t=>{e.displayInitBanner(t)},exports.stylePresets=r,exports.success=(...e)=>s.success(...e),exports.table=(e,t)=>s.table(e,t),exports.themes=o,exports.time=e=>s.time(e),exports.timeEnd=e=>s.timeEnd(e),exports.trace=(...e)=>s.trace(...e),exports.warn=(...e)=>s.warn(...e);
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./chunks/Logger-DMjlVQWi.js"),t=require("./chunks/environment--eaTrhRu.js");class StyledLogger extends e.Logger{logWithSVG(e,t,s={}){super.logWithSVG(e,t,s)}logAnimated(e,t=3){super.logAnimated(e,t)}showBanner(e){super.showBanner(e)}setBannerType(e){super.setBannerType(e)}setTheme(e){super.setTheme(e)}}const s=new StyledLogger,r={success:t.StylePresets.success().build(),error:t.StylePresets.error().build(),warning:t.StylePresets.warning().build(),info:t.StylePresets.info().build(),accent:t.StylePresets.accent().build()},o=Object.keys(e.THEME_PRESETS),n=Object.keys(e.BANNER_VARIANTS);exports.BANNER_VARIANTS=e.BANNER_VARIANTS,exports.THEME_BANNERS=e.THEME_BANNERS,exports.THEME_PRESETS=e.THEME_PRESETS,exports.StyleBuilder=t.StyleBuilder,exports.StylePresets=t.StylePresets,exports.StyledLogger=StyledLogger,exports.bannerTypes=n,exports.createStyle=()=>new t.StyleBuilder,exports.critical=(...e)=>s.critical(...e),exports.debug=(...e)=>s.debug(...e),exports.default=s,exports.error=(...e)=>s.error(...e),exports.group=(e,t)=>s.group(e,t),exports.groupEnd=()=>s.groupEnd(),exports.info=(...e)=>s.info(...e),exports.logAnimated=(e,t)=>s.logAnimated(e,t),exports.logWithSVG=(e,t,r)=>s.logWithSVG(e,t,r),exports.scope=e=>s.scope(e),exports.setBannerType=e=>s.setBannerType(e),exports.setGlobalPrefix=e=>s.setGlobalPrefix(e),exports.setTheme=e=>s.setTheme(e),exports.setVerbosity=e=>s.setVerbosity(e),exports.showBanner=e=>s.showBanner(e),exports.showInitBanner=t=>{e.displayInitBanner(t)},exports.stylePresets=r,exports.success=(...e)=>s.success(...e),exports.table=(e,t)=>s.table(e,t),exports.themes=o,exports.time=e=>s.time(e),exports.timeEnd=e=>s.timeEnd(e),exports.trace=(...e)=>s.trace(...e),exports.warn=(...e)=>s.warn(...e);
2
2
  //# sourceMappingURL=styling.cjs.map
package/dist/styling.js CHANGED
@@ -1,6 +1,6 @@
1
- import { L as Logger, T as THEME_PRESETS, B as BANNER_VARIANTS, d as displayInitBanner } from "./chunks/Logger-Th9SfADL.js";
2
- import { a } from "./chunks/Logger-Th9SfADL.js";
3
- import { S as StylePresets, b as StyleBuilder } from "./chunks/environment-wXLQvk5g.js";
1
+ import { L as Logger, T as THEME_PRESETS, B as BANNER_VARIANTS, d as displayInitBanner } from "./chunks/Logger-BynuRJQf.js";
2
+ import { a } from "./chunks/Logger-BynuRJQf.js";
3
+ import { S as StylePresets, b as StyleBuilder } from "./chunks/environment-BanAyF-K.js";
4
4
  class StyledLogger extends Logger {
5
5
  /**
6
6
  * Log with SVG background image
@@ -0,0 +1,63 @@
1
+ import { LogLevel, LogStyles } from '../types/index.js';
2
+ export type ANSIStyle = {
3
+ text: string;
4
+ timestamp?: string;
5
+ level?: string;
6
+ prefix?: string;
7
+ message?: string;
8
+ location?: string;
9
+ reset: string;
10
+ };
11
+ export declare class TerminalRenderer {
12
+ private colorCapability;
13
+ constructor(colorCapability?: 'full' | 'basic' | 'none');
14
+ /**
15
+ * Get ANSI color codes for basic colors
16
+ */
17
+ private getColorCode;
18
+ /**
19
+ * Get ANSI style codes
20
+ */
21
+ private getStyleCode;
22
+ /**
23
+ * Convert log styles to ANSI formatting
24
+ */
25
+ renderTerminal(level: LogLevel, message: string, timestamp?: string, prefix?: string, location?: string, styles?: LogStyles): ANSIStyle;
26
+ /**
27
+ * Style timestamp based on preset or defaults
28
+ */
29
+ private styleTimestamp;
30
+ /**
31
+ * Style level with appropriate colors and formatting
32
+ */
33
+ private styleLevel;
34
+ /**
35
+ * Style prefix based on preset
36
+ */
37
+ private stylePrefix;
38
+ /**
39
+ * Style message based on preset
40
+ */
41
+ private styleMessage;
42
+ /**
43
+ * Style location (file:line) information
44
+ */
45
+ private styleLocation;
46
+ /**
47
+ * Get text representation of log level
48
+ */
49
+ getLevelText(level: LogLevel): string;
50
+ /**
51
+ * Create cyberpunk-style ANSI rendering
52
+ */
53
+ renderCyberpunk(level: LogLevel, message: string, timestamp?: string, prefix?: string, location?: string): ANSIStyle;
54
+ /**
55
+ * Create minimal ANSI rendering
56
+ */
57
+ renderMinimal(level: LogLevel, message: string, timestamp?: string, prefix?: string): ANSIStyle;
58
+ /**
59
+ * Get chalk instance for log level (for compatibility with adapter)
60
+ */
61
+ getChalkForLevel(level: LogLevel): any;
62
+ }
63
+ //# sourceMappingURL=terminal-renderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"terminal-renderer.d.ts","sourceRoot":"","sources":["../../src/terminal/terminal-renderer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,MAAM,SAAS,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,qBAAa,gBAAgB;IACzB,OAAO,CAAC,eAAe,CAA4B;gBAEvC,eAAe,GAAE,MAAM,GAAG,OAAO,GAAG,MAAe;IAI/D;;OAEG;IACH,OAAO,CAAC,YAAY;IAmBpB;;OAEG;IACH,OAAO,CAAC,YAAY;IAapB;;OAEG;IACH,cAAc,CACV,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,SAAS,GACnB,SAAS;IAgCZ;;OAEG;IACH,OAAO,CAAC,cAAc;IAWtB;;OAEG;IACH,OAAO,CAAC,UAAU;IA2BlB;;OAEG;IACH,OAAO,CAAC,WAAW;IAWnB;;OAEG;IACH,OAAO,CAAC,YAAY;IAMpB;;OAEG;IACH,OAAO,CAAC,aAAa;IAgBrB;;OAEG;IACI,YAAY,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM;IAY5C;;OAEG;IACH,eAAe,CACX,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM,GAClB,SAAS;IAqCZ;;OAEG;IACH,aAAa,CACT,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,GAChB,SAAS;IA+BZ;;OAEG;IACI,gBAAgB,CAAC,KAAK,EAAE,QAAQ,GAAG,GAAG;CA4ChD"}
@@ -0,0 +1,48 @@
1
+ import { LogStyles, LogLevel } from '../types/index.js';
2
+ import { ANSIStyle, TerminalRenderer } from '../terminal/terminal-renderer.js';
3
+ export declare class CSS2ANSIAdapter {
4
+ private renderer;
5
+ constructor();
6
+ /**
7
+ * Convert LogStyles to ANSIStyle for terminal rendering
8
+ */
9
+ adaptStyles(level: LogLevel, message: string, timestamp?: string, prefix?: string, location?: string, styles?: LogStyles, presetName?: string): ANSIStyle;
10
+ /**
11
+ * Adapt production preset for terminal
12
+ */
13
+ private adaptProductionStyles;
14
+ /**
15
+ * Adapt debug preset for terminal
16
+ */
17
+ private adaptDebugStyles;
18
+ /**
19
+ * Adapt glassmorphism preset for terminal
20
+ */
21
+ private adaptGlassmorphismStyles;
22
+ /**
23
+ * Convert CSS color values to ANSI-friendly colors
24
+ */
25
+ adaptColor(cssColor: string): string;
26
+ /**
27
+ * Extract primary color from CSS gradient
28
+ */
29
+ private extractColorFromGradient;
30
+ /**
31
+ * Convert CSS color names to ANSI-compatible names
32
+ */
33
+ private cssNameToANSI;
34
+ /**
35
+ * Check if a style should be rendered in terminal
36
+ */
37
+ shouldRenderStyle(styleType: string, styles?: LogStyles): boolean;
38
+ /**
39
+ * Get renderer instance for advanced usage
40
+ */
41
+ getRenderer(): TerminalRenderer;
42
+ }
43
+ export declare const css2ansiAdapter: CSS2ANSIAdapter;
44
+ /**
45
+ * Convenience function for quick style adaptation
46
+ */
47
+ export declare function adaptToTerminal(level: LogLevel, message: string, timestamp?: string, prefix?: string, location?: string, styles?: LogStyles, presetName?: string): ANSIStyle;
48
+ //# sourceMappingURL=adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/utils/adapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAGlD,qBAAa,eAAe;IACxB,OAAO,CAAC,QAAQ,CAAmB;;IAOnC;;OAEG;IACH,WAAW,CACP,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,SAAS,EAClB,UAAU,CAAC,EAAE,MAAM,GACpB,SAAS;IAqBZ;;OAEG;IACH,OAAO,CAAC,qBAAqB;IA0C7B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAqDxB;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAyChC;;OAEG;IACH,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAoBpC;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAMhC;;OAEG;IACH,OAAO,CAAC,aAAa;IAyBrB;;OAEG;IACH,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,GAAG,OAAO;IAOjE;;OAEG;IACH,WAAW,IAAI,gBAAgB;CAGlC;AAGD,eAAO,MAAM,eAAe,iBAAwB,CAAC;AAErD;;GAEG;AACH,wBAAgB,eAAe,CAC3B,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,SAAS,EAClB,UAAU,CAAC,EAAE,MAAM,GACpB,SAAS,CAEX"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Environment Detector - Robust environment detection for logger
3
+ * Detects browser, terminal, server, and other runtime environments
4
+ */
5
+ export type Environment = 'browser' | 'terminal' | 'server' | 'webworker' | 'deno' | 'unknown';
6
+ /**
7
+ * Main environment detection function
8
+ */
9
+ export declare function getEnvironment(): Environment;
10
+ /**
11
+ * Check if running in an interactive terminal
12
+ */
13
+ export declare function isRunningInTerminal(): boolean;
14
+ /**
15
+ * Check if environment supports ANSI colors
16
+ */
17
+ export declare function supportsANSI(): boolean;
18
+ /**
19
+ * Get environment-specific color capability
20
+ */
21
+ export declare function getColorCapability(): 'full' | 'basic' | 'none';
22
+ /**
23
+ * Environment information for debugging
24
+ */
25
+ export declare function getEnvironmentInfo(): {
26
+ environment: Environment;
27
+ supportsANSI: boolean;
28
+ colorCapability: "none" | "full" | "basic";
29
+ isTTY: boolean;
30
+ platform: string;
31
+ nodeVersion: string | null;
32
+ term: string | null | undefined;
33
+ colorTerm: string | null | undefined;
34
+ };
35
+ //# sourceMappingURL=environment-detector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"environment-detector.d.ts","sourceRoot":"","sources":["../../src/utils/environment-detector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,UAAU,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,GAAG,SAAS,CAAC;AAE/F;;GAEG;AACH,wBAAgB,cAAc,IAAI,WAAW,CA0B5C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAiC7C;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,OAAO,CAQtC;AAmBD;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,GAAG,OAAO,GAAG,MAAM,CAsB9D;AAED;;GAEG;AACH,wBAAgB,kBAAkB;;;;;;;;;EAWjC"}
@@ -37,7 +37,7 @@ export declare function supportsANSIColors(): boolean;
37
37
  * Gets environment-specific information
38
38
  */
39
39
  export declare function getEnvironmentInfo(): {
40
- runtime: "unknown" | "node" | "browser" | "webworker" | "deno";
40
+ runtime: "unknown" | "browser" | "webworker" | "deno" | "node";
41
41
  supportsColors: boolean;
42
42
  supportsCSSColors: boolean;
43
43
  supportsANSIColors: boolean;
@@ -1,4 +1,4 @@
1
- import { LogLevel, StackInfo, DevToolsTheme, AdaptiveColors } from '../types/index.js';
1
+ import { LogLevel, StackInfo, DevToolsTheme, AdaptiveColors, LogStyles } from '../types/index.js';
2
2
  /**
3
3
  * Style configuration for each log level
4
4
  */
@@ -24,8 +24,9 @@ export declare function getAdaptiveColor(colors: AdaptiveColors, theme?: DevTool
24
24
  export declare function setupThemeChangeListener(callback: (theme: DevToolsTheme) => void): (() => void) | null;
25
25
  /**
26
26
  * Creates styled console output with multiple %c formatters
27
+ * Automatically adapts to browser or terminal environment
27
28
  */
28
- export declare function createStyledOutput(level: LogLevel, levelStyles: Record<LogLevel | 'success', LevelStyleConfig>, prefix: string | undefined, message: string, stackInfo: StackInfo | null, autoDetectTheme?: boolean): [string, ...string[]];
29
+ export declare function createStyledOutput(level: LogLevel, levelStyles: Record<LogLevel | 'success', LevelStyleConfig>, prefix: string | undefined, message: string, stackInfo: StackInfo | null, autoDetectTheme?: boolean, presetStyles?: LogStyles, presetName?: string): [string, ...string[]];
29
30
  /**
30
31
  * Create a unique ID for log entries
31
32
  */
@@ -38,4 +39,8 @@ export declare function escapeHtml(text: string): string;
38
39
  * Convert objects to safe string representation for logging
39
40
  */
40
41
  export declare function safeStringify(obj: any, _maxDepth?: number): string;
42
+ /**
43
+ * Create terminal output with ANSI colors and formatting
44
+ */
45
+ export declare function createTerminalOutput(level: LogLevel, message: string, timestamp?: string, prefix?: string, stackInfo?: StackInfo | null, presetStyles?: LogStyles, presetName?: string): [string, ...string[]];
41
46
  //# sourceMappingURL=output.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/utils/output.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAK5F;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,aAAa,CAYnD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,cAAc,EAAE,K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"type": "module",
5
- "description": "Logger avanzado para consola con estilos CSS, temas adaptativos, badges automáticos, SVG, animaciones y CLI integrado",
5
+ "description": "Logger avanzado para consola con estilos CSS, temas adaptativos, badges automáticos, SVG, animaciones, CLI integrado y soporte dual browser/terminal con colores ANSI",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "keywords": [
@@ -18,6 +18,11 @@
18
18
  "debug",
19
19
  "consola",
20
20
  "registro",
21
+ "terminal",
22
+ "ansi",
23
+ "chalk",
24
+ "server",
25
+ "nodejs",
21
26
  "depuración",
22
27
  "temas",
23
28
  "badges",
@@ -88,5 +93,8 @@
88
93
  "typescript": "~5.8.3",
89
94
  "vite": "^7.1.2",
90
95
  "vite-plugin-dts": "^4.5.4"
96
+ },
97
+ "dependencies": {
98
+ "chalk": "^5.6.2"
91
99
  }
92
100
  }
package/src/Logger.ts CHANGED
@@ -24,6 +24,7 @@ import type {
24
24
  import { parseStackTrace } from './utils/stackTrace.js';
25
25
  import { formatTimestamp } from './utils/timestamps.js';
26
26
  import { createStyledOutput, setupThemeChangeListener } from './utils/output.js';
27
+ import { getEnvironment } from './utils/environment-detector.js';
27
28
 
28
29
  // Styling imports
29
30
  import {
@@ -383,12 +384,15 @@ export class Logger {
383
384
  // Apply the smart preset configuration
384
385
  this.displaySettings.showTimestamp = presetConfig.timestamp?.show ?? true;
385
386
  this.displaySettings.showLocation = presetConfig.location?.show ?? true;
386
-
387
+
387
388
  // Store the preset config for use in createStyledOutput
388
389
  (this as any)._activePreset = presetConfig;
389
390
  (this as any)._activePresetName = name;
390
-
391
- this.success(`Applied preset: ${name}`);
391
+
392
+ // Only show success message in browser to avoid verbose terminal logs
393
+ if (getEnvironment() === 'browser') {
394
+ this.success(`Applied preset: ${name}`);
395
+ }
392
396
  }
393
397
  }
394
398
 
@@ -698,12 +702,14 @@ export class Logger {
698
702
 
699
703
  // Create styled output with theme detection and display settings
700
704
  const [format, ...styles] = createStyledOutput(
701
- level,
702
- LEVEL_STYLES,
703
- prefix,
704
- message,
705
+ level,
706
+ LEVEL_STYLES,
707
+ prefix,
708
+ message,
705
709
  this.displaySettings.showLocation ? stackInfo : null,
706
- this.config.autoDetectTheme
710
+ this.config.autoDetectTheme,
711
+ (this as any)._activePreset,
712
+ (this as any)._activePresetName
707
713
  );
708
714
 
709
715
  // Add group indentation
@@ -824,12 +830,14 @@ export class Logger {
824
830
 
825
831
  // Handle success as special case - use info level with success styling
826
832
  const [format, ...styles] = createStyledOutput(
827
- 'info',
828
- LEVEL_STYLES,
829
- prefix,
830
- message,
833
+ 'info',
834
+ LEVEL_STYLES,
835
+ prefix,
836
+ message,
831
837
  this.displaySettings.showLocation ? stackInfo : null,
832
- this.config.autoDetectTheme
838
+ this.config.autoDetectTheme,
839
+ (this as any)._activePreset,
840
+ (this as any)._activePresetName
833
841
  );
834
842
 
835
843
  // Override with success styling