Skip to content

Instantly share code, notes, and snippets.

@mrosata
Last active October 8, 2016 18:34
Show Gist options
  • Select an option

  • Save mrosata/8fc76efcaca12530d4a5c2d2be0d9e38 to your computer and use it in GitHub Desktop.

Select an option

Save mrosata/8fc76efcaca12530d4a5c2d2be0d9e38 to your computer and use it in GitHub Desktop.
Simple pretty logging functions used in my videos to display parts of the program as examples.
"use strict";
var presentationLogger = (function(window, undefined) {
// warn -> Message -> Warning
var warn = function _warning (val) {
console.warn( `%c${val}`, 'color:#ff3c41;font-weight:bold' );
};
// echo :: Message -> Echo message to console italized.
var echo = function _logging (val) {
console.log( `%c${val}`, 'color:#47cf73;font-style:italic' );
}
// log :: Mixed [, Mixed..] -> Logs values to console.log
var log = function _echoMessages (...msgs) {
console.debug(...msgs);
}
var folder = function(label, fn, collapsed = false) {
let fold = collapsed ? console.groupCollapsed : console.group;
fold(label);
fn();
console.groupEnd();
};
return {
warn: warn,
log: log,
echo: echo,
error: console.error,
trace: console.trace,
fold: console.group,
foldEnd: console.groupEnd,
folder: folder,
table: console.table,
assert: console.assert,
folded: console.groupCollapsed,
clear: console.clear,
count: console.count,
stamp: console.timestamp,
profile: console.profile,
profileEnd: console.profileEnd,
mem: console.memory
};
}(window));
@mrosata

mrosata commented Sep 21, 2016

Copy link
Copy Markdown
Author

These functions/methods are useful for my videos I'm making to teach JavaScript. They are great for logging messages but since the code is just as large as the code in the video lesson it doesn't make sense to have it sitting there onscreen during the presentation.

Feel free to paste this into your code pen. My console is themed to be dark so the logout messages look good with the colors added in the console.warn and console.debug statements.

@mrosata

mrosata commented Oct 8, 2016

Copy link
Copy Markdown
Author

Removed static text in the warn/log methods. Switched 'echo' and 'log' around (so now log is proxy to 'console.log' and 'echo' does what 'log' previously did (just italicized message). Added more of the console methods as utils.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment