Skip to content

10. Log (pL.js)

Pimp Trizkit edited this page Mar 10, 2018 · 9 revisions
<< Previous        Back to Table of Contents        Next >>

    "It's Log!" - Ren & Stimpy

Dependency pLS

This will log to the console messages and objects. There is a global data array pLS (length 3) that is added which stores your logging settings. Change your settings here. The first item of the array is a boolean to turn on or off the logging. The second item is the name of the app/script to display in the console, set to "" if undesired. And the last item in the array is a boolean to determine if a timestamp should be placed before the message (but after the app/script name).

If the optional object is used, it will be on a separate line. Some browsers like this better. And older browsers might not support pushing an object to the console very well, or at all.

Code:

const pLS=[true,"appNameVersion",true];
const pL=(m,o)=>{if(pLS[0]){console.log(pLS[1]+" "+(pLS[2]?"("+(new Date()).toLocaleString()+")":"")+" > "+m);if(o)console.log(o);}}

Usage:

pL("Hello World!");  // Standard log using optional settings in `pLS`.
pL("Hello FooBar World",foobar);  // Same as above but a second line will be used for foobar.

Return:

Nothing, unless your looking at the console.

Params:

Keep in mind, the actual logging settings are set in pLS before runtime.

pL(m,o)

m = < Message String > * REQUIRED

  • The string to display to the console.

o = < Object > Optional

  • An optional object to display in the console. This will be displayed on a separate line which sometimes displays better in various browsers, but otherwise about the same in the rest.
  • Older browsers might not support pushing an object to the console very well; this helps clean them up. Older still... and they might not support it at all; they could crash in the console regardless.

Clone this wiki locally