{"_id":"@arve.knudsen/js-logger","_rev":"3-7f2f6e254ad2591c314da6e6f37eb025","name":"@arve.knudsen/js-logger","description":"Lightweight, unobtrusive, configurable JavaScript logger","dist-tags":{"latest":"1.3.1"},"versions":{"1.3.1":{"name":"@arve.knudsen/js-logger","version":"1.3.1","description":"Lightweight, unobtrusive, configurable JavaScript logger","author":{"name":"Jonny Reeves","url":"http://jonnyreeves.co.uk"},"homepage":"http://github.com/aknuds1/js-logger","repository":{"type":"git","url":"git://github.com/aknuds1/js-logger.git"},"bugs":{"url":"http://github.com/aknuds1/js-logger/issues"},"license":"MIT","main":"src/logger.js","scripts":{"test":"gulp test lint"},"devDependencies":{"gulp":"~3.8.11","gulp-util":"~2.2.14","gulp-uglify":"~1.2.0","gulp-replace":"~0.5.3","gulp-rename":"~1.2.0","gulp-qunit":"~1.2.1","gulp-jshint":"~1.10.0","gulp-size":"~1.2.1","gulp-git":"~1.2.0"},"gitHead":"492bfac2737a7ba33f44c6fa7eefae22785855a0","_id":"@arve.knudsen/js-logger@1.3.1","_shasum":"5928bd0d23ae9259d616e554bc1f483b88a47e6d","_from":".","_npmVersion":"3.8.6","_nodeVersion":"5.11.1","_npmUser":{"name":"arve.knudsen","email":"arve.knudsen@gmail.com"},"dist":{"shasum":"5928bd0d23ae9259d616e554bc1f483b88a47e6d","tarball":"https://registry.npmjs.org/@arve.knudsen/js-logger/-/js-logger-1.3.1.tgz","integrity":"sha512-mTI+prlw8/XzpzFxmjxfC7ciSwNM5HVwPjXiW24/no0EAR3/kHtwTmDXzu1UoYEAFMt1e5EmbTZUEZiB90WYQQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC5DS3ouf31f5Rr14xBgUnT+n4v38DoaAEBqfLTCuLJrQIgA/o55WVghf/4LP6mZdZ5vhr715P5y+fkFFeaWCRnfvc="}]},"maintainers":[{"name":"arve.knudsen","email":"arve.knudsen@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/js-logger-1.3.1.tgz_1474290722230_0.6440755254589021"}}},"readme":"# js-Logger [![Build Status](https://travis-ci.org/jonnyreeves/js-logger.svg?branch=master)](https://travis-ci.org/jonnyreeves/js-logger) [![npm version](https://badge.fury.io/js/js-logger.svg)](http://badge.fury.io/js/js-logger) ![npm dependencies](https://david-dm.org/jonnyreeves/js-logger.png)\n\n> Lightweight, unobtrusive, configurable JavaScript logger.\n\n[logger.js](https://github.com/jonnyreeves/js-logger/blob/master/src/logger.js) will make you rich, famous and want for almost nothing - oh and it's a flexible abstraction over using `console.log` as well.\n\n## Installation\njs-Logger has zero dependencies and comes with AMD and CommonJS module boilerplate.  If the last sentence meant nothing to you then just lob the following into your page:\n\n```html\n<script src=\"https://raw.github.com/jonnyreeves/js-logger/master/src/logger.min.js\"></script>\n```\n\n## Usage\nNothing beats the sheer ecstasy of logging!  js-Logger does its best to not be awkward and get in the way.  If you're the sort of person who just wants to get down and dirty then all you need is one line of code:\n\n```js\n// Log messages will be written to the window's console.\nLogger.useDefaults();\n```\n\nNow, when you want to emit a red-hot log message, just drop one of the following (the syntax is identical to the `console` object)\n\n```js\nLogger.debug(\"I'm a debug message!\");\nLogger.info(\"OMG! Check this window out!\", window);\nLogger.warn(\"Purple Alert! Purple Alert!\");\nLogger.error(\"HOLY SHI... no carrier.\");\n```\n\nLog messages can get a bit annoying; you don't need to tell me, it's all cool.  If things are getting too noisy for your liking then it's time you read up on the `Logger.setLevel` method:\n\n```js\n// Only log WARN and ERROR messages.\nLogger.setLevel(Logger.WARN);\nLogger.debug(\"Donut machine is out of pink ones\");  // Not a peep.\nLogger.warn(\"Asteroid detected!\");  // Logs \"Asteroid detected!\", best do something about that!\n\n// Ah, you know what, I'm sick of all these messages.\nLogger.setLevel(Logger.OFF);\nLogger.error(\"Hull breach on decks 5 through to 41!\");  // ...\n```\n\n## Log Handler Functions\nAll log messages are routed through a handler function which redirects filtered messages somewhere.  You can configure the handler function via `Logger.setHandler` nothing that the supplied function expects two arguments; the first being the log messages to output and the latter being a context object which can be inspected by the log handler.\n\n```js\nLogger.setHandler(function (messages, context) {\n\t// Send messages to a custom logging endpoint for analysis.\n\t// TODO: Add some security? (nah, you worry too much! :P)\n\tjQuery.post('/logs', { message: messages[0], level: context.level });\n});\n```\n\n### Default Log Handler Function\nWhen you invoke `Logger.useDefaults()`, you can specify a default LogLevel and a custom\nlogFormatter function which can alter the messages printed to the console:\n\n```js\nLogger.useDefaults({\n\tlogLevel: Logger.WARN,\n\tformatter: function (messages, context) {\n\t\tmessages.unshift('[MyApp]');\n\t\tif (context.name) messages.unshift('[' + context.name + ']');\n\t}\n})\n```\n\nIn order to get the default log handler function, you may call `Logger.getDefaultHandler()`.\n\n## Named Loggers\nOkay, let's get serious, logging is not for kids, it's for adults with serious software to write and mission critical log messages to trawl through.  To help you in your goal, js-Logger provides 'named' loggers which can be configured individual with their own contexts.\n\n```js\n// Retrieve a named logger and store it for use.\nvar myLogger = Logger.get('ModuleA');\nmyLogger.info(\"FizzWozz starting up\");\n\n// This logger instance can be configured independent of all others (including the global one).\nmyLogger.setLevel(Logger.WARN);\n\n// As it's the same instance being returned each time, you don't have to store a reference:\nLogger.get('ModuleA').warn('FizzWozz combombulated!');\n```\n\nNote that `Logger.setLevel()` will also change the current log filter level for all named logger instances; so typically you would configure your logger levels like so:\n\n```js\n// Create a couple of named loggers (typically in their own module)\nvar loggerA = Logger.get('LoggerA');\nvar loggerB = Logger.get('LoggerB');\n\n// Configure log levels.\nLogger.setLevel(Logger.WARN);  // Global logging level.\nLogger.get('LoggerB').setLevel(Logger.DEBUG);  // Enable debug logging for LoggerB\n```\n\n## Profiling\nSometimes its good to know what's taking so damn long; you can use `Logger.time()` and `Logger.timeEnd()` to keep tabs on things, the default log handler implementation delegates to the equivalent console methods if they exist, or write to `console.log` if they don't.\n\n```js\n// Start timing something\nLogger.time('self destruct sequence');\n\n// ... Some time passes ...\n\n// Stop timing something.\nLogger.timeEnd('self destruct sequence'); // logs: 'self destruct sequence: 1022ms'.\n```\n\nNote that `time` and `timeEnd` methods are also provided to named Logger instances.\n","maintainers":[{"name":"arve.knudsen","email":"arve.knudsen@gmail.com"}],"time":{"modified":"2022-06-12T14:49:03.012Z","created":"2016-09-19T13:12:04.133Z","1.3.1":"2016-09-19T13:12:04.133Z"},"homepage":"http://github.com/aknuds1/js-logger","repository":{"type":"git","url":"git://github.com/aknuds1/js-logger.git"},"author":{"name":"Jonny Reeves","url":"http://jonnyreeves.co.uk"},"bugs":{"url":"http://github.com/aknuds1/js-logger/issues"},"license":"MIT","readmeFilename":"README.md"}