Skip to main content

D2SV client to server logging

D2SV UI uses log4javascript to enable logging for UI components. By default, the library is configured to channel log output to web browser console. In the past while debugging for some issue in D2 Smartview, we felt the need to correlate this client-side log output with server-side log output generated by back-end components and usually saved in "D2-Smartview.log" file. Driven by this need, we've created this sample plugin which re-configures the log4javascript and channels the log output to the same server-side log file. Key concepts explored in this plugin are

  • REST endpoint with un-conventional input/output.
  • RequireJS module re-configuration

Instruction to try out the sample

  • Build the plugin using npm run build from SDK workspace root.
  • Copy D2SV-Client2Server-Logging-1.0.0.jar from "dist" folder in workspace root and paste it inside WEB-INF/lib folder of a deployed D2 Smartview application.
  • Edit D2 Smartview logging configuration file logback.xml from WEB-INF/classes folder and set the root logging level to INFO.
  • Edit rest-api-runtime.properties from WEB-INF/classes folder and add/append pattern /clientlog to the value of property rest.security.anonymous.url.patterns.
  • Restart application server on which D2 Smartview is deployed.
  • Reload D2-Smartview application in web-browser with additional query parameter loglevel=info.
    tip

    Complete URL might look like https://mydomain.com/D2-Smartview/ui?loglevel=info#d2

  • Open console for the web-browser and check if some INFO level log output is present.
  • On the server-side open D2-Smartview.log file and search for the same log statements as from web-browser console.

Source code structure

D2SV-Client2Server-Logging
|
| pom.xml
|
+---src
| \---main
| +---java
| | \---com
| | +---emc
| | | D2PluginVersion.java
| | |
| | \---opentext
| | \---d2
| | +---rest
| | | \---context
| | | \---jc
| | | PluginRestConfig_C2SLogging.java
| | |
| | \---smartview
| | \---c2slogging
| | | C2SLoggingPlugin.java
| | |
| | +---api
| | | C2SLoggingVersion.java
| | |
| | \---rest
| | | package-info.java
| | |
| | +---api
| | | | IClientLogManager.java
| | | |
| | | \---impl
| | | ClientLogManager.java
| | |
| | +---controller
| | | InboundExternalLogController.java
| | |
| | \---model
| | HelpModel.java
| | LogEntry.java
| | LogLevel.java
| | LogRequest.java
| |
| +---resources
| | | c2slogging-version.properties
| | | D2Plugin.properties
| | |
| | \---smartview
| | SmartView.properties
| |
| \---smartview
| | .csslintrc
| | .eslintrc-html.yml
| | .eslintrc.yml
| | .npmrc
| | c2slogging.setup.js
| | config-editor.js
| | Gruntfile.js
| | package.json
| | server.conf.js
| |
| +---src
| | | c2slogging-extensions.json
| | | c2slogging-init.js
| | | component.js
| | | config-build.js
| | | Gruntfile.js
| | |
| | +---bundles
| | | c2slogging-bundle.js
| | |
| | +---test
| | | extensions.spec.js
| | |
| | \---utils
| | | startup.js
| | |
| | \---theme
| | | action.icons.js
| | |
| | \---action_icons
| | action_sample_icon.svg
| |
| \---test
| Gruntfile.js
| karma.conf.js
|
\---target

Files and their purpose

Following are the list of function oriented source files and their purpose. Other source files present within the plugin are part of common infrastructure code and explained in Understanding D2SV plugin project.

REST Controller
  • src/main/java/com/opentext/d2/rest/context/jc/PluginRestConfig_C2SLogging.java - Declares Spring Bean IClientLogManager through ClientLogManager.
  • src/main/java/com/opentext/d2/smartview/c2slogging/rest/api/IClientLogManager.java - Declares log manager interface for REST controllers to use.
  • src/main/java/com/opentext/d2/smartview/c2slogging/rest/api/impl/ClientLogManager.java - Log manager implementation that parses and maps input log statements and relays those statements into server side log.
  • src/main/java/com/opentext/d2/smartview/c2slogging/rest/controller/InboundExternalLogController.java - Defines two REST endpoints, one receives HTTP POST request with log statements as part of request body, the other responds to HTTP GET requests with help information on how to use the first endpoint.
  • src/main/java/com/opentext/d2/smartview/c2slogging/rest/model/HelpModel.java - Serializable POJO that holds help information.
  • src/main/java/com/opentext/d2/smartview/c2slogging/rest/model/LogEntry.java - Serializable POJO that represents a single log statement.
  • src/main/java/com/opentext/d2/smartview/c2slogging/rest/model/LogLevel.java - Enum that represents D2SV client-side log levels.
  • src/main/java/com/opentext/d2/smartview/c2slogging/rest/model/LogRequest.java - Serializable POJO that holds a bunch of log statements together.
RequireJS module configuration
  • src/main/smartview/src/c2slogging-init.js - This file is used to re-configure module nuc/utils/log so that it channels log statements to the endpoint created by Java code from above. It also configures nuc/lib/log4javascript to customize the request body format sent to the REST endpoint.
    info

    The module nuc/utils/log encapsulates the log4javascript library and provides managed logging API to D2SV UI components.