standard-log 11.4.0 → 11.5.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 (51) hide show
  1. package/README.md +5 -0
  2. package/cjs/index.d.ts +2 -2
  3. package/cjs/index.d.ts.map +1 -1
  4. package/cjs/index.js +0 -1
  5. package/cjs/index.js.map +1 -1
  6. package/cjs/logger.d.ts.map +1 -1
  7. package/cjs/logger.js +4 -4
  8. package/cjs/logger.js.map +1 -1
  9. package/cjs/standardLog.ctx.d.ts +10 -0
  10. package/cjs/standardLog.ctx.d.ts.map +1 -0
  11. package/cjs/standardLog.ctx.js +6 -0
  12. package/cjs/standardLog.ctx.js.map +1 -0
  13. package/cjs/standardLog.d.ts +1 -15
  14. package/cjs/standardLog.d.ts.map +1 -1
  15. package/cjs/standardLog.js +14 -14
  16. package/cjs/standardLog.js.map +1 -1
  17. package/cjs/types.d.ts +9 -2
  18. package/cjs/types.d.ts.map +1 -1
  19. package/cjs/types.js.map +1 -1
  20. package/dist/standard-log.es5.js +201 -269
  21. package/dist/standard-log.es5.js.gz +0 -0
  22. package/dist/standard-log.es5.js.map +1 -1
  23. package/dist/standard-log.es5.js.map.gz +0 -0
  24. package/dist/standard-log.esm.js +200 -163
  25. package/dist/standard-log.esm.js.gz +0 -0
  26. package/dist/standard-log.esm.js.map +1 -1
  27. package/dist/standard-log.esm.js.map.gz +0 -0
  28. package/esm/index.d.ts +2 -2
  29. package/esm/index.d.ts.map +1 -1
  30. package/esm/index.js +0 -1
  31. package/esm/index.js.map +1 -1
  32. package/esm/logger.d.ts.map +1 -1
  33. package/esm/logger.js +4 -4
  34. package/esm/logger.js.map +1 -1
  35. package/esm/standardLog.ctx.d.ts +10 -0
  36. package/esm/standardLog.ctx.d.ts.map +1 -0
  37. package/esm/standardLog.ctx.js +3 -0
  38. package/esm/standardLog.ctx.js.map +1 -0
  39. package/esm/standardLog.d.ts +1 -15
  40. package/esm/standardLog.d.ts.map +1 -1
  41. package/esm/standardLog.js +1 -1
  42. package/esm/standardLog.js.map +1 -1
  43. package/esm/types.d.ts +9 -2
  44. package/esm/types.d.ts.map +1 -1
  45. package/esm/types.js.map +1 -1
  46. package/package.json +3 -3
  47. package/ts/index.ts +7 -2
  48. package/ts/logger.ts +3 -4
  49. package/ts/standardLog.ctx.ts +8 -0
  50. package/ts/standardLog.ts +2 -14
  51. package/ts/types.ts +10 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "standard-log",
3
- "version": "11.4.0",
3
+ "version": "11.5.0",
4
4
  "description": "The standard log library",
5
5
  "homepage": "https://github.com/unional/standard-log/tree/main/packages/log",
6
6
  "bugs": {
@@ -39,7 +39,7 @@
39
39
  ],
40
40
  "dependencies": {
41
41
  "@just-func/types": "^0.5.0",
42
- "iso-error": "^4.4.0",
42
+ "iso-error": "^5.0.0",
43
43
  "ms": "^2.1.3",
44
44
  "type-plus": "^4.16.0",
45
45
  "upper-case": "^2.0.2"
@@ -95,7 +95,7 @@
95
95
  "build:clean": "rimraf *.tsbuildinfo",
96
96
  "build:cjs": "tsc -p ./tsconfig.cjs.json && ncp package.cjs.json cjs/package.json",
97
97
  "build:esm": "tsc -p ./tsconfig.esm.json",
98
- "build:tslib": "tsc -p ./tsconfig.tslib.json",
98
+ "build:tslib": "tsc -p ./tsconfig.tslib.json && ncp package.cjs.json tslib/package.json",
99
99
  "bundle": "run-p bundle:es5 bundle:esm",
100
100
  "bundle:es5": "webpack -c ./webpack.es5.cjs",
101
101
  "bundle:esm": "webpack -c ./webpack.esm.cjs",
package/ts/index.ts CHANGED
@@ -7,5 +7,10 @@ export {
7
7
  configGlobal, createStandardLog, createStandardLogForTest,
8
8
  getLogger, suppressLogs
9
9
  } from './standardLog.js'
10
- export type { StandardLog, StandardLogForTest, StandardLogInstance } from './standardLog.js'
11
- export * from './types.js'
10
+ export type { GetLogger, StandardLog, StandardLogForTest } from './standardLog.js'
11
+ export type {
12
+ ConsoleLike, LogEntry, LogFilter, LogFormatter, LogFunction, Logger, LoggerOptions, LogLevel,
13
+ LogLevelEntry, LogMethod, LogMethodNames, LogReporter, LogReporterOptions, ReporterFilter,
14
+ StandardLogInstance, StandardLogOptions
15
+ } from './types.js'
16
+
package/ts/logger.ts CHANGED
@@ -30,11 +30,10 @@ export function createLogger<N extends string = LogMethodNames>(
30
30
  count: {
31
31
  writable: false,
32
32
  value: ((counter) => (...args: any[]) => {
33
- const level = logLevels.debug
34
- if (shouldLog(store, level, logger.level))
33
+ if (shouldLog(store, logLevels.debug, logger.level))
35
34
  write({
36
35
  id,
37
- level,
36
+ level: logLevels.debug,
38
37
  args: [++counter, ...args],
39
38
  timestamp: new Date()
40
39
  })
@@ -47,7 +46,7 @@ export function createLogger<N extends string = LogMethodNames>(
47
46
  if (shouldLog(store, logLevel, logger.level)) {
48
47
  const methodName = store.logLevelStore.getName(logLevel)
49
48
  const bindedMethod = logger[methodName].bind(logger)
50
- const result = logFn(bindedMethod)
49
+ const result = logFn(bindedMethod, logger.level ?? store.logLevel)
51
50
  if (result) bindedMethod(result)
52
51
  }
53
52
  }
@@ -0,0 +1,8 @@
1
+ import { record } from 'type-plus'
2
+ import type { LogStore } from './logStore.js'
3
+ import type { LogMethodNames, StandardLogInstance } from './types.js'
4
+
5
+ export const ctx: {
6
+ configured?: boolean,
7
+ gsl?: { store: LogStore, standardLog: StandardLogInstance<LogMethodNames> }
8
+ } = record()
package/ts/standardLog.ts CHANGED
@@ -3,15 +3,8 @@ import { createLogger } from './logger.js'
3
3
  import { DEFAULT_LOG_METHOD_NAMES, logLevels } from './logLevels.js'
4
4
  import { createLogStore, LogStore } from './logStore.js'
5
5
  import { createMemoryLogReporter, MemoryLogReporter } from './memory.js'
6
- import type { Logger, LoggerOptions, LogLevel, LogMethodNames, StandardLogOptions } from './types.js'
7
-
8
- export interface StandardLogInstance<N extends string = LogMethodNames> {
9
- logLevel: number,
10
- toLogLevelName(level: number): string,
11
- toLogLevel(name: N): number,
12
- getLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>,
13
- getNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>
14
- }
6
+ import { ctx } from './standardLog.ctx.js'
7
+ import type { Logger, LoggerOptions, LogLevel, LogMethodNames, StandardLogInstance, StandardLogOptions } from './types.js'
15
8
 
16
9
  export interface StandardLog<N extends string = LogMethodNames> extends Readonly<StandardLogInstance<N>> {
17
10
  }
@@ -113,11 +106,6 @@ export function getLogger<N extends string = LogMethodNames>(id: string, options
113
106
  return getGlobalSL<N>().getLogger(id, options)
114
107
  }
115
108
 
116
- export const ctx: {
117
- configured?: boolean,
118
- gsl?: { store: LogStore, standardLog: StandardLogInstance<LogMethodNames> }
119
- } = record()
120
-
121
109
  function getGlobalSL<N extends string = LogMethodNames>(): StandardLogInstance<N> {
122
110
  if (!ctx.gsl) ctx.gsl = createStandardLogClosure()
123
111
 
package/ts/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { StackTraceMeta } from '@just-func/types'
1
+ import type { StackTraceMeta } from '@just-func/types'
2
2
 
3
3
  export type StandardLogOptions<CustomLevelNames extends string = LogMethodNames> = {
4
4
  customLevels?: Record<CustomLevelNames, number>,
@@ -44,10 +44,18 @@ export type LogEntry = {
44
44
 
45
45
  export type LogMethod = (...args: any[]) => void
46
46
 
47
- export type LogFunction = ((log: LogMethod) => void) | (() => string)
47
+ export type LogFunction = (log: LogMethod, logLevel: number) => string | void
48
48
 
49
49
  export type ReporterFilter = string | RegExp | ((reporterId: string) => boolean)
50
50
 
51
+ export interface StandardLogInstance<N extends string = LogMethodNames> {
52
+ logLevel: number,
53
+ toLogLevelName(level: number): string,
54
+ toLogLevel(name: N): number,
55
+ getLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>,
56
+ getNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>
57
+ }
58
+
51
59
  /**
52
60
  * Formats a log entry.
53
61
  * Depends on the reporter, it can expect a different return type.