Skip to content

Commit

Permalink
Merge branch 'release/v0.18.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
holtwick committed Mar 15, 2024
2 parents 4418217 + fcf647a commit 3721f3f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 32 deletions.
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.17.7",
"version": "0.18.0",
"description": "🌱 Simple foundation library",
"author": {
"name": "Dirk Holtwick",
Expand Down
32 changes: 16 additions & 16 deletions src/browser/log/log-browser-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ export function LoggerBrowserSetupDebugFactory(opt: LogHandlerOptions = {}) {
log.warn = defineForLogLevel(LogLevelWarn, originalConsole.warn.bind(originalConsole.console, ...fixedArgs))
log.error = defineForLogLevel(LogLevelError, originalConsole.error.bind(originalConsole.console, ...fixedArgs))

/**
* Takes log level as argument, but will fail to show all the debug info
* as the others do like file name and line number of the originating call
*/
log.generic = (logLevel: LogLevel, ...args) => {
if (level <= logLevel) {
if (logLevel === LogLevelError)
originalConsole.error(...fixedArgs, ...args)
else if (logLevel === LogLevelWarn)
originalConsole.warn(...fixedArgs, ...args)
else if (logLevel === LogLevelInfo)
originalConsole.info(...fixedArgs, ...args)
else
originalConsole.debug(...fixedArgs, ...args)
}
}
// /**
// * Takes log level as argument, but will fail to show all the debug info
// * as the others do like file name and line number of the originating call
// */
// log.generic = (logLevel: LogLevel, ...args) => {
// if (level <= logLevel) {
// if (logLevel === LogLevelError)
// originalConsole.error(...fixedArgs, ...args)
// else if (logLevel === LogLevelWarn)
// originalConsole.warn(...fixedArgs, ...args)
// else if (logLevel === LogLevelInfo)
// originalConsole.info(...fixedArgs, ...args)
// else
// originalConsole.debug(...fixedArgs, ...args)
// }
// }

log.fatal = defineForLogLevel(LogLevelFatal, (...args: any) => {
log.error(...args)
Expand Down
14 changes: 7 additions & 7 deletions src/common/log/log-console-capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ export function logCaptureConsole(log: LoggerInterface) {

onlyOnce = true

globalThis.console.log = (...args: any[]) => log.generic(LogLevelDebug, ...args)
globalThis.console.debug = (...args: any[]) => log.generic(LogLevelDebug, ...args)
globalThis.console.warn = (...args: any[]) => log.generic(LogLevelWarn, ...args)
globalThis.console.error = (...args: any[]) => log.generic(LogLevelError, ...args)
globalThis.console.info = (...args: any[]) => log.generic(LogLevelInfo, ...args)
globalThis.console.log = (...args: any[]) => log.debug(LogLevelDebug, ...args)
globalThis.console.debug = (...args: any[]) => log.debug(LogLevelDebug, ...args)
globalThis.console.warn = (...args: any[]) => log.warn(LogLevelWarn, ...args)
globalThis.console.error = (...args: any[]) => log.error(LogLevelError, ...args)
globalThis.console.info = (...args: any[]) => log.info(LogLevelInfo, ...args)

globalThis.addEventListener?.('unhandledrejection', (event: any) => {
log.generic(LogLevelError, 'onUnhandledrejection', event)
log.error('onUnhandledrejection', event)
})

globalThis.addEventListener?.('error', (event: any) => {
log.generic(LogLevelError, 'onError', event)
log.error('onError', event)
})
}
12 changes: 4 additions & 8 deletions src/common/log/log-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,22 @@ export function LoggerContext(_prefix = ''): LoggerContextInterface {
}

const emit = (msg: LogMessage) => {
// if (log.active === true) {
// if (msg.level >= Logger.level && msg.level >= log.level) {
if (logCheckNamespace(name)) {
for (const handler of logHandlers) {
if (handler)
handler(msg)
}
}
// }
// }
}

const log = defineForLogLevel(LogLevelDebug, (...messages: any[]) => {
emit({ name, messages, level: LogLevelDebug })
})

log.generic = function (level: LogLevel, ...messages: any[]) {
if (logLevel <= level)
emit({ name, messages, level })
}
// log.generic = function (level: LogLevel, ...messages: any[]) {
// if (logLevel <= level)
// emit({ name, messages, level })
// }

log.label = name
// log.active = true
Expand Down

0 comments on commit 3721f3f

Please sign in to comment.