Skip to content

Commit

Permalink
Merge pull request #971 from Accenture/bugfix/207-logs-folder-automat…
Browse files Browse the repository at this point in the history
…ically-created

bugfix/207: dont create logfile when running helper methods + bugfix/969: log not truncated during test execution
  • Loading branch information
JoernBerkefeld committed Jun 6, 2023
2 parents d3dd9d5 + e5c2295 commit 247752a
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 154 deletions.
71 changes: 52 additions & 19 deletions docs/dist/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,6 @@ Provides default functionality that can be overwritten by child metadata type cl
<dt><a href="#setupSDK">setupSDK(sessionKey, authObject)</a> ⇒ <code><a href="#SDK">SDK</a></code></dt>
<dd><p>Returns an SDK instance to be used for API calls</p>
</dd>
<dt><a href="#createNewLoggerTransport">createNewLoggerTransport()</a> ⇒ <code>object</code></dt>
<dd><p>wrapper around our standard winston logging to console and logfile</p>
</dd>
<dt><a href="#startLogger">startLogger()</a> ⇒ <code>void</code></dt>
<dd><p>initiate winston logger</p>
</dd>
</dl>

## Typedefs
Expand Down Expand Up @@ -5898,6 +5892,8 @@ CLI entry for SFMC DevTools
* [._isValidType(selectedType, [handleOutside])](#Util._isValidType) ⇒ <code>boolean</code>
* [.getTypeAndSubType(selectedType)](#Util.getTypeAndSubType) ⇒ <code>Array.&lt;string&gt;</code>
* [.getRetrieveTypeChoices()](#Util.getRetrieveTypeChoices) ⇒ <code>Array.&lt;TYPE.SupportedMetadataTypes&gt;</code>
* [._createNewLoggerTransport([noLogFile])](#Util._createNewLoggerTransport) ⇒ <code>object</code>
* [.startLogger([restart], [noLogFile])](#Util.startLogger) ⇒ <code>void</code>
* [.metadataLogger(level, type, method, payload, [source])](#Util.metadataLogger) ⇒ <code>void</code>
* [.replaceByObject(str, obj)](#Util.replaceByObject) ⇒ <code>string</code> \| <code>object</code>
* [.inverseGet(objs, val)](#Util.inverseGet) ⇒ <code>string</code>
Expand Down Expand Up @@ -6049,6 +6045,30 @@ helper for getDefaultProperties()

**Kind**: static method of [<code>Util</code>](#Util)
**Returns**: <code>Array.&lt;TYPE.SupportedMetadataTypes&gt;</code> - type choices
<a name="Util._createNewLoggerTransport"></a>

### Util.\_createNewLoggerTransport([noLogFile]) ⇒ <code>object</code>
wrapper around our standard winston logging to console and logfile

**Kind**: static method of [<code>Util</code>](#Util)
**Returns**: <code>object</code> - initiated logger for console and file

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [noLogFile] | <code>boolean</code> | <code>false</code> | optional flag to indicate if we should log to file; CLI logs are always on |

<a name="Util.startLogger"></a>

### Util.startLogger([restart], [noLogFile]) ⇒ <code>void</code>
initiate winston logger

**Kind**: static method of [<code>Util</code>](#Util)

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [restart] | <code>boolean</code> | <code>false</code> | if true, logger will be restarted; otherwise, an existing logger will be used |
| [noLogFile] | <code>boolean</code> | <code>false</code> | if false, logger will log to file; otherwise, only to console |

<a name="Util.metadataLogger"></a>

### Util.metadataLogger(level, type, method, payload, [source]) ⇒ <code>void</code>
Expand Down Expand Up @@ -7762,6 +7782,8 @@ Util that contains logger and simple util methods
* [._isValidType(selectedType, [handleOutside])](#Util._isValidType) ⇒ <code>boolean</code>
* [.getTypeAndSubType(selectedType)](#Util.getTypeAndSubType) ⇒ <code>Array.&lt;string&gt;</code>
* [.getRetrieveTypeChoices()](#Util.getRetrieveTypeChoices) ⇒ <code>Array.&lt;TYPE.SupportedMetadataTypes&gt;</code>
* [._createNewLoggerTransport([noLogFile])](#Util._createNewLoggerTransport) ⇒ <code>object</code>
* [.startLogger([restart], [noLogFile])](#Util.startLogger) ⇒ <code>void</code>
* [.metadataLogger(level, type, method, payload, [source])](#Util.metadataLogger) ⇒ <code>void</code>
* [.replaceByObject(str, obj)](#Util.replaceByObject) ⇒ <code>string</code> \| <code>object</code>
* [.inverseGet(objs, val)](#Util.inverseGet) ⇒ <code>string</code>
Expand Down Expand Up @@ -7913,6 +7935,30 @@ helper for getDefaultProperties()

**Kind**: static method of [<code>Util</code>](#Util)
**Returns**: <code>Array.&lt;TYPE.SupportedMetadataTypes&gt;</code> - type choices
<a name="Util._createNewLoggerTransport"></a>

### Util.\_createNewLoggerTransport([noLogFile]) ⇒ <code>object</code>
wrapper around our standard winston logging to console and logfile

**Kind**: static method of [<code>Util</code>](#Util)
**Returns**: <code>object</code> - initiated logger for console and file

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [noLogFile] | <code>boolean</code> | <code>false</code> | optional flag to indicate if we should log to file; CLI logs are always on |

<a name="Util.startLogger"></a>

### Util.startLogger([restart], [noLogFile]) ⇒ <code>void</code>
initiate winston logger

**Kind**: static method of [<code>Util</code>](#Util)

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [restart] | <code>boolean</code> | <code>false</code> | if true, logger will be restarted; otherwise, an existing logger will be used |
| [noLogFile] | <code>boolean</code> | <code>false</code> | if false, logger will log to file; otherwise, only to console |

<a name="Util.metadataLogger"></a>

### Util.metadataLogger(level, type, method, payload, [source]) ⇒ <code>void</code>
Expand Down Expand Up @@ -8171,19 +8217,6 @@ Returns an SDK instance to be used for API calls
| sessionKey | <code>string</code> | key for specific BU |
| authObject | <code>TYPE.AuthObject</code> | credentials for specific BU |

<a name="createNewLoggerTransport"></a>

## createNewLoggerTransport() ⇒ <code>object</code>
wrapper around our standard winston logging to console and logfile

**Kind**: global function
**Returns**: <code>object</code> - initiated logger for console and file
<a name="startLogger"></a>

## startLogger() ⇒ <code>void</code>
initiate winston logger

**Kind**: global function
<a name="TypeKeyCombo"></a>

## TypeKeyCombo : <code>Object.&lt;string, string&gt;</code>
Expand Down
4 changes: 2 additions & 2 deletions lib/Deployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Deployer {
buMultiMetadataTypeMap[cred + '/' + bu] = multiMetadataTypeMap;
counter_credBu++;
Util.logger.info('');
Util.restartLogger();
Util.startLogger(true);
}
} else {
// anything but "*" passed in
Expand Down Expand Up @@ -157,7 +157,7 @@ class Deployer {
buMultiMetadataTypeMap[cred + '/' + buPath] = multiMetadataTypeMap;
counter_credBu++;
Util.logger.info('');
Util.restartLogger();
Util.startLogger(true);
}
Util.logger.info(`\n :: ${counter_credBu} BUs for ${cred}\n`);
} else {
Expand Down
4 changes: 4 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ yargs
type: 'boolean',
description: 'Only output errors to CLI',
})
.option('noLogFile', {
type: 'boolean',
description: 'Only output log to CLI but not to files',
})
.option('skipInteraction', {
alias: ['yes', 'y'],
description: 'Interactive questions where possible and go with defaults instead',
Expand Down
27 changes: 23 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Mcdev {
'json',
'refresh',
'skipInteraction',
'noLogFile',
];
for (const option of knownOptions) {
if (argv[option] !== undefined) {
Expand Down Expand Up @@ -89,6 +90,7 @@ class Mcdev {
* @returns {Promise.<TYPE.DeltaPkgItem[]>} list of changed items
*/
static async createDeltaPkg(argv) {
Util.startLogger();
Util.logger.info('Create Delta Package ::');
const properties = await config.getProperties();
if (!(await config.checkProperties(properties))) {
Expand All @@ -111,6 +113,7 @@ class Mcdev {
* @returns {Promise} .
*/
static async selectTypes() {
Util.startLogger();
const properties = await config.getProperties();
if (!(await config.checkProperties(properties))) {
return null;
Expand All @@ -127,6 +130,7 @@ class Mcdev {
* @returns {Promise.<boolean>} success flag
*/
static async upgrade() {
Util.startLogger();
const properties = await config.getProperties();
if (!properties) {
Util.logger.error('No config found. Please run mcdev init');
Expand All @@ -149,6 +153,7 @@ class Mcdev {
* @returns {Promise.<object>} -
*/
static async retrieve(businessUnit, selectedTypesArr, keys, changelogOnly) {
Util.startLogger();
Util.logger.info('mcdev:: Retrieve');
const properties = await config.getProperties();
if (!(await config.checkProperties(properties))) {
Expand Down Expand Up @@ -176,7 +181,7 @@ class Mcdev {
for (const bu in properties.credentials[cred].businessUnits) {
await this._retrieveBU(cred, bu, selectedTypesArr, keys);
counter_credBu++;
Util.restartLogger();
Util.startLogger(true);
}
counter_credTotal += counter_credBu;
Util.logger.info(`\n :: ${counter_credBu} BUs for ${cred}\n`);
Expand Down Expand Up @@ -210,7 +215,7 @@ class Mcdev {
for (const bu in properties.credentials[cred].businessUnits) {
await this._retrieveBU(cred, bu, selectedTypesArr, keys);
counter_credBu++;
Util.restartLogger();
Util.startLogger(true);
}
Util.logger.info(`\n :: ${counter_credBu} BUs for ${cred}\n`);
} else {
Expand Down Expand Up @@ -351,6 +356,7 @@ class Mcdev {
* @returns {Promise.<Object.<string,TYPE.MultiMetadataTypeMap>>} deployed metadata per BU (first key: bu name, second key: metadata type)
*/
static async deploy(businessUnit, selectedTypesArr, keyArr, fromRetrieve = false) {
Util.startLogger();
return Deployer.deploy(businessUnit, selectedTypesArr, keyArr, fromRetrieve);
}

Expand All @@ -361,6 +367,7 @@ class Mcdev {
* @returns {Promise.<void>} -
*/
static async initProject(credentialsName) {
Util.startLogger();
Util.logger.info('mcdev:: Setting up project');
const properties = await config.getProperties(!!credentialsName, true);
await Init.initProject(properties, credentialsName);
Expand All @@ -371,6 +378,7 @@ class Mcdev {
* @returns {Promise.<void>} -
*/
static async joinProject() {
Util.startLogger();
Util.logger.info('mcdev:: Joining an existing project');
await Init.joinProject();
}
Expand All @@ -382,6 +390,7 @@ class Mcdev {
* @returns {Promise.<void>} -
*/
static async findBUs(credentialsName) {
Util.startLogger();
Util.logger.info('mcdev:: Load BUs');
const properties = await config.getProperties();
if (!(await config.checkProperties(properties))) {
Expand All @@ -401,6 +410,7 @@ class Mcdev {
* @returns {Promise.<void>} -
*/
static async document(businessUnit, type) {
Util.startLogger();
Util.logger.info('mcdev:: Document');
const properties = await config.getProperties();
if (!(await config.checkProperties(properties))) {
Expand Down Expand Up @@ -440,6 +450,7 @@ class Mcdev {
* @returns {Promise.<boolean>} true if successful, false otherwise
*/
static async deleteByKey(businessUnit, type, customerKey) {
Util.startLogger();
Util.logger.info('mcdev:: delete');
if (!Util._isValidType(type)) {
return;
Expand Down Expand Up @@ -477,6 +488,7 @@ class Mcdev {
* @returns {Promise.<void>} -
*/
static async refresh(businessUnit, type, keyArr) {
Util.startLogger();
Util.logger.info('mcdev:: refresh');
if (!type || !Util._isValidType(type, true)) {
type = 'triggeredSend';
Expand Down Expand Up @@ -512,6 +524,7 @@ class Mcdev {
* @returns {Promise.<void>} -
*/
static async badKeys(businessUnit) {
Util.startLogger();
const properties = await config.getProperties();
if (!(await config.checkProperties(properties))) {
return null;
Expand Down Expand Up @@ -585,6 +598,7 @@ class Mcdev {
* @returns {Promise.<TYPE.MultiMetadataTypeList>} -
*/
static async retrieveAsTemplate(businessUnit, selectedType, name, market) {
Util.startLogger();
Util.logger.info('mcdev:: Retrieve as Template');
const properties = await config.getProperties();
if (!(await config.checkProperties(properties))) {
Expand Down Expand Up @@ -626,6 +640,7 @@ class Mcdev {
* @returns {Promise.<TYPE.MultiMetadataTypeList>} -
*/
static async buildTemplate(businessUnit, selectedType, keyArr, market) {
Util.startLogger();
Util.logger.info('mcdev:: Build Template from retrieved files');
return Builder.buildTemplate(businessUnit, selectedType, keyArr, market);
}
Expand All @@ -639,6 +654,7 @@ class Mcdev {
* @returns {Promise.<void>} -
*/
static async buildDefinition(businessUnit, selectedType, name, market) {
Util.startLogger();
Util.logger.info('mcdev:: Build Definition from Template');
return Builder.buildDefinition(businessUnit, selectedType, name, market);
}
Expand All @@ -652,6 +668,7 @@ class Mcdev {
* @returns {Promise.<void>} -
*/
static async buildDefinitionBulk(listName, type, name) {
Util.startLogger();
Util.logger.info('mcdev:: Build Definition from Template Bulk');
return Builder.buildDefinitionBulk(listName, type, name);
}
Expand All @@ -663,6 +680,7 @@ class Mcdev {
* @returns {Promise.<string[]>} list of all files that need to be committed in a flat array ['path/file1.ext', 'path/file2.ext']
*/
static async getFilesToCommit(businessUnit, selectedType, keyArr) {
Util.startLogger();
Util.logger.info('mcdev:: getFilesToCommit');
const properties = await config.getProperties();
if (!(await config.checkProperties(properties))) {
Expand Down Expand Up @@ -691,6 +709,7 @@ class Mcdev {
* @returns {Promise.<boolean>} true if all started successfully, false if not
*/
static async execute(businessUnit, selectedTypesArr, keys) {
Util.startLogger();
Util.logger.info('mcdev:: Execute');
const properties = await config.getProperties();
let counter_credBu = 0;
Expand Down Expand Up @@ -723,7 +742,7 @@ class Mcdev {
} else {
counter_failed++;
}
Util.restartLogger();
Util.startLogger(true);
}
counter_credTotal += counter_credBu;
Util.logger.info(
Expand Down Expand Up @@ -763,7 +782,7 @@ class Mcdev {
} else {
counter_failed++;
}
Util.restartLogger();
Util.startLogger(true);
}
Util.logger.info(
`\n :: Executed the entity on ${counter_credBu} BUs for ${cred}\n`
Expand Down
Loading

0 comments on commit 247752a

Please sign in to comment.