This repository was archived by the owner on Aug 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolves #50
- Loading branch information
Alan Shaw
authored
Apr 5, 2019
1 parent
89975d3
commit 2da3b5d
Showing
6 changed files
with
160 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const toUri = require('multiaddr-to-uri') | ||
const QueryString = require('querystring') | ||
const { ok } = require('../../lib/fetch') | ||
|
||
module.exports = (fetch, config) => { | ||
return async (level, options) => { | ||
options = options || {} | ||
|
||
const qs = { arg: level } | ||
|
||
if (options.subsystem) { | ||
qs.subsystem = options.subsystem | ||
} | ||
|
||
const url = `${toUri(config.apiAddr)}/api/log/level?${QueryString.stringify(qs)}` | ||
const res = await ok(fetch(url, { signal: options.signal })) | ||
return res.json() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const test = require('ava') | ||
const CID = require('cids') | ||
const Filecoin = require('../helpers/filecoin') | ||
|
||
test('should set the log level for all subsystems', async t => { | ||
const fc = Filecoin() | ||
|
||
let res | ||
res = await fc.log.level('error') | ||
t.is(res, 'Changed log level of all subsystems to: error') | ||
|
||
res = await fc.log.level('warning') | ||
t.is(res, 'Changed log level of all subsystems to: warning') | ||
|
||
res = await fc.log.level('info') | ||
t.is(res, 'Changed log level of all subsystems to: info') | ||
}) | ||
|
||
test('should set the log level for a specific subsystem', async t => { | ||
const fc = Filecoin() | ||
|
||
let res | ||
res = await fc.log.level('error', { subsystem: 'ping' }) | ||
t.is(res, 'Changed log level of \'ping\' to \'error\'') | ||
|
||
res = await fc.log.level('warning', { subsystem: 'ping' }) | ||
t.is(res, 'Changed log level of \'ping\' to \'warning\'') | ||
|
||
res = await fc.log.level('info', { subsystem: 'ping' }) | ||
t.is(res, 'Changed log level of \'ping\' to \'info\'') | ||
}) | ||
|
||
test('should error for unknown log level', async t => { | ||
const fc = Filecoin() | ||
const err = await t.throwsAsync(fc.log.level('foo')) | ||
t.is(err.message, 'unknown log level: foo. Available levels: debug, info, warning, error, fatal, panic') | ||
}) | ||
|
||
test('should error for unknown subsystem', async t => { | ||
const fc = Filecoin() | ||
const err = await t.throwsAsync(fc.log.level('info', { subsystem: 'foo' })) | ||
t.is(err.message, 'Error: No such logger') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const test = require('ava') | ||
const Filecoin = require('../../../../src') | ||
|
||
test('should set the log level for all subsystems', async t => { | ||
const level = 'error' | ||
const expectedMessage = `Changed log level of all subsystems to: ${level}` | ||
const fetch = url => { | ||
url = new URL(url) | ||
t.is(url.searchParams.get('arg'), level) | ||
return { ok: true, json: () => expectedMessage } | ||
} | ||
const fc = Filecoin(fetch) | ||
|
||
const msg = await fc.log.level(level) | ||
t.is(msg, expectedMessage) | ||
}) | ||
|
||
test('should set the log level for a specific subsystem', async t => { | ||
const level = 'error' | ||
const subsystem = 'ping' | ||
const expectedMessage = `Changed log level of \'${subsystem}\' to \'${level}\'` | ||
const fetch = url => { | ||
url = new URL(url) | ||
t.is(url.searchParams.get('arg'), level) | ||
t.is(url.searchParams.get('subsystem'), subsystem) | ||
return { ok: true, json: () => expectedMessage } | ||
} | ||
const fc = Filecoin(fetch) | ||
|
||
const msg = await fc.log.level(level, { subsystem }) | ||
t.is(msg, expectedMessage) | ||
}) | ||
|
||
test('should error for unknown log level', async t => { | ||
const level = 'foo' | ||
const expectedMessage = `'unknown log level: ${level}. Available levels: debug, info, warning, error, fatal, panic'` | ||
const fetch = url => { | ||
return { ok: false, text: () => JSON.stringify({ Message: expectedMessage }) } | ||
} | ||
const fc = Filecoin(fetch) | ||
|
||
const err = await t.throwsAsync(fc.log.level(level)) | ||
t.is(err.message, expectedMessage) | ||
}) | ||
|
||
test('should error for unknown subsystem', async t => { | ||
const level = 'error' | ||
const subsystem = 'foo' | ||
const expectedMessage = 'Error: No such logger' | ||
const fetch = url => { | ||
return { ok: false, text: () => JSON.stringify({ Message: expectedMessage }) } | ||
} | ||
const fc = Filecoin(fetch) | ||
|
||
const err = await t.throwsAsync(fc.log.level(level, { subsystem })) | ||
t.is(err.message, expectedMessage) | ||
}) |