diff --git a/README.md b/README.md index 0b8d213..64e646c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ulog v2.0.0-beta.16 +# ulog v2.0.0-beta.17 ### The Universal Logger [![npm](https://img.shields.io/npm/v/ulog.svg)](https://npmjs.com/package/ulog) @@ -8,14 +8,14 @@ . -![logo](https://unpkg.com/ulog@2.0.0-beta.16/ulog.png) +![logo](https://unpkg.com/ulog@2.0.0-beta.17/ulog.png) ## The logger for javascript applications `ulog` is *the* logger for Javascript applications. It's universal, meaning it runs everywhere. You can use `ulog` in your Express server application running on Node JS just as well as in your React single page application running in the browser. It just works. -![screenshot](https://unpkg.com/ulog@2.0.0-beta.16/screenshot.jpg) +![screenshot](https://unpkg.com/ulog@2.0.0-beta.17/screenshot.jpg) ## Features @@ -130,7 +130,7 @@ log('Logging is easy') If you want, you can import `ulog` with a script tag: ```html - + @@ -146,12 +146,12 @@ log('Logging is easy!') If you want the file for the browser to include in your project yourself, you can download it from here. -* [ulog.min.js](https://unpkg.com/ulog@2.0.0-beta.16/ulog.min.js) (~2.7kB minified and gzipped) -* [ulog.lazy.min.js](https://unpkg.com/ulog@2.0.0-beta.16/ulog.lazy.min.js) (~4.3kB minified and gzipped) +* [ulog.min.js](https://unpkg.com/ulog@2.0.0-beta.17/ulog.min.js) (~2.7kB minified and gzipped) +* [ulog.lazy.min.js](https://unpkg.com/ulog@2.0.0-beta.17/ulog.lazy.min.js) (~4.3kB minified and gzipped) > `ulog.min.js` lazy loads `ulog.lazy.min.js` on demand, so make sure to include both files in your download -* [full.min.js](https://unpkg.com/ulog@2.0.0-beta.16/full.min.js) (~5.7kB minified and gzipped) +* [full.min.js](https://unpkg.com/ulog@2.0.0-beta.17/full.min.js) (~5.7kB minified and gzipped) > Full bundle, no lazy loading @@ -613,12 +613,12 @@ messages at these higher levels are indented a bit more than the other messages, making the logging harder to read. This can be clearly seen in the screenshot from `ulog` v2.0.0-beta-11, which did not yet have alignment: -![screenshot](https://unpkg.com/ulog@2.0.0-beta.16/screenshot-beta.11.jpg) +![screenshot](https://unpkg.com/ulog@2.0.0-beta.17/screenshot-beta.11.jpg) `ulog` now automatically adds some formatting that negates the extra indentation the messages at these higher levels get, so all messages are nicely aligned: -![screenshot](https://unpkg.com/ulog@2.0.0-beta.16/screenshot.jpg) +![screenshot](https://unpkg.com/ulog@2.0.0-beta.17/screenshot.jpg) You can control alignment with [config option `log_align`](#config-option-log_align). diff --git a/build.js b/build.js index 96e1b03..01585c5 100644 --- a/build.js +++ b/build.js @@ -44,6 +44,22 @@ var v = pkg.version fs.writeFileSync(file, data, 'utf8') log.info(`README.md (~${(data.length / 1024).toFixed(1)} kB)`) + file = path.resolve(__dirname, 'tutorial', 'index.html') + log(`Reading ${file}`) + data = fs.readFileSync(file, 'utf-8') + data = data.replace(/ulog@\d(\d)?\.\d(\d)?\.\d(\d)?(-[a-z]+\.\d(\d)?)?/g, `ulog@${v}`) + log(`Writing ${file}`) + fs.writeFileSync(file, data, 'utf8') + log.info(`tutorial/index.html (~${(data.length / 1024).toFixed(1)} kB)`) + + file = path.resolve(__dirname, 'vs', 'debug.html') + log(`Reading ${file}`) + data = fs.readFileSync(file, 'utf-8') + data = data.replace(/ulog@\d(\d)?\.\d(\d)?\.\d(\d)?(-[a-z]+\.\d(\d)?)?/g, `ulog@${v}`) + log(`Writing ${file}`) + fs.writeFileSync(file, data, 'utf8') + log.info(`vs/debug.html (~${(data.length / 1024).toFixed(1)} kB)`) + ulog('a:one').debug('A debug message') ulog('a:two').debug('A debug message') ulog('a:three').debug('A debug message') diff --git a/mods/config/watch.js b/mods/config/watch.js index bf37c0f..acbd3e2 100644 --- a/mods/config/watch.js +++ b/mods/config/watch.js @@ -7,10 +7,8 @@ var notify = require('./notify') module.exports = function(ulog) { var filename = path.resolve(ulog.get('log_config') || 'log.config') - console.info('watching ' + filename) try { fs.watch(filename, { persistent: false }, function() { - console.info(filename + ' changed. reading it again') read(ulog, function(cfg){ var changed = update(ulog.config, cfg) if (changed.length) notify(ulog, changed) diff --git a/package.json b/package.json index f3be7c5..746e6e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ulog", - "version": "2.0.0-beta.16", + "version": "2.0.0-beta.17", "description": "The universal logger", "main": "./ulog.js", "unpkg": "ulog.min.js", diff --git a/tutorial/index.html b/tutorial/index.html index aac72da..faa01c7 100644 --- a/tutorial/index.html +++ b/tutorial/index.html @@ -4,7 +4,7 @@ ulog tutorial - + diff --git a/vs/callstack.jpg b/vs/callstack.jpg new file mode 100644 index 0000000..821d2e5 Binary files /dev/null and b/vs/callstack.jpg differ diff --git a/vs/debug.html b/vs/debug.html index 52e249b..ba989d6 100644 --- a/vs/debug.html +++ b/vs/debug.html @@ -2,11 +2,11 @@ - debug vs ulog + ulog vs debug - + @@ -42,15 +42,19 @@

vs debug

Open devtools

Open the browser developer tools (F12).

Enable logging

-

No output will be visible until you enable logging, by adding a - configuration key to localStorage. To enable logging - in both debug and ulog, add this to localStorage:

-

debug=*
-  

-

To add this to localStorage, you can use the developer tools (for Chrome, tab Application) - or in the Console tab, run this command:

-

localStorage.setItem('debug', '*')
-  

+

No output will be visible until you enable logging. To enable + logging in both debug and ulog, set + debug=*.

+ +

You can do this using the developer tools GUI (tab Application in + Chrome), or in the Console tab run this command: + localStorage.setItem('debug', '*'), + or you can press the button below:

+

+

Log some messages

Press the buttons to log messages with both loggers:

-

Paragraph text

- Body text -
Heading 6
-

Paragraph text

-
Heading 5
-

Paragraph text

-

Heading 4

-

Paragraph text

-

Heading 3

-

Paragraph text

-

Heading 2

-

Paragraph text

-

Heading 1

+

You should get output like this:

+ +

ulog monitors the config

+

You may notice that debug is not producing any output, + whereas ulog is. That's because ulog monitors + the configuration at runtime but debug doesn't. So to get + debug to pick up our configuration change, reload the + page (F5). Then, press both buttons again. This time, we can see + debug and ulog output side by side:

+ +

The output of ulog and debug is very similar. + Both loggers add the name of the logger to the message and both loggers + show some timing information. Also, both loggers use colors to produce + more clear output. But, there are actually more differences here than + initially meet the eye. +

ulog preserves the callstack

+

One big difference between debug and ulog + is marked with arrows in the screenshot. ulog preserves + the callstack, meaning file names and line numbers shown in the + console point to the client code. This is in big contrast to + debug, which injects it's own formatting function in + the callstack, meaning all file names and line numbers point to that + function in the debug minified source file. Not very + convenient!

+

ulog has configurable formatting

+

debug only allows some tweaks to it's formatting. + ulog allows you to take full control of formatting. + You can change the format for all or some loggers using config + option log_format. For example, let's try adding the time to the + message. Set log_format=time lvl name perf in the + devtools or press the button below:

+ + \ No newline at end of file diff --git a/vs/debug.js b/vs/debug.js index 120fedd..1ee57d0 100644 --- a/vs/debug.js +++ b/vs/debug.js @@ -2,9 +2,9 @@ self.mydebug = { log: function(){ // code below is tightly coupled to debug var log = debug('debug') - log('-----------') - log('| debug |') - log('-----------') + log('------------') + log('| debug |') + log('------------') } } diff --git a/vs/enable-debug.jpg b/vs/enable-debug.jpg new file mode 100644 index 0000000..b509bf1 Binary files /dev/null and b/vs/enable-debug.jpg differ diff --git a/vs/loglevel.html b/vs/loglevel.html new file mode 100644 index 0000000..cb6fd55 --- /dev/null +++ b/vs/loglevel.html @@ -0,0 +1,46 @@ + + + + + ulog vs loglevel + + + + + + + + + + + + + + + + +
+

vs loglevel

+

This page compares ulog to loglevel.

+

Open devtools

+

Open the browser developer tools (F12).

+

TO DO

+
+ + \ No newline at end of file diff --git a/vs/loglevel.js b/vs/loglevel.js new file mode 100644 index 0000000..f65b961 --- /dev/null +++ b/vs/loglevel.js @@ -0,0 +1,10 @@ +self.myloglevel = { + log: function(){ + // code below is tightly coupled to debug + var logger = log.createLogger('loglevel') + logger.info('------------') + logger.info('| loglevel |') + logger.info('------------') + } +} + diff --git a/vs/ulog-only.jpg b/vs/ulog-only.jpg new file mode 100644 index 0000000..9473e23 Binary files /dev/null and b/vs/ulog-only.jpg differ diff --git a/vs/ulog.js b/vs/ulog.js index 2054198..68262cc 100644 --- a/vs/ulog.js +++ b/vs/ulog.js @@ -3,8 +3,8 @@ self.myulog = { // we use anylogger to create the logger // so we stay loosely coupled to ulog var log = anylogger('ulog').debug - log('-----------') - log('| ulog |') - log('-----------') + log('------------') + log('| ulog |') + log('------------') } }