Skip to content

Commit b6ebf27

Browse files
authored
Fix logs (#52)
1 parent 4922f58 commit b6ebf27

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 1.1.7 (August 18, 2021)
22
* Migrate from `request` to `axios` as main lib
33
* Keep alive connection by default
4+
* Reduce logging level to trace
45

56
## 1.1.6 (July 29, 2021)
67
* Now `getAttachment` from `AttachmentProcessor` may retrieve items from `Maester`

lib/authentication/CookieRestClient.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class CookieRestClient extends NoAuthRestClient {
3636
}
3737

3838
async login() {
39-
this.emitter.logger.info('Performing Login ...');
39+
this.emitter.logger.trace('Performing Login ...');
4040
const loginResponse = await this.requestCall({
4141
method: 'POST',
4242
url: this.cfg.loginUrl,
@@ -55,12 +55,12 @@ export class CookieRestClient extends NoAuthRestClient {
5555

5656
this.handleLoginResponse(loginResponse);
5757
this.loggedIn = true;
58-
this.emitter.logger.info('Login Complete.');
58+
this.emitter.logger.trace('Login Complete.');
5959
}
6060

6161
async logout() {
6262
if (this.cfg.logoutUrl && this.loggedIn) {
63-
this.emitter.logger.info('Performing Logout...');
63+
this.emitter.logger.trace('Performing Logout...');
6464
const logoutResponse = await this.requestCall({
6565
method: this.cfg.logoutMethod,
6666
url: this.cfg.logoutUrl,
@@ -71,9 +71,9 @@ export class CookieRestClient extends NoAuthRestClient {
7171
});
7272
this.handleLogoutResponse(logoutResponse);
7373
this.loggedIn = false;
74-
this.emitter.logger.info('Logout complete.');
74+
this.emitter.logger.trace('Logout complete.');
7575
} else {
76-
this.emitter.logger.info('Nothing to logout');
76+
this.emitter.logger.trace('Nothing to logout');
7777
}
7878
}
7979

lib/authentication/NoAuthRestClient.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class NoAuthRestClient {
2828
throw new Error(`Error in making request to ${response.config.url}/ Status code: ${response.statusCode}, Body: ${JSON.stringify(response.body)}`);
2929
}
3030

31-
this.emitter.logger.debug(`Response statusCode: ${response.statusCode}`);
31+
this.emitter.logger.trace(`Response statusCode: ${response.statusCode}`);
3232
return response.body;
3333
}
3434

@@ -41,18 +41,25 @@ export class NoAuthRestClient {
4141
// if the provided URL is an absolute path. Defaults to true
4242
async makeRequest(options) {
4343
const {
44-
url, method, body, headers = {}, urlIsSegment = true, isJson = true, responseHandler, axiosOptions = {},
44+
axiosOptions = {},
45+
body,
46+
headers = {},
47+
isJson = true,
48+
method,
49+
responseHandler,
50+
url,
51+
urlIsSegment = true,
4552
} = options;
4653
const urlToCall = urlIsSegment
4754
? `${removeTrailingSlash(this.cfg.resourceServerUrl.trim())}/${removeLeadingSlash(url.trim())}` // Trim trailing or leading '/'
4855
: url.trim();
4956

50-
this.emitter.logger.debug(`Making ${method} request...`);
57+
this.emitter.logger.trace(`Making ${method} request...`);
5158

5259
const requestOptions = {
5360
...axiosOptions,
54-
method,
5561
headers,
62+
method,
5663
data: body,
5764
url: urlToCall,
5865
};

lib/authentication/OAuth2AuthorizationCodeRestClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const request = promisify(require('request'));
55

66
export class OAuth2RestClient extends NoAuthRestClient {
77
private async fetchNewToken() {
8-
this.emitter.logger.info('Fetching new token...');
8+
this.emitter.logger.trace('Fetching new token...');
99
const authTokenResponse = await request({
1010
uri: this.cfg.authorizationServerTokenEndpointUrl,
1111
method: 'POST',
@@ -21,7 +21,7 @@ export class OAuth2RestClient extends NoAuthRestClient {
2121
},
2222
});
2323

24-
this.emitter.logger.info('New token fetched...');
24+
this.emitter.logger.trace('New token fetched...');
2525

2626
if (authTokenResponse.statusCode >= 400) {
2727
throw new Error(`Error in authentication. Status code: ${authTokenResponse.statusCode}, Body: ${JSON.stringify(authTokenResponse.body)}`);
@@ -37,7 +37,7 @@ export class OAuth2RestClient extends NoAuthRestClient {
3737
const tokenExpiryTime = new Date(this.cfg.oauth2.tokenExpiryTime);
3838
const now = new Date();
3939
if (now < tokenExpiryTime) {
40-
this.emitter.logger.info('Previously valid token found.');
40+
this.emitter.logger.trace('Previously valid token found.');
4141
return this.cfg.oauth2.access_token;
4242
}
4343

0 commit comments

Comments
 (0)