src/lib/json-layout.model.ts
Formats a logging event into JavaScript Object Notation (JSON). The implemenatation is mainly the same as with log4javascript.JsonLayout, with an improvement of serializing messages containing '"'."
Methods |
| Public format | ||||||
format(loggingEvent: LoggingEvent)
|
||||||
|
Defined in src/lib/json-layout.model.ts:14
|
||||||
|
Formats the log message.
Parameters :
Returns :
string
|
| Public toString |
toString()
|
|
Defined in src/lib/json-layout.model.ts:30
|
|
Gets the layout's name. Mainly for unit testing purposes.
Returns :
string
layout's name |
import * as log4javascript from "log4javascript";
import { LoggingEvent } from "log4javascript";
/**
* Formats a logging event into JavaScript Object Notation (JSON).
* The implemenatation is mainly the same as with log4javascript.JsonLayout,
* with an improvement of serializing messages containing '\"'."
*/
export class JsonLayout extends log4javascript.JsonLayout {
/**
* Formats the log message.
*/
public format(loggingEvent: LoggingEvent): string {
const eventObj = {
logger: loggingEvent.logger.name,
timestamp: loggingEvent.timeStampInMilliseconds,
level: loggingEvent.level.toString(),
url: window.location.href,
message: this.isCombinedMessages() ? loggingEvent.getCombinedMessages() : loggingEvent.messages
};
return JSON.stringify(eventObj);
}
/**
* Gets the layout's name.
* Mainly for unit testing purposes.
* @return layout's name
*/
public toString(): string {
return "Ionic.Logging.JsonLayout";
}
}