@stacksjs/logging 0.58.56 → 0.58.58

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 (3) hide show
  1. package/dist/index.js +161 -4
  2. package/package.json +1 -1
  3. package/src/index.ts +55 -12
package/dist/index.js CHANGED
@@ -1776,7 +1776,7 @@ var init_consola_36c0034f = __esm(() => {
1776
1776
  });
1777
1777
 
1778
1778
  // src/index.ts
1779
- import process2 from "process";
1779
+ import process3 from "process";
1780
1780
 
1781
1781
  // /home/runner/work/stacks/stacks/node_modules/consola/dist/index.mjs
1782
1782
  init_consola_36c0034f();
@@ -1786,17 +1786,174 @@ init_utils();
1786
1786
 
1787
1787
  // src/index.ts
1788
1788
  import {ExitCode} from "@stacksjs/types";
1789
+
1790
+ // /home/runner/work/stacks/stacks/storage/framework/core/path/src/index.ts
1791
+ import process2 from "process";
1792
+
1793
+ // /home/runner/work/stacks/stacks/node_modules/pathe/dist/shared/pathe.ff20891b.mjs
1794
+ var normalizeWindowsPath = function(input = "") {
1795
+ if (!input) {
1796
+ return input;
1797
+ }
1798
+ return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r2) => r2.toUpperCase());
1799
+ };
1800
+ var cwd = function() {
1801
+ if (typeof process !== "undefined" && typeof process.cwd === "function") {
1802
+ return process.cwd().replace(/\\/g, "/");
1803
+ }
1804
+ return "/";
1805
+ };
1806
+ var normalizeString = function(path, allowAboveRoot) {
1807
+ let res = "";
1808
+ let lastSegmentLength = 0;
1809
+ let lastSlash = -1;
1810
+ let dots = 0;
1811
+ let char = null;
1812
+ for (let index = 0;index <= path.length; ++index) {
1813
+ if (index < path.length) {
1814
+ char = path[index];
1815
+ } else if (char === "/") {
1816
+ break;
1817
+ } else {
1818
+ char = "/";
1819
+ }
1820
+ if (char === "/") {
1821
+ if (lastSlash === index - 1 || dots === 1)
1822
+ ;
1823
+ else if (dots === 2) {
1824
+ if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
1825
+ if (res.length > 2) {
1826
+ const lastSlashIndex = res.lastIndexOf("/");
1827
+ if (lastSlashIndex === -1) {
1828
+ res = "";
1829
+ lastSegmentLength = 0;
1830
+ } else {
1831
+ res = res.slice(0, lastSlashIndex);
1832
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
1833
+ }
1834
+ lastSlash = index;
1835
+ dots = 0;
1836
+ continue;
1837
+ } else if (res.length > 0) {
1838
+ res = "";
1839
+ lastSegmentLength = 0;
1840
+ lastSlash = index;
1841
+ dots = 0;
1842
+ continue;
1843
+ }
1844
+ }
1845
+ if (allowAboveRoot) {
1846
+ res += res.length > 0 ? "/.." : "..";
1847
+ lastSegmentLength = 2;
1848
+ }
1849
+ } else {
1850
+ if (res.length > 0) {
1851
+ res += `/${path.slice(lastSlash + 1, index)}`;
1852
+ } else {
1853
+ res = path.slice(lastSlash + 1, index);
1854
+ }
1855
+ lastSegmentLength = index - lastSlash - 1;
1856
+ }
1857
+ lastSlash = index;
1858
+ dots = 0;
1859
+ } else if (char === "." && dots !== -1) {
1860
+ ++dots;
1861
+ } else {
1862
+ dots = -1;
1863
+ }
1864
+ }
1865
+ return res;
1866
+ };
1867
+ var _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
1868
+ var _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
1869
+ var resolve = function(...arguments_) {
1870
+ arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
1871
+ let resolvedPath = "";
1872
+ let resolvedAbsolute = false;
1873
+ for (let index = arguments_.length - 1;index >= -1 && !resolvedAbsolute; index--) {
1874
+ const path = index >= 0 ? arguments_[index] : cwd();
1875
+ if (!path || path.length === 0) {
1876
+ continue;
1877
+ }
1878
+ resolvedPath = `${path}/${resolvedPath}`;
1879
+ resolvedAbsolute = isAbsolute(path);
1880
+ }
1881
+ resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
1882
+ if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
1883
+ return `/${resolvedPath}`;
1884
+ }
1885
+ return resolvedPath.length > 0 ? resolvedPath : ".";
1886
+ };
1887
+ var isAbsolute = function(p2) {
1888
+ return _IS_ABSOLUTE_RE.test(p2);
1889
+ };
1890
+ // /home/runner/work/stacks/stacks/storage/framework/core/path/src/index.ts
1891
+ function logsPath(path2) {
1892
+ return projectStoragePath(`logs/${path2 || ""}`);
1893
+ }
1894
+ function projectPath(filePath = "") {
1895
+ let path2 = process2.cwd();
1896
+ while (path2.includes("storage"))
1897
+ path2 = resolve(path2, "..");
1898
+ return resolve(path2, filePath);
1899
+ }
1900
+ function projectStoragePath(path2) {
1901
+ return projectPath(`storage/${path2 || ""}`);
1902
+ }
1903
+
1904
+ // src/index.ts
1905
+ async function writeToLogFile(message) {
1906
+ const formattedMessage = `[${new Date().toISOString()}] ${message}\n`;
1907
+ try {
1908
+ const file = Bun.file(logFilePath);
1909
+ const writer = file.writer();
1910
+ const text2 = await file.text();
1911
+ writer.write(`${text2}\n`);
1912
+ writer.write(`${formattedMessage}\n`);
1913
+ await writer.end();
1914
+ } catch (error) {
1915
+ const file = Bun.file(logFilePath);
1916
+ const writer = file.writer();
1917
+ writer.write(`${formattedMessage}\n`);
1918
+ await writer.end();
1919
+ }
1920
+ }
1789
1921
  function dump(...args) {
1790
- return log.debug(args);
1922
+ args.forEach((arg) => log.debug(arg));
1791
1923
  }
1792
1924
  function dd(...args) {
1793
1925
  args.forEach((arg) => log.debug(arg));
1794
- process2.exit(ExitCode.FatalError);
1926
+ process3.exit(ExitCode.FatalError);
1795
1927
  }
1796
1928
  var logger = consola;
1797
- var log = consola;
1929
+ var logFilePath = logsPath("console.log");
1930
+ var log = {
1931
+ info: async (...arg) => {
1932
+ consola.info(...arg);
1933
+ await writeToLogFile(`INFO: ${arg}`);
1934
+ },
1935
+ success: async (msg) => {
1936
+ consola.success(msg);
1937
+ await writeToLogFile(`SUCCESS: ${msg}`);
1938
+ },
1939
+ error: async (err, options) => {
1940
+ handleError(err, options);
1941
+ await writeToLogFile(`ERROR: ${err}`);
1942
+ },
1943
+ warn: async (arg) => {
1944
+ consola.warn(arg);
1945
+ await writeToLogFile(`WARN: ${arg}`);
1946
+ },
1947
+ debug: async (arg) => {
1948
+ consola.debug(arg);
1949
+ await writeToLogFile(`DEBUG: ${arg}`);
1950
+ },
1951
+ dump,
1952
+ dd
1953
+ };
1798
1954
  export {
1799
1955
  logger,
1956
+ logFilePath,
1800
1957
  log,
1801
1958
  dump,
1802
1959
  dd
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/logging",
3
3
  "type": "module",
4
- "version": "0.58.56",
4
+ "version": "0.58.58",
5
5
  "description": "The Stacks logging system.",
6
6
  "author": "Chris Breuer",
7
7
  "license": "MIT",
package/src/index.ts CHANGED
@@ -1,22 +1,65 @@
1
1
  import process from 'node:process'
2
2
  import consola from 'consola'
3
3
  import { ExitCode } from '@stacksjs/types'
4
+ import { logsPath } from '@stacksjs/path'
4
5
 
5
6
  export const logger = consola
6
- export const log = consola
7
- // export const log = {
8
- // info: (...args: any[]) => consola.info(...args),
9
- // success: (msg: string) => logger.success(msg),
10
- // error: (err: string | StacksError, options?: any) => handleError(err, options),
11
- // warn: (...args: any[]) => logger.warn(...args),
12
- // debug: (...args: any[]) => logger.debug(...args),
13
- // prompt:
14
- // dump,
15
- // dd,
16
- // }
7
+
8
+ export const logFilePath = logsPath('console.log')
9
+
10
+ async function writeToLogFile(message: string) {
11
+ const formattedMessage = `[${new Date().toISOString()}] ${message}\n`
12
+ try {
13
+ const file = Bun.file(logFilePath)
14
+ const writer = file.writer()
15
+ const text = await file.text()
16
+ writer.write(`${text}\n`)
17
+ writer.write(`${formattedMessage}\n`)
18
+ await writer.end()
19
+ }
20
+ catch (error) {
21
+ // Assuming the error is due to the file not existing
22
+ // Create the file and then write the message
23
+ const file = Bun.file(logFilePath) // Use the create option
24
+ const writer = file.writer()
25
+ writer.write(`${formattedMessage}\n`)
26
+ await writer.end()
27
+ }
28
+ }
29
+
30
+ export const log = {
31
+ info: async (...arg: any) => {
32
+ consola.info(...arg)
33
+ await writeToLogFile(`INFO: ${arg}`)
34
+ },
35
+
36
+ success: async (msg: string) => {
37
+ consola.success(msg)
38
+ await writeToLogFile(`SUCCESS: ${msg}`)
39
+ },
40
+
41
+ error: async (err: string, options?: any) => {
42
+ handleError(err, options) // Assuming handleError logs the error
43
+ await writeToLogFile(`ERROR: ${err}`)
44
+ },
45
+
46
+ warn: async (arg: string) => {
47
+ consola.warn(arg)
48
+ await writeToLogFile(`WARN: ${arg}`)
49
+ },
50
+
51
+ debug: async (arg: string) => {
52
+ consola.debug(arg)
53
+ await writeToLogFile(`DEBUG: ${arg}`)
54
+ },
55
+
56
+ // prompt,
57
+ dump,
58
+ dd,
59
+ }
17
60
 
18
61
  export function dump(...args: any[]) {
19
- return log.debug(args)
62
+ args.forEach(arg => log.debug(arg))
20
63
  }
21
64
 
22
65
  export function dd(...args: any[]) {