{"id":153,"date":"2015-03-24T05:43:40","date_gmt":"2015-03-24T05:43:40","guid":{"rendered":"https:\/\/www.tech.shinynewthings.com\/?p=153"},"modified":"2015-04-08T18:43:31","modified_gmt":"2015-04-08T18:43:31","slug":"styling-console-log-output","status":"publish","type":"post","link":"https:\/\/www.tech.shinynewthings.com\/?p=153","title":{"rendered":"Console Log Output &#8211;  Substitution and CSS in Chrome"},"content":{"rendered":"<p>Debugging should be more colorful.<\/p>\n<p>Console.log in Chrome accepts a number of parameters including css.<\/p>\n<p>Output can be stylized by using %c prior to the stylized text.<\/p>\n<p>Example:<\/p>\n<pre><code>console.log(\"I'm%c Colorful.\", \"color: blue; font-size:14px\");\n<\/code><\/pre>\n<p>A simple utility wrapper I use to stylize console.log output.<\/p>\n<pre><code>var styled = (function () {\n\nvar fontStyle = 'font-family: Helvetica,Arial,sans-serif; font-size: 13px;', boxStyle = ' line-height: 25px; padding: 5px 5px; border-radius: 4px;', styles = { msg : ' color: #eee; background: #222; ' + fontStyle + boxStyle, err : ' color: #0F0; background: #222; ' + fontStyle + boxStyle }, log = function (msg, styleStr) { if (styleStr) { console.log('%c' + msg, styles[styleStr]); } else { console.log('%c' + msg, styles.msg); } } return log; }());\n\nstyled('New Log Style. '); \nstyled('New Error Style. ', 'err');\n<\/code><\/pre>\n<p>Additional Console substitutions.<\/p>\n<p>As String:<\/p>\n<pre><code>console.log('%s', 'String'); \/\/ String\n<\/code><\/pre>\n<p>As Integer:<\/p>\n<pre><code>console.log('%d', 5.3); \/\/ 5\nconsole.log('%i', 5.3); \/\/ 5\n<\/code><\/pre>\n<p>As Float:<\/p>\n<pre><code>console.log('%f', 5.3); \/\/ 5.3\n<\/code><\/pre>\n<p>Displaying expandable Objects \/ Arrays (note: css cannot style this output).<\/p>\n<pre><code>console.log('Expandable object or array %O', {type:'color', color:'blue'}); \/\/ Expandable object or array Object\n<\/code><\/pre>\n<p>Random Example:<\/p>\n<pre><code>console.log(\"I'm%c - %c%s%c.\", \"color: black; font-size:19px\", \"color: blue; font-size:14px\", \"Colorful\", \"color: black; font-size:19px\");\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Debugging should be more colorful. Console.log in Chrome accepts a number of parameters including css. Output can be stylized by using %c prior to the stylized text. Example: console.log(&#8220;I&#8217;m%c Colorful.&#8221;, &#8220;color: blue; font-size:14px&#8221;); A simple utility wrapper I use to stylize console.log output. var styled = (function () { var fontStyle = &#8216;font-family: Helvetica,Arial,sans-serif; font-size: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-153","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts\/153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=153"}],"version-history":[{"count":10,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts\/153\/revisions"}],"predecessor-version":[{"id":191,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts\/153\/revisions\/191"}],"wp:attachment":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}