Skip to content

Stop printing logs in the console just by calling a function. You can also record the logs and view it later.

Notifications You must be signed in to change notification settings

Sujsun/ConsoleControl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

#ConsoleControl for Javascript

Intro

  • Enable or disable logs by calling ConsoleControl.enable();/ConsoleControl.disable();
  • Record logs by calling ConsoleControl.record(true);
  • To print the recorded logs use ConsoleControl.print();
  • Recorded logs will be printed along with file name and line number.

Installation

Just include ConsoleControl.js file in your page.

Eg:

<script src="/js/ConsoleControl.js"></script>

And start using it.

Code Example

To enable or disable logs

console.log('1. WILL BE PRINTED');          // This will be printed

ConsoleControl.disable();                   // Disabling logs
console.log('2. WILL NOT BE PRINTED');      // This will NOT be printed

ConsoleControl.enable();                    // Enabling the logs back
console.log('3. WILL BE PRINTED');          // This will be printed

To record logs

ConsoleControl.record(true);                // Enabling record logs
console.log('1. RECORDED');                 // This will be recorded

ConsoleControl.record(false);               // Disabling record logs
console.log('2. NOT RECORDED');             // This will NOT be recorded

ConsoleControl.print(); 	                // Prints the recorded log

To disable logs and record

ConsoleControl.disable({record: true}); 	// Disabling logs and enabling the record logs
console.log('1. RECORDED');         		// This will be recorded

ConsoleControl.print(); 	        		// Prints the recorded log

Doc

Methods Description Arguments Argument Value
ConsoleControl.enable(<options>) Enable logs options {record: true/false}
ConsoleControl.disable(<options>) Disable logs options {record: true/false}
ConsoleControl.record(<recordFlag>) Sets the record status *recordFlag true/false
ConsoleControl.print() Prints the recorded logs along with file name and line number
ConsoleControl.logs() Returs the recorded logs as JSON
ConsoleControl.eraseLogs() Erases the recorded logs
ConsoleControl.reset() Resets the plugin
ConsoleControl.version() Returns the version of plugin

Motivation

  • In production evironment, no developer want to leak their logs in browser console but still they love to capture the logs silently for debugging.
  • This plugin helps the developers to stop printing the logs in broswer console and to record logs silently.

Eg:

var environment = 'production';

if(environment === 'production') {
	ConsoleControl.disable({record: true}); 	// Disabling logs and enabling the record logs
}

And later if you need logs, you can get by...

ConsoleControl.print();                         // Prints the recorded log

Or

ConsoleControl.logs();                          // Returns the recorded logs as JSON

Contributors

  • Sundarasan Natarajan
  • You, if you are interested

About

Stop printing logs in the console just by calling a function. You can also record the logs and view it later.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published