Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: empty tag needs to be empty string #3

Merged
merged 1 commit into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@rocicorp/logger",
"description": "Logging utilities",
"version": "1.1.0",
"version": "1.1.1",
"repository": "github:rocicorp/logger",
"license": "Apache-2.0",
"engines": {
Expand Down
15 changes: 15 additions & 0 deletions src/logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,18 @@ test('LogContext default level', () => {
expect(mockInfo.lastCall.args).to.deep.equal(['bbb']);
expect(mockError.lastCall.args).to.deep.equal(['ccc']);
});

test('Optional tag', () => {
const mockDebug = mockConsoleMethod('debug');
const lc = new LogContext('debug');
lc.debug?.('a');
expect(mockDebug.lastCall.args).to.deep.equal(['a']);

const lc2 = lc.addContext('b');
lc2.debug?.('c');
expect(mockDebug.lastCall.args).to.deep.equal(['b', 'c']);

const lc3 = lc.addContext('d', 'e');
lc3.debug?.('f');
expect(mockDebug.lastCall.args).to.deep.equal(['d=e', 'f']);
});
4 changes: 2 additions & 2 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ export class SilentLogger implements OptionalLogger {
* f(lc2); // logging inside f will be prefixed with 'foo'
*/
export class LogContext extends OptionalLoggerImpl {
private readonly _s;
private readonly _s: string;
private readonly _logger: OptionalLogger;

/**
* @param loggerOrLevel If passed a LogLevel a ConsoleLogget is used
*/
constructor(loggerOrLevel: OptionalLogger | LogLevel = 'info', tag?: string) {
constructor(loggerOrLevel: OptionalLogger | LogLevel = 'info', tag = '') {
const actualLogger: OptionalLogger = isLogLevel(loggerOrLevel)
? new OptionalLoggerImpl(consoleLogger, loggerOrLevel)
: loggerOrLevel;
Expand Down