Skip to content

Commit

Permalink
Merge branch 'release/release/0.13.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
holtwick committed Sep 12, 2023
2 parents 46f46fa + b742c5e commit 3a69383
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 12 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.13.4",
"version": "0.13.5",
"description": "🌱 Simple foundation library",
"author": {
"name": "Dirk Holtwick",
Expand Down
10 changes: 5 additions & 5 deletions src/browser/log/log-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import type { LogHandler, LogHandlerOptions, LogMessage } from '../../common/log/log-base'
import { LogLevelError, LogLevelInfo, LogLevelWarn } from '../../common/log/log-base'
import { browserSelectColorByName } from '../../common/log/log-colors'
import { useLevelFilter, useNamespaceFilter } from '../../common/log/log-filter'
import { joinLogStrings, useLevelFilter, useNamespaceFilter } from '../../common/log/log-filter'
import { formatMilliseconds, getTimestamp } from '../../common/time'
import { browserSupportsColors } from './log-colors'

Expand Down Expand Up @@ -84,22 +84,22 @@ export function LoggerBrowserHandler(opt: LogHandlerOptions = {}): LogHandler {
case LogLevelInfo:
if (opt.levelHelper)
args[0] = `I|* ${args[0]}`
console.info(...args)
console.info(joinLogStrings(...args))
break
case LogLevelWarn:
if (opt.levelHelper)
args[0] = `W|** ${args[0]}`
console.warn(...args)
console.warn(joinLogStrings(...args))
break
case LogLevelError:
if (opt.levelHelper)
args[0] = `E|*** ${args[0]}`
console.error(...args)
console.error(joinLogStrings(...args))
break
default:
if (opt.levelHelper)
args[0] = `D| ${args[0]}`
console.debug(...args)
console.debug(joinLogStrings(...args))
break
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/common/data/lru.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// https://github.com/sindresorhus/quick-lru

// todo
10 changes: 5 additions & 5 deletions src/common/log/log-console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import type { LogHandler, LogHandlerOptions, LogMessage } from './log-base'
import { LogLevelError, LogLevelInfo, LogLevelWarn } from './log-base'
import { useLevelFilter, useNamespaceFilter } from './log-filter'
import { joinLogStrings, useLevelFilter, useNamespaceFilter } from './log-filter'

/**
* Very basic logger. Please take a look at the browser and node
Expand Down Expand Up @@ -32,16 +32,16 @@ export function LoggerConsoleHandler(opt: LogHandlerOptions = {}): LogHandler {
const name = msg.name ? `[${msg.name}]` : ''
switch (msg.level) {
case LogLevelInfo:
console.info(`I|* ${name}`, ...msg.messages)
console.info(joinLogStrings(`I|* ${name}`, ...msg.messages))
break
case LogLevelWarn:
console.warn(`W|** ${name}`, ...msg.messages)
console.warn(joinLogStrings(`W|** ${name}`, ...msg.messages))
break
case LogLevelError:
console.error(`E|*** ${name}`, ...msg.messages)
console.error(joinLogStrings(`E|*** ${name}`, ...msg.messages))
break
default:
console.debug(`D| ${name}`, ...msg.messages)
console.debug(joinLogStrings(`D| ${name}`, ...msg.messages))
break
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/common/log/log-filter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

import { LogLevelAll, LogLevelDebug, LogLevelError, LogLevelInfo, LogLevelOff, LogLevelWarn } from './log-base'
import { getNamespaceFilterString, parseLogLevel, useLevelFilter, useNamespaceFilter } from './log-filter'
import { getNamespaceFilterString, joinLogStrings, parseLogLevel, useLevelFilter, useNamespaceFilter } from './log-filter'

describe('log-filter', () => {
test('should match', () => {
Expand Down Expand Up @@ -106,4 +106,11 @@ describe('log-filter', () => {
expect(parseLogLevel(true)).toEqual(LogLevelAll)
expect(parseLogLevel(2)).toEqual(LogLevelWarn)
})

it('should join strings', () => {
expect(joinLogStrings('test')).toMatchInlineSnapshot(['test'])
expect(joinLogStrings('test', 'more', 1,2,3)).toMatchInlineSnapshot(['test more',1,2,3])
expect(joinLogStrings('test', {a:1})).toMatchInlineSnapshot(['test', {a:1}])
expect(joinLogStrings('test', 'a', 'b', true, undefined, null, {a:1})).toMatchInlineSnapshot(['test a', 'b', true, undefined, null, {a:1}])
});
})
17 changes: 17 additions & 0 deletions src/common/log/log-filter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.
/* eslint-disable n/prefer-global/process */

import { isPrimitive, isString } from '../data'
import type { LogLevel, LogLevelAliasType } from './log-base'
import { LogLevelAlias, LogLevelAll, LogLevelOff } from './log-base'

Expand Down Expand Up @@ -133,3 +134,19 @@ export function useLevelFilter(
const filterLevel = parseLogLevel(filter)
return level => level >= filterLevel
}

export function joinLogStrings(...messages: any[]) {
if (!isString(messages[1]))
return messages
return [`${String(messages[0])} ${String(messages[1])}`, ...messages.slice(2)]

// let s = ''
// for (let i = 0; i < messages.length; i++) {
// const element = messages[i]
// if (isString(element))
// s += (s.length > 1 ? ' ' : '') + String(element)
// else
// return [s, ...messages.slice(i)]
// }
// return [s]
}

0 comments on commit 3a69383

Please sign in to comment.