Skip to content

Commit

Permalink
Allow arbitrary objects to be logged to console (this will allow circ…
Browse files Browse the repository at this point in the history
…ular objects to be parsed) (#55)
  • Loading branch information
dbfannin authored Apr 4, 2018
1 parent 94f5bf2 commit 36196c1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-logger",
"version": "2.1.0",
"version": "2.1.1",
"scripts": {
"build": "gulp build",
"build:watch": "gulp",
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {CustomNGXLoggerService} from './custom-logger.service';
export * from './custom-logger.service';
export * from './custom-logger.service.mock';


import {NGXLoggerHttpService} from './http.service';
export * from './http.service';
export * from './http.service.mock';
Expand Down
12 changes: 9 additions & 3 deletions src/logger.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ export class NGXLogger {

return additional.map((next, idx) => {
try {
return typeof next === 'object' ? JSON.stringify(next, null, 2) : next;
// We just want to make sure the JSON can be parsed, we do not want to actually change the type
if (typeof next === 'object') {
JSON.stringify(next)
}

return next;
}
catch (e) {
return `The additional[${idx}] value could not be parsed using JSON.stringify().`
Expand All @@ -119,14 +124,15 @@ export class NGXLogger {

message = this._prepareMessage(message);

additional = this._prepareAdditionalParameters(additional);
// only use validated parameters for HTTP requests
const validatedAdditionalParameters = this._prepareAdditionalParameters(additional);

const timestamp = new Date().toISOString();
const config = this.configService.getConfig();

if (logOnServer && config.serverLoggingUrl && level >= config.serverLogLevel) {
// Allow logging on server even if client log level is off
this.httpService.logOnServer(config.serverLoggingUrl, message, additional, timestamp, logLevelString).subscribe((res: any) => {
this.httpService.logOnServer(config.serverLoggingUrl, message, validatedAdditionalParameters, timestamp, logLevelString).subscribe((res: any) => {
// I don't think we should do anything on success
},
(error: HttpErrorResponse) => {
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-logger",
"version": "2.1.0",
"version": "2.1.1",
"repository": {
"type": "git",
"url": "https://github.com/dbfannin/ngx-logger"
Expand Down

0 comments on commit 36196c1

Please sign in to comment.