top of page

CEL: JavaScript Log Window

ABSTRACT (by Federico Levis ) Category: CEL

Cognos Extension Library (CEL) Feature: Window to Log from RS JS or from whatever JS Code (inside HTML Page, Web Application, ...):

Feature Description

CEL contains 3 js (jslog.js, json2.js, dom-drag.js) that implement JS LOG feature: using them it is very simply

  • to log from your JS code into an optional JS Window with different LOG Level (enable/disable by Bitmask) and flexible options (Log string, Object, JSON,....).

  • enable/disable JSLOG Window: when it si not displayed (Level=0) there is no meaningful delay in JS code execution, due to the extra jslog instructions.

CEL JSLOG can be used to log from JS code in whatever context, Cognos RS or HTML or WEB application.

1) Example: JSLOG from the JS of an HTML Page

a) include the 3 CEL JS highlighted below:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <body bgcolor="#ffffff">

<script type="text/javascript" src="dom-drag.js"></script> <script type="text/javascript" src="jslog.js"></script> <script type="text/javascript" src="json2.js"></script>

b) init js with jslog_init (jslogLevel)

jslogLev is the desired Level, a BitMask with whatever Level you want to use:

var JSLOG_ERR = 0; // Always Enabled when jslog is displayed var JSLOG_INFO = 1; var JSLOG_DEBUG = 2; var JSLOG_TEST = 4; var JSLOG_DUMP = 8;

Examples:

// enable JSLOG_INFO and JSLOG_DEBUG

jslog_init (3);

// enable only JSLOG_TEST

jslog_init (4);

// disable JSLOG Window, that is not disaplyed

jslog_init (0);

NOTE: you can init jslog with an optionl URL parameter

c) In your JS code you can use the jslog API

// Log whatever strimg

jslog (iLev,szMsg);

//log Object

jslogObj (iLev,szMsg,obj);

// Log JSON

jslogJson (iLev,szMsg,json);

Example

IN our HTML page we call 3 function with different jsLevel:

function jslog1() { var szFirstName = "Federico"; jslog(JSLOG_INFO,"This a Log at Level 1. My name is " + szFirstName); } function jslog2() { var author = new Object(); author.szFirstName= "Federico"; author.szLastName = "Levis"; author.szCity = "Padova"; author.szNation = "Italy"; jslogObj(JSLOG_DEBUG,"Log at Level 2 of a JS Object. author:", author); } function jslog4() { var jsonEx = {"total":5,"rows":[ {"giorno_rif":"21/04/2015","data_elab":"20/05/2015 05:00:08","durata_elab_sec":15,"err_num":7}, {"giorno_rif":"22/04/2015","data_elab":"20/05/2015 05:00:05","durata_elab_sec":0,"err_num":1}, {"giorno_rif":"23/04/2015","data_elab":"20/05/2015 05:00:01","durata_elab_sec":3,"err_num":3}, {"giorno_rif":"24/04/2015","data_elab":"20/05/2015 05:00:13","durata_elab_sec":3,"err_num":2}, {"giorno_rif":"25/04/2015","data_elab":"20/05/2015 05:00:16","durata_elab_sec":3,"err_num":14} ]}; jslogJson(JSLOG_TEST,"Log at Level 2 of a JS Object. jsonEx:", jsonEx); }

Follow the result when we have started jslog with

jslog_start (7)

All the Levels are enabled and everything is logged:

Follow the result when we have started jslog with

jslog_start (2)

Only JSLOG_DEBUG is enabled and logged:

Follow the result when we have started jslog with

jslog_start (0)

The JSLOG Window is not disaplyed and nothing is logged

2) JS LOG within Cognos RS

Prerequisite: Cognos Extension Library (CEL) is installed and included in your Report

Log Window can be Created in 2 ways:

a) Adding to Report URI the Parameter p_jslog

p_jslog=jsLogLev

e.g p_jslog=7 to enable Level 1, 2 and 4

b) Adding in your RS Code a prompt Value with name=_jslog (the value is used as jsLogLev)

  • From JS Code it is possible to Log with CEL API as described in previous Point 1

bottom of page