UNPKG

@salesforce/plugin-apex

Version:
82 lines 3.33 kB
/* * Copyright 2026, Salesforce, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { LogService } from '@salesforce/apex-node'; import { Flags, SfCommand, requiredOrgFlagWithDeprecations, orgApiVersionFlagWithDeprecations, loglevel, } from '@salesforce/sf-plugins-core'; import { Messages } from '@salesforce/core'; import { colorLogs } from '../../../logColorize.js'; Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); const messages = Messages.loadMessages('@salesforce/plugin-apex', 'tail'); export default class Log extends SfCommand { static summary = messages.getMessage('summary'); static description = messages.getMessage('description'); static examples = messages.getMessages('examples'); static deprecateAliases = true; static aliases = ['force:apex:log:tail']; static enableJsonFlag = false; static flags = { 'target-org': requiredOrgFlagWithDeprecations, 'api-version': orgApiVersionFlagWithDeprecations, loglevel, color: Flags.boolean({ char: 'c', summary: messages.getMessage('flags.color.summary'), }), 'debug-level': Flags.string({ deprecateAliases: true, aliases: ['debuglevel'], char: 'd', summary: messages.getMessage('flags.debug-level.summary'), exclusive: ['skip-trace-flag'], }), 'skip-trace-flag': Flags.boolean({ deprecateAliases: true, aliases: ['skiptraceflag'], char: 's', summary: messages.getMessage('flags.skip-trace-flag.summary'), }), }; color; async run() { const { flags } = await this.parse(Log); this.color = flags.color; const conn = flags['target-org'].getConnection(flags['api-version']); const logService = this.getLogService(conn); if (!flags['skip-trace-flag']) { await logService.prepareTraceFlag(flags['debug-level'] ?? ''); } // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-misused-promises await logService.tail(flags['target-org'], this.logTailer.bind(this)); this.log(messages.getMessage('finishedTailing')); } // the colorize function used to be async, but not isn't. Preserving the public method signature // eslint-disable-next-line @typescript-eslint/require-await async logTailer(fullLog) { if (fullLog) { this.log(this.color ? colorLogs(fullLog) : fullLog); } } /** * for UT purposes * * @param conn : Connection to the org * @private */ // eslint-disable-next-line class-methods-use-this getLogService(conn) { return new LogService(conn); } } //# sourceMappingURL=log.js.map