loupe-typescript
v1.2.1
Published
Loupe Agent for Web clients
Downloads
53
Maintainers
Readme
loupe-typescript
loupe-typescript is a Loupe Agent for web browser applications.
The agent will hook into the window.onerror event to automatically log any uncaught JavaScript errors.
Use of the agent needs to be combined with a server component to correlate the actions your user performs client side with the corresponding server side processing, giving you a better insight into end to end functionality. See the project readme for more details.
Installation
You can install the module via npm:
API
critical(category: string, caption: string, description: string, parameters?: any[] | null, exception?: any | null, details?: any | null, methodSourceInfo?: * MethodSourceInfo | null) - write a categorized Crticial message to Loupe.
error(category: string, caption: string, description: string, parameters?: any[] | null, exception?: any | null, details?: any | null, methodSourceInfo?: * MethodSourceInfo | null) - write a categorized Error message to Loupe.
information(category: string, caption: string, description: string, parameters?: any[] | null, exception?: any | null, details?: any | null, methodSourceInfo?: MethodSourceInfo | null) - write a categorized Information message to Loupe.
warning(category: string, caption: string, description: string, parameters?: any[] | null, exception?: any | null, details?: any | null, methodSourceInfo?: * MethodSourceInfo | null) - write a categorized Warning message to Loupe.
verbose(category: string, caption: string, description: string, parameters?: any[] | null, exception?: any | null, details?: any | null, methodSourceInfo?:MethodSourceInfo | null) - write a categorized Verbose message to Loupe.
write(severity: LogMessageSeverity, category: string, caption: string, description: string, parameters?: any[] | null, exception?: any | null, details?: any |null, methodSourceInfo?: MethodSourceInfo | null) - write a categorized message to Loupe.
setSessionId(value: string) - set the client session id.
setCORSOrigin(value: string | null) - set the target endpoint for log message. If not set, the current host is used with the default log point of /Loupe/Log.
setAuthorizationHeader(header: Header) - sets the Authorization header to send when logging to Loupe.
clientSessionHeader() - gets the Header used as the agent session id.
resetMessageInterval(interval: number) - resets the interval used to batch up and send messages. This interval starts at 10 milliseconds and increases if there are failures to send; messages are stored in the browser local storage and resent in order when communication is restored.
addSendMessageCommandToEventQueue() - immediately send any queued messages.
The critical, error, information, warning and verbose methods are all convenience wrappers over the critical method. For these, the parameters are:
- category - The application subsystem or logging category that the log message is associated with, which supports a dot-delimited hierarchy (eg the logger name).
- caption - A simple single-line message caption. (Will not be processed for formatting).
- description - Additional multi-line descriptive message (or may be null) which can be a format string followed by corresponding args.
- parameters - Optional. A variable number of arguments referenced by the formatted description string (or no arguments to skip formatting).
- exception - Optional. The error details. This can be a string detailing the exception, an Exception object, or a JavaScript Error object.
- details - Optional. A JSON object, or string version of, with additional details to be logged and shown in the details in Loupe Desktop and Loupe Server. This is useful for passing context information or state information that could be useful for diagnostics.
- methodSourceInfo - Optional. Details of the file, method, line and column number. This allows source information to be passed without the performance overhead of working out the current file and line (eg by examining the stack, which may well be different with compressed source, especially if source maps are not being used).
Examples
The first step to using Loupe is to create an instance of the agent, passing in the window and document objects:
Next, set an id for the client session. The id can be any unique number, but we recommend a guid:
If your server project is hosted on a different domain or port, then you'll need to set the target:
Next, start logging:
The description supports C# style string formatting parameters, which should be passed as an array in parameters. For example:
For errors and additional details you can use:
The additional details parameter cab be either a string or a JSON object.
To addition source information you can use the MethodSourceInfo:
For me examples, see the sample project.
Dependencies
- stacktrace-js for stack trace handling for uncaught window errors.
- platform for obtaining platform details fo the client
License
This module is licensed under ...