js-console-wrapper


Wrapper for console calls in JavaScript

Due to Google Code shutting down in early 2016 this project has been moved to GitHub: https://github.com/martindsouza/js-console-wrapperhttps://github.com/martindsouza/js-console-wrapper

Console Wrapper

  • Introduction
    • Demo
  • Setup
    • Download
  • Instructions
    • APEX Integration
  • Additional Resources
  • Change Log

Introduction

Console is a command in JavaScript (JS). It allows you to print objects to the console window to assist with debugging your JS code. Console is available in most browsers except IE. Since it is not accessible in IE, developers have to remove it each time they want to move their code into production since most web applications will have some IE clients.

The console wrapper resolves the following issues: * Will not raise an error if run in IE (null op run) * Can toggle console output via the Levels option * Tight integration with Integration Oracle Application Express (APEX)

If you want some more information about console and its capabilities please see the Additional Resources section below.

Console wrapper is developed by Martin Giffy D'Souza.

Demo

You can view some of the console wrapper functions here: http://apex.oracle.com/pls/apex/f?p=16406:1200:0

Setup

The console wrapper leverages jQuery. To load the console wrapper include both jQuery and the $console_wrapper.js file:

```

```

Download

You can download the latest release of $console_wrapper.js: * $console_wrapper.js. * Demo

Instructions

Levels

The console wrapper allows you to control the type of messages that are displayed in the console window. There's a hierarchy of levels that control this. They are:

  • exception
  • error
  • warn
  • info
  • log / debug
  • off

If you set the level to be info all info and above (warn, error, exception) messages will be displayed. By default the initial level is set to off which means no messages will be displayed on the console window (this is slightly different if used in an APEX application, see APEX Integration). You can change the logging level by using the setLevel function:

//Enable logging mode $.console.setLevel('log');

If you want to see the current level for the console wrapper you can use the getLevel command:

//Get current level (text) $.console.getLevel();

jQuery Chained Logging

Since the console wrapper uses jQuery you can leverage jQuery's chaining capabilities as shown in the following example:

//This assumes you have some tag with a class of "red". //For example <span class="red">some text</span> //This will log something, change the color of the text to red, then log something else //The main advantage is that it's all done in one line. $('.red').log('Before Red').css({color:'red'}).log('After Red');

When chaining in jQuery it only accepts the .log() function. If you want to display a different type of message set the first parameter in as the type you want. For example:

//This is based on the previous example except that it will be a info message instead of a log message $('.red').log('info','Before Red').css({color:'red'}).log('info','After Red');

Log Parameters

You may want to log all the parameters that are passed into a function. The logParams function will log all the parameters that were passed into the function along with the variable they were assigned to. For unassigned parameters "unassigned" will appear. The following example highlights how to use the logParams function.

``` function myFn(pA, pB){ $.console.logParams(); //do something as part of function }//myFn

//Run myFn myFn(1,2,3); ```

The output from this is: Parameters (this is grouped) pA: 1 pB: 2 unassigned: 3

The logParams function takes an optional pOptions JSON object. This object supports the following options:

  • createGroup boolean If true a group will be created (and closed appropriately). Default: true.
  • groupCollapsed boolean If createGroup is true, this determines if the group is collapased or not. Default: true.
  • groupText string If create group is true, this will be the name of the group. Default: "Parameters"

APEX Integration

The console wrapper was originally designed for Oracle APEX applications. If implemented as part of an APEX application the documentation above is correct except for the following points:

  • Setup: You do not need to include the jQuery file as it is already included in APEX 4.0 and above
  • Levels: In APEX if you are in debug mode the console wrapper will default to the "log" level.

Additional Resources

Change Log

Project Information

Labels:
JavaScript Console apex oracleapex