Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arbitrary objects #55

Merged
merged 1 commit into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this actually cause a schema change for the output of the information logged to the server? If I remember correctly, the message that is created from this parser is always a string, which might cause problems for anyone trying to use it.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't change the message (which is correct that it is always a string). The additional is an any[], so I think we'll be fine there. I think we want to keep the type of the logged additional, but still verify it is valid.

}
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