Skip to content

Commit

Permalink
aio app logs display info message in case custom log forwarding is …
Browse files Browse the repository at this point in the history
…configured
  • Loading branch information
buskamuza committed Jan 20, 2022
1 parent f3d5208 commit bad8b16
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/commands/app/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ governing permissions and limitations under the License.
*/

const { flags } = require('@oclif/command')
// const { cli } = require('cli-ux')
const BaseCommand = require('../../BaseCommand')
const { wrapError } = require('../../lib/app-helper')
const rtLib = require('@adobe/aio-lib-runtime')
const LogForwarding = require('../../lib/log-forwarding')

class Logs extends BaseCommand {
_processEachAction (fullConfig, processFn) {
Expand All @@ -40,6 +40,15 @@ class Logs extends BaseCommand {
throw new Error('There are no backend implementations for this project folder.')
}

const lf = await LogForwarding.init(fullConfig.aio)
const serverConfig = await lf.getServerConfig()
const logForwardingDestination = serverConfig.getDestination()
if (logForwardingDestination !== 'adobe_io_runtime') {
this.log(`Namespace is configured with custom log forwarding destination: '${logForwardingDestination}'. ` +
'Please use corresponding logging platform to view logs.')
return
}

if (flags.limit < 1) {
this.log('--limit should be > 0, using --limit=1')
flags.limit = 1
Expand Down
29 changes: 26 additions & 3 deletions test/commands/app/logs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@ governing permissions and limitations under the License.
const TheCommand = require('../../../src/commands/app/logs')
const BaseCommand = require('../../../src/BaseCommand')
const dataMocks = require('../../data-mocks/config-loader')
const LogForwarding = require('../../../src/lib/log-forwarding')

jest.mock('../../../src/lib/log-forwarding', () => {
const orig = jest.requireActual('../../../src/lib/log-forwarding')
return {
...orig,
init: jest.fn()
}
})

const createFullConfig = (aioConfig = {}, appFixtureName = 'legacy-app') => {
const appConfig = dataMocks(appFixtureName, aioConfig)
return appConfig
return dataMocks(appFixtureName, aioConfig)
}

const mockFS = require('fs-extra')
Expand Down Expand Up @@ -51,7 +59,7 @@ describe('interface', () => {
})

describe('run', () => {
let command
let command, logForwarding

const owConfig = () => Object.values(command.appConfig.all)[0].ow // every extension has the same 'ow' package

Expand All @@ -66,6 +74,11 @@ describe('run', () => {
command.log = jest.fn()
command.getFullConfig = jest.fn()
command.getFullConfig.mockReturnValue(command.appConfig)
logForwarding = {
getServerConfig: jest.fn()
.mockResolvedValue(new LogForwarding.LogForwardingConfig('adobe_io_runtime', {}))
}
LogForwarding.init.mockResolvedValue(logForwarding)
})

test('no flags, sets limit to 1', async () => {
Expand All @@ -78,6 +91,16 @@ describe('run', () => {
expect(command.error).not.toHaveBeenCalled()
})

test('no flags, custom log forwarding', async () => {
mockFS.existsSync.mockReturnValue(true)
logForwarding.getServerConfig.mockResolvedValue(
new LogForwarding.LogForwardingConfig('custom_destination', {})
)

await command.run()
expect(printActionLogs).not.toHaveBeenCalled()
})

test('--limit < 1, sets limit to 1', async () => {
mockFS.existsSync.mockReturnValue(true)
command.argv = ['--limit', '-1']
Expand Down

0 comments on commit bad8b16

Please sign in to comment.