Skip to content

Commit

Permalink
Merge branch 'release/v0.19.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
holtwick committed Apr 4, 2024
2 parents bf6d246 + 66ed537 commit 4c57365
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@
"**/cypress/**",
"**/.{idea,git,cache,output,temp}/**"
],
"typescript.tsdk": "node_modules/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib",
"javascript.preferences.importModuleSpecifier": "relative"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zeed",
"type": "module",
"version": "0.18.7",
"version": "0.19.0",
"description": "🌱 Simple foundation library",
"author": {
"name": "Dirk Holtwick",
Expand Down
11 changes: 9 additions & 2 deletions src/browser/log/log-context-browser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { isEmpty } from '../../common'
import { getGlobalLogger } from '../../common/log'
import { isEmpty } from '../../common/data/is'
import { getGlobalLogger } from '../../common/log/log'
import type { LogLevelAliasType, LoggerInterface } from '../../common/log/log-base'
import type { LogConfig } from '../../common/log/log-config'
import { _LoggerFromConfig } from '../../common/log/log-config'
import { isBrowser } from '../../common/platform'
import { LoggerBrowserHandler } from './log-browser'
import { LoggerBrowserSetupDebugFactory } from './log-browser-factory'
Expand All @@ -13,3 +15,8 @@ export function Logger(name?: string, level?: LogLevelAliasType): LoggerInterfac
}
})(name, level)
}

/** See LogConfig */
export function LoggerFromConfig(config: LogConfig, name: string, level?: LogLevelAliasType): LoggerInterface {
return _LoggerFromConfig(Logger, config, name, level)
}
1 change: 1 addition & 0 deletions src/common/log/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './log'
export * from './log-base'
export * from './log-colors'
export * from './log-config'
export * from './log-console'
export * from './log-console-original'
export * from './log-console-capture'
Expand Down
35 changes: 35 additions & 0 deletions src/common/log/log-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { isNumber, isString } from '../data/is'
import { getGlobalLogger } from './log'
import type { LogLevelAliasType, LoggerInterface } from './log-base'

/**
* Simple log configuration for use in modular scenarios.
*
* `LogConfig` can be of various types:
*
* 1. `LoggerInterface`: Just a complete logger howeveryou like it
* 2. `true`: The default logger on
* 3. `string`: Logger with name
* 4. `number`: Logger with level e.g. set to `0` to see all
*
* All others turn it off.
*/
export type LogConfig = LoggerInterface | string | number | null | undefined | boolean

/** See LogConfig */
export function _LoggerFromConfig(
Logger: (name?: string, level?: LogLevelAliasType) => LoggerInterface,
config: LogConfig,
name: string,
level?: LogLevelAliasType,
): LoggerInterface {
if (config === true)
return Logger(name, level)
if (isString(config) && config.length > 0)
return Logger(config, level)
if (isNumber(config))
return Logger(name, config)
if (typeof config === 'function')
return config
return Logger(name, false)
}
11 changes: 9 additions & 2 deletions src/node/log/log-context-node.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import process from 'node:process'
import { valueToBoolean } from '../../common'
import { getGlobalLogger } from '../../common/log'
import { valueToBoolean } from '../../common/data/convert'
import type { LogConfig } from '../../common/log/log-config'
import { getGlobalLogger } from '../../common/log/log'
import type { LogLevelAliasType, LoggerInterface } from '../../common/log/log-base'
import { toPath } from '../env'
import { _LoggerFromConfig } from '../../common/log/log-config'
import { LoggerFileHandler } from './log-file'
import { LoggerNodeHandler } from './log-node'

Expand All @@ -25,3 +27,8 @@ export function Logger(name?: string, level?: LogLevelAliasType): LoggerInterfac
context.setHandlers(handlers)
})(name, level)
}

/** See LogConfig */
export function LoggerFromConfig(config: LogConfig, name: string, level?: LogLevelAliasType): LoggerInterface {
return _LoggerFromConfig(Logger, config, name, level)
}

0 comments on commit 4c57365

Please sign in to comment.