├── .gitignore ├── .npmignore ├── .nvmrc ├── .travis.yml ├── LICENSE ├── README.md ├── README.pics ├── console++-1.png └── console++-2.png ├── console++.js ├── package-lock.json ├── package.json └── test └── basic_test.js /.gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | 10 | pids 11 | logs 12 | results 13 | 14 | npm-debug.log 15 | 16 | .idea/ -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | *.png 2 | 3 | test/ 4 | 5 | .travis.yml -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | lts/* -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 'node' 4 | - 'lts/*' 5 | - '14' 6 | - '12' 7 | - '8' 8 | deploy: 9 | provider: npm 10 | skip_cleanup: true 11 | 12 | # Publishing conditions 13 | on: 14 | tags: true 15 | repo: detro/consoleplusplus 16 | node: 'lts/*' 17 | 18 | # Authentication 19 | email: detronizator@gmail.com 20 | api_key: 21 | secure: BZiBrV/jGEQ4LInefVzta1XWWirVfYletvaMvTcLfhJzBmTsOIdI9w8B/6btXOxTvZoqkztFxc5j/v0M77G9h149HdnFiOpLuuzFDP9zGlYkQBEF9Tz56Z3KvIFh67Av3oqMf83tSEdJbiF4dYgUvIqLXkzvIb+v6Ne8S1NE4DzArxf03fZU8gbPgdW37qPRjiWqNdKbZH/PPGtw7JStAlSrvR2RaTPGOxTTJkeLVRWnK5vbVb0TShGYHj2ki/86zaiyG4B0JKLQenKt81KTFCwJdNAz/qCwT0fOEhgl7rutlx6pvekvBtuYERKZXxZmb9+pTbBX+0P+45mWn2DNUYMGizhnMADQrU1gidZWJUJGHqkctKIn6MM9u/+t+gA7i66JsjW53ZT/1xcA3FnyvoJNUejzPy4ljLGW30wn4fOUQ9g1J+p1reuMtFCgtlIz5JoRnb30XxoFyhPDts/YeWULGlYdm/4KSNpICOX/ZHMx9S86qUjc2bDnqQdE5TV+PFcvLCuds7zWqj/dhhOSInbRWbByxOqpEpATKrGuKJeyOiQRcCIIo79vlt79c8REft7mUb/NLETmSCURIXZDFnefVLl/xfA437eGmN99aEEFW+UjQY0RG43ArQGm7UHycSAz0UgUADFxhoXeJuzPcjAMOMns69ZAUzfzu+xfpco= 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2021, Ivan De Marino 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![NPM version](https://img.shields.io/npm/v/consoleplusplus)](https://www.npmjs.com/package/consoleplusplus) 2 | [![Build Status](https://travis-ci.org/detro/consoleplusplus.svg?branch=master)](https://travis-ci.org/detro/consoleplusplus) 3 | [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fdetro%2Fconsoleplusplus.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fdetro%2Fconsoleplusplus?ref=badge_shield) 4 | 5 | # Console++ - enhance your `console` 6 | 7 | **Console++** makes your `console` awesomeR. Colours, logging level and shit 8 | like that. 9 | 10 | And it works with both [PhantomJS](http://phantomjs.org) and 11 | [NodeJS](http://nodejs.org) (and pretty much any proper JavaScript runtime). 12 | 13 | ### NPM _one-liner_? 14 | 15 | ``` 16 | npm install consoleplusplus 17 | ``` 18 | 19 | ## How does it make it _awesomeR_? 20 | 21 | Like this: 22 | 23 | ```javascript 24 | // here console is not that awesomeR 25 | 26 | require("consoleplusplus"); 27 | // or 28 | require("./console++.js"); //< if downloaded locally 29 | 30 | // now console is very awesomeR!!! 31 | ``` 32 | 33 | **Console++** adds a bit of sparkling power to your shy little console. 34 | It's not a fancy logging library with all the bells and whistles - it's a 35 | "poor man" logger that you can drop in your code without having to rewrite it. 36 | 37 | _Here is for the lazy developer!_ 38 | 39 | ## How do I use it? 40 | 41 | _Ehm_, like a `console` genius! Just type stuff like: 42 | 43 | ```javascript 44 | console.log("A (boring) console.log message"); 45 | 46 | console.debug("An (irrelevant) console.debug message"); 47 | 48 | console.info("A (somewhat important) console.info message"); 49 | 50 | console.warn("A (quite important) console.warning message"); 51 | 52 | console.error("A (critical!) console.error message"); 53 | ``` 54 | 55 | and you get: 56 | 57 | ![alt text](https://raw.github.com/detro/consoleplusplus/master/README.pics/console++-1.png "Some output") 58 | 59 | ## No really, how? 60 | 61 | Yes, it manipulates the `console` object (_oh, the horror!_) so that you can 62 | have some fancy colours, timestamped messages and a bit more. Output looks like: 63 | 64 | ``` 65 | [LEVEL - TIMESTAMP] THE_MESSAGE 66 | ``` 67 | 68 | Not all messages are printed. It introduces the concept of `level` (set via 69 | `console.setLevel(level)`): as you would expect, it goes from `DEBUG` (lowest, 70 | that corresponds to _print all the things_) to `ERROR` (highest, that 71 | corresponds to _print only the errors_). 72 | 73 | By default the `LEVEL` portion of the message is coloured (see below how 74 | to disable this). Also, you can enable matching colouring for `THE_MESSAGE` 75 | (see methods listing below). 76 | 77 | One nifty feature (I think) it's that you have fine-grained control over 78 | `THE_MESSAGE`. You can wrap text within `#COLOR{TEXT_TO_COLOR}` like: 79 | 80 | ```javascript 81 | var message = "#red{this} is #cyan{a} #yellow{nice} message"; 82 | console.debug(message); 83 | ``` 84 | 85 | to print something like: 86 | 87 | ![alt text](https://raw.github.com/detro/consoleplusplus/master/README.pics/console++-2.png "Some colored output") 88 | 89 | **PLEASE**, do read the code to learn more. 90 | 91 | ## How do I configure it? 92 | 93 | **Console++** adds some few little methods to the `console` so you can tune 94 | it a bit, based on your taste. 95 | 96 | I'd like to be very lazy and say _"go read the code"_, but I guess I can list 97 | here those methods. 98 | 99 | ```javascript 100 | console.LEVELS = _LEVELS; 101 | 102 | // Set/Get Level 103 | console.setLevel(level); //< default `DEBUG` 104 | console.getLevel(); 105 | console.getLevelName(level); 106 | console.getLevelColor(level); 107 | console.isLevelVisible(levelToCompare); 108 | 109 | // Enable/Disable Colored Output 110 | console.enableColor(); //< default enabled 111 | console.disableColor(); 112 | console.isColored(); 113 | 114 | // Enable/Disable Colored Message Output 115 | console.enableMessageColor(); //< default disabled 116 | console.disableMessageColor(); 117 | console.isMessageColored(); 118 | 119 | // Enable/Disable Timestamped Output 120 | console.enableTimestamp(); //< default enabled 121 | console.disableTimestamp(); 122 | console.isTimestamped(); 123 | 124 | // Enable/Disable Equal Spacing on Level Name 125 | console.enableEqualSpacing(); //< default enabled 126 | console.disableEqualSpacing(); 127 | console.isEqualSpaced(); 128 | 129 | // Set OnOutput Callback (useful to write to file or something) 130 | // Callback: `function(formattedMessage, levelName)` 131 | console.onOutput(callback); //< default `null` 132 | ``` 133 | 134 | ## Limitations 135 | * Characters `{` and `}` are reserved: using those will produce an undefined result 136 | 137 | ## Links 138 | 139 | * On NPM: https://npmjs.org/package/consoleplusplus 140 | * On GitHub: https://github.com/detro/consoleplusplus 141 | 142 | _Keep calm and make awesome_. 143 | 144 | ## License 145 | 146 | This project is licensed under [BSD 3-Clause "New" or "Revised" License](./LICENSE). 147 | 148 | [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fdetro%2Fconsoleplusplus.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fdetro%2Fconsoleplusplus?ref=badge_large) 149 | 150 | 151 | 152 | 153 | 154 | -------------------------------------------------------------------------------- /README.pics/console++-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/detro/consoleplusplus/cb86e5289fd4bc144aed7a47761f07c6caf44925/README.pics/console++-1.png -------------------------------------------------------------------------------- /README.pics/console++-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/detro/consoleplusplus/cb86e5289fd4bc144aed7a47761f07c6caf44925/README.pics/console++-2.png -------------------------------------------------------------------------------- /console++.js: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Console++ by Ivan De Marino . 3 | 4 | Copyright (c) 2012, Ivan De Marino 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | if (console.LEVELS) { 29 | // Already loaded. No need to manipulate the "console" further. 30 | // NOTE: NodeJS already caches modules. This is just defensive coding. 31 | exports = console; 32 | return; 33 | } 34 | 35 | // private: 36 | var _ANSICODES = { 37 | 'reset' : '\033[0m', 38 | 'bold' : '\033[1m', 39 | 'italic' : '\033[3m', 40 | 'underline' : '\033[4m', 41 | 'blink' : '\033[5m', 42 | 'black' : '\033[30m', 43 | 'red' : '\033[31m', 44 | 'green' : '\033[32m', 45 | 'yellow' : '\033[33m', 46 | 'blue' : '\033[34m', 47 | 'magenta' : '\033[35m', 48 | 'cyan' : '\033[36m', 49 | 'white' : '\033[37m', 50 | 'grey' : '\033[90m' 51 | }, 52 | _LEVELS = { 53 | NONE : 0, 54 | OFF : 0, //< alias for "NONE" 55 | ERROR : 1, 56 | WARN : 2, 57 | WARNING : 2, //< alias for "WARN" 58 | INFO : 3, 59 | INFORMATION : 3, //< alias for "INFO" 60 | DEBUG : 4 61 | }, 62 | _LEVELS_COLOR = [ //< _LEVELS_COLOR position matches the _LEVELS values 63 | "NOCOLOR", 64 | "red", 65 | "yellow", 66 | "cyan", 67 | "green" 68 | ], 69 | _LEVELS_NAME = [ //< _LEVELS_NAME position matches the _LEVELS values 70 | "NONE", 71 | "ERROR", 72 | "WARN ", 73 | "INFO ", 74 | "DEBUG" 75 | ], 76 | _console = { 77 | error : console.error, 78 | warn : console.warn, 79 | info : console.info, 80 | debug : console.log, 81 | log : console.log 82 | }, 83 | _level = _LEVELS.DEBUG, 84 | _colored = true, 85 | _messageColored = false, 86 | _printLevel = true, 87 | _timed = true, 88 | _onOutput = null, 89 | _spacing = true; 90 | 91 | /** 92 | * Take a string and apply console ANSI colors for expressions "#color{msg}" 93 | * NOTE: Does nothing if "console.colored === false". 94 | * 95 | * @param str Input String 96 | * @returns Same string but with colors applied 97 | */ 98 | var _applyColors = function(str) { 99 | var tag = /#([a-z]+)\{|\}/, 100 | cstack = [], 101 | matches = null, 102 | orig = null, 103 | name = null, 104 | code = null; 105 | 106 | while (tag.test(str)) { 107 | matches = tag.exec(str); 108 | orig = matches[0]; 109 | 110 | if (console.isColored()) { 111 | if (orig === '}') { 112 | cstack.pop(); 113 | } else { 114 | name = matches[1]; 115 | if (name in _ANSICODES) { 116 | code = _ANSICODES[name]; 117 | cstack.push(code); 118 | } 119 | } 120 | 121 | str = str.replace(orig, _ANSICODES.reset + cstack.join('')); 122 | } else { 123 | str = str.replace(orig, ''); 124 | } 125 | } 126 | return str; 127 | }; 128 | 129 | /** 130 | * Decorate the Arguments passed to the console methods we override. 131 | * First element, the message, is now colored, timed and more (based on config). 132 | * 133 | * @param argsArray Array of arguments to decorate 134 | * @param level Logging level to apply (regulates coloring and text) 135 | * @returns Array of Arguments, decorated. 136 | */ 137 | var _decorateArgs = function(argsArray, level) { 138 | var args = Array.prototype.slice.call(argsArray, 1), 139 | msg = argsArray[0], 140 | levelMsg; 141 | 142 | if (console.isColored()) { 143 | levelMsg = console.getLevelName(level); 144 | if (!console.isEqualSpaced()) { 145 | levelMsg = levelMsg.trim(); 146 | } 147 | levelMsg = _applyColors("#" + console.getLevelColor(level) + "{" + levelMsg + "}"); 148 | msg = _applyColors(msg); 149 | 150 | if (console.isMessageColored()) { 151 | msg = _applyColors("#" + console.getLevelColor(level) + "{" + msg + "}"); 152 | } 153 | } else { 154 | levelMsg = console.getLevelName(level); 155 | } 156 | 157 | msg = _formatMessage(msg, levelMsg); 158 | 159 | args.splice(0, 0, msg); 160 | 161 | return args; 162 | }; 163 | 164 | /** 165 | * Formats the Message content. 166 | * @param msg The message itself 167 | * @param levelMsg The portion of message that contains the Level (maybe colored) 168 | * @retuns The formatted message 169 | */ 170 | var _formatMessage = function(msg, levelMsg) { 171 | var printLevelMsg = console.isLevelMsgPrinted(), 172 | printTimestamp = console.isTimestamped(), 173 | formatted; 174 | 175 | if (printLevelMsg && printTimestamp) { 176 | formatted = "[" + levelMsg + " - " + new Date().toJSON() + "] " + msg; 177 | } else if (printLevelMsg) { 178 | formatted = "[" + levelMsg + "] " + msg; 179 | } else if (printTimestamp) { 180 | formatted = "[" + new Date().toJSON() + "] " + msg; 181 | } else { 182 | formatted = msg; 183 | } 184 | 185 | return formatted; 186 | }; 187 | 188 | /** 189 | * Invokes the "console.onOutput()" callback, if it was set by user. 190 | * This is useful in case the user wants to write the console output to another media as well. 191 | * 192 | * The callback is invoked with 2 parameters: 193 | * - formattedMessage: formatted message, ready for output 194 | * - levelName: the name of the logging level, to inform the user 195 | * 196 | * @param msg The Message itself 197 | * @param level The Message Level (Number) 198 | */ 199 | var _invokeOnOutput = function(msg, level) { 200 | var formattedMessage, 201 | levelName; 202 | 203 | if (_onOutput !== null && typeof(_onOutput) === "function") { 204 | levelName = console.getLevelName(level); 205 | formattedMessage = _formatMessage(msg, levelName); 206 | 207 | _onOutput.call(null, formattedMessage, levelName); 208 | } 209 | }; 210 | 211 | 212 | // public: 213 | // CONSTANT: Logging Levels 214 | console.LEVELS = _LEVELS; 215 | 216 | // Set/Get Level 217 | console.setLevel = function(level) { 218 | _level = level; 219 | }; 220 | console.getLevel = function() { 221 | return _level; 222 | }; 223 | console.getLevelName = function(level) { 224 | return _LEVELS_NAME[typeof(level) === "undefined" ? _level : level]; 225 | }; 226 | console.getLevelColor = function(level) { 227 | return _LEVELS_COLOR[typeof(level) === "undefined" ? _level : level]; 228 | }; 229 | console.isLevelVisible = function(levelToCompare) { 230 | return _level >= levelToCompare; 231 | }; 232 | 233 | // Enable/Disable Colored Output 234 | console.enableColor = function() { 235 | _colored = true; 236 | }; 237 | console.disableColor = function() { 238 | _colored = false; 239 | }; 240 | console.isColored = function() { 241 | return _colored; 242 | }; 243 | 244 | // Enable/Disable Colored Message Output 245 | console.enableMessageColor = function() { 246 | _messageColored = true; 247 | }; 248 | console.disableMessageColor = function() { 249 | _messageColored = false; 250 | }; 251 | console.isMessageColored = function() { 252 | return _messageColored; 253 | }; 254 | 255 | // Enable/Disable Level Printing in Output 256 | console.enableLevelMsg = function() { 257 | _printLevel = true; 258 | }; 259 | console.disableLevelMsg = function() { 260 | _printLevel = false; 261 | }; 262 | console.isLevelMsgPrinted = function() { 263 | return _printLevel; 264 | }; 265 | 266 | // Enable/Disable Timestamped Output 267 | console.enableTimestamp = function() { 268 | _timed = true; 269 | }; 270 | console.disableTimestamp = function() { 271 | _timed = false; 272 | }; 273 | console.isTimestamped = function() { 274 | return _timed; 275 | }; 276 | 277 | // Enable/Disable Equal Spacing on Level Name 278 | console.enableEqualSpacing = function() { 279 | _spacing = true; 280 | }; 281 | console.disableEqualSpacing = function() { 282 | _spacing = false; 283 | }; 284 | console.isEqualSpaced = function() { 285 | return _spacing; 286 | }; 287 | 288 | // Set OnOutput Callback (useful to write to file or something) 289 | // Callback: `function(formattedMessage, levelName)` 290 | console.onOutput = function(callback) { 291 | _onOutput = callback; 292 | }; 293 | 294 | // Decodes coloring markup in string 295 | console.str2clr = function(str) { 296 | return console.isColored() ? _applyColors(str): str; 297 | }; 298 | 299 | // Overrides some key "console" Object methods 300 | console.error = function(msg) { 301 | if (arguments.length > 0 && this.isLevelVisible(_LEVELS.ERROR)) { 302 | _console.error.apply(this, _decorateArgs(arguments, _LEVELS.ERROR)); 303 | _invokeOnOutput(msg, _LEVELS.ERROR); 304 | } 305 | }.bind(console); 306 | console.warn = function(msg) { 307 | if (arguments.length > 0 && this.isLevelVisible(_LEVELS.WARN)) { 308 | _console.warn.apply(this, _decorateArgs(arguments, _LEVELS.WARN)); 309 | _invokeOnOutput(msg, _LEVELS.WARN); 310 | } 311 | }.bind(console); 312 | console.info = function(msg) { 313 | if (arguments.length > 0 && this.isLevelVisible(_LEVELS.INFO)) { 314 | _console.info.apply(this, _decorateArgs(arguments, _LEVELS.INFO)); 315 | _invokeOnOutput(msg, _LEVELS.INFO); 316 | } 317 | }.bind(console); 318 | console.debug = function(msg) { 319 | if (arguments.length > 0 && this.isLevelVisible(_LEVELS.DEBUG)) { 320 | _console.debug.apply(this, _decorateArgs(arguments, _LEVELS.DEBUG)); 321 | _invokeOnOutput(msg, _LEVELS.DEBUG); 322 | } 323 | }.bind(console); 324 | console.log = function(msg) { 325 | if (arguments.length > 0) { 326 | _console.log.apply(this, arguments); 327 | } 328 | }; 329 | 330 | exports = console; 331 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "consoleplusplus", 3 | "version": "1.4.4", 4 | "lockfileVersion": 1 5 | } 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "consoleplusplus", 3 | "version": "1.4.4", 4 | "description": "Console++ - enhance your console", 5 | "main": "console++.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "node test/basic_test.js" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git://github.com/detro/consoleplusplus.git" 15 | }, 16 | "keywords": [ 17 | "console", 18 | "log", 19 | "level", 20 | "colours", 21 | "standard output" 22 | ], 23 | "author": "Ivan De Marino ", 24 | "license": "BSD", 25 | "readmeFilename": "README.md" 26 | } 27 | -------------------------------------------------------------------------------- /test/basic_test.js: -------------------------------------------------------------------------------- 1 | require("../console++.js"); 2 | 3 | console.setLevel(console.LEVELS.NONE); 4 | 5 | console.log("A (boring) console.log message"); 6 | 7 | console.debug("An (irrelevant) console.debug message"); 8 | 9 | console.info("A (somewhat important) console.info message"); 10 | 11 | console.warn("A (quite important) console.warning message"); 12 | 13 | console.error("A (critical!) console.error message"); 14 | 15 | var message = "#red{this} is #cyan{a} #yellow{nice} message"; 16 | console.debug(message); 17 | 18 | function printLevels() { 19 | console.log("log"); 20 | console.debug("debug "+console.str2clr("#cyan{verde}")); 21 | console.info("info"); 22 | console.warn("warning #blink{blink}") 23 | console.error("error"); 24 | } 25 | 26 | printLevels(); 27 | 28 | console.setLevel(console.LEVELS.DEBUG); 29 | printLevels(); 30 | 31 | console.disableTimestamp(); 32 | console.setLevel(console.LEVELS.INFO); 33 | printLevels(); 34 | console.enableTimestamp(); 35 | require("../console++.js"); 36 | 37 | console.setLevel(console.LEVELS.WARN); 38 | console.disableColor(); 39 | printLevels(); 40 | console.enableColor(); 41 | 42 | console.enableMessageColor(); 43 | console.setLevel(console.LEVELS.ERROR); 44 | printLevels(); 45 | 46 | console.setLevel(console.LEVELS.DEBUG); 47 | console.disableEqualSpacing(); 48 | printLevels(); 49 | 50 | console.disableTimestamp(); 51 | printLevels(); 52 | 53 | for (var i in console) { 54 | console.log(i + " " + typeof(console[i])); 55 | } 56 | --------------------------------------------------------------------------------