Skip to content

Commit

Permalink
Merge pull request #759 from hashicorp/ignore-cdktf-log-on-init
Browse files Browse the repository at this point in the history
fix(cli): dont error on init when log has been written
  • Loading branch information
skorfmann committed Jun 7, 2021
2 parents ca47534 + f086b48 commit c20b05b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/cdktf-cli/bin/cmds/init.ts
Expand Up @@ -12,7 +12,7 @@ import { terraformCheck } from './terraform-check';
import { displayVersionMessage } from './version-check'
import { FUTURE_FLAGS } from 'cdktf/lib/features';
import { downloadFile, HttpError } from '../../lib/util';
import { logger } from '../../lib/logging';
import { logFileName, logger } from '../../lib/logging';

const chalkColour = new chalk.Instance();

Expand Down Expand Up @@ -44,7 +44,7 @@ class Command implements yargs.CommandModule {
await terraformCheck()
await displayVersionMessage()

if (fs.readdirSync('.').filter(f => !f.startsWith('.')).length > 0) {
if (fs.readdirSync('.').filter(f => !f.startsWith('.') && f !== logFileName).length > 0) {
console.error(chalkColour`{redBright ERROR: Cannot initialize a project in a non-empty directory}`);
process.exit(1);
}
Expand Down
6 changes: 4 additions & 2 deletions packages/cdktf-cli/lib/logging.ts
Expand Up @@ -4,9 +4,10 @@ const logger = getLogger();

logger.level = process.env.CDKTF_LOG_LEVEL || 'INFO';

const logFileName = "cdktf.log";
if (process.env.CDKTF_DISABLE_LOGGING === 'false') {
configure({
appenders: { cdktf: { type: "file", filename: "./cdktf.log" } },
appenders: { cdktf: { type: "file", filename: "./" + logFileName } },
categories: { default: { appenders: ["cdktf"], level: "debug" } }
});
}
Expand All @@ -18,5 +19,6 @@ const processLogger = (chunk: Buffer | string | Uint8Array) => {
export {
logger,
getLogger,
processLogger
processLogger,
logFileName
}

0 comments on commit c20b05b

Please sign in to comment.