mirror of
https://github.com/mathew-kurian/Scribe.js
synced 2025-04-24 22:34:58 +00:00
Add workings examples for current work
This commit is contained in:
parent
db8934f1d2
commit
34c8c770e7
3 changed files with 56 additions and 0 deletions
23
examples/run.js
Normal file
23
examples/run.js
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
/**
|
||||||
|
* The main file
|
||||||
|
*/
|
||||||
|
|
||||||
|
var scribe = require('../scribe'), //loads Scribe
|
||||||
|
console = process.console; //create a local (for the module) console
|
||||||
|
|
||||||
|
//Don't worry, you can still acces the original console
|
||||||
|
global.console.log("I'm using the original console.log()");
|
||||||
|
|
||||||
|
//Let's create a new logger `myLoger` ...
|
||||||
|
console.addLogger('myLogger');
|
||||||
|
//... and use it !
|
||||||
|
console.tag('MyTag').time().file().myLogger('Scribe.js is awesome');
|
||||||
|
|
||||||
|
|
||||||
|
//Let's see how to use the new console in a sub-module :
|
||||||
|
//(just open submodules to see what's going on there)
|
||||||
|
|
||||||
|
//By default, submodules still use original console
|
||||||
|
require('./sub-without_new_console').saySomething("Hello world !");
|
||||||
|
//But, you can use the new one !
|
||||||
|
require('./sub-with_new_console').saySomething("Hello world !");
|
18
examples/sub-with_new_console.js
Normal file
18
examples/sub-with_new_console.js
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
(function () {
|
||||||
|
|
||||||
|
|
||||||
|
//You can use the new console and all its loggers
|
||||||
|
//it's not too far away
|
||||||
|
var console = process.console;
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
|
||||||
|
saySomething : function (msg) {
|
||||||
|
msg = "With new console - " + msg;
|
||||||
|
console.myLogger(msg); //I'm using my custom logger `myLogger`
|
||||||
|
//you can still use global.console object if you need to
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}());
|
15
examples/sub-without_new_console.js
Normal file
15
examples/sub-without_new_console.js
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
(function () {
|
||||||
|
|
||||||
|
//By default, the module access global.console
|
||||||
|
//so it doesn't break dependencies logging
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
|
||||||
|
saySomething : function (msg) {
|
||||||
|
msg = "Without new console - " + msg;
|
||||||
|
console.log(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}());
|
Loading…
Add table
Reference in a new issue