Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // small wrapper of console.log
- // msg = string of text you want to output
- // type = some string matching a case in the switch
- // result: will color and style your console.log messages.
- // note: if no type is added, 'default' will be used.
- function Log(msg, type) {
- if (type === undefined || type === null) type = 'default';
- var styles = '';
- styles += 'text-shadow: 2px 2px rgba(0, 0, 0, 0.8);';
- styles += 'font-size: 14px;';
- styles += 'font-family: "Consolas";';
- styles += 'border: 2px solid black;';
- styles += 'line-height: 20px;';
- styles += 'width: 100%;'
- switch (type) {
- case 'default':
- // no concat of messages.
- styles += 'color: white;';
- styles += 'background: darkslategray;';
- break;
- case 'ok':
- msg = " OK: " + msg;
- styles += 'color: ghostwhite;';
- styles += 'background: green;';
- break;
- case 'err':
- msg = " ERROR: " + msg;
- styles += 'color: gold;';
- styles += 'background: firebrick;';
- styles += 'font-weight: bold;';
- break;
- case 'net':
- msg = "NETWORK: " + msg;
- styles += 'color: palegreen;';
- styles += 'background: rebeccapurple;';
- styles += 'font-style: italic;';
- break;
- //case '???':
- // uncomment this case and
- // add stuff here if you want more cases!
- //break;
- default: break;
- }
- console.log('%c ' + msg + " ", styles);
- }
- Log("regular message with no specification of type.");
- Log("an OK typed message.", 'ok');
- Log("an ERR typed message.", 'err');
- Log("a NET typed message.", 'net');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement