TODO: Write short intro
TODO: Write examples
TODO: Write examples
TODO: Write examples
TODO: Write examples
TODO: Write examples
TODO: Write examples
TODO: Write examples
TODO: Write examples
TODO: Write examples
TODO: Write examples
echo 'You' # => Level of importance is 0
echo.debug 'are' # => … is 0
echo.info 'awesome,' # => … is 1
echo.warn 'my' # => … is 2
echo.error 'friend!' # => … is 3echo('Good news!', level: 3) # => … is 3
echo('Good news!', level: 'error') # => … is 3This code:
echo.log('Test', 'logging', namespace: 'app.lol_module.45')
echo.log(['trololo'])… will store:
[
{
"timestamp": 1341468018606,
"body": ["Test", "logging"],
"namespace": "app.lol_module.45"
},
{
"timestamp": 1341468018606,
"body": [["trololo"]],
"namespace": ""
}
]By default logs is don't print to developer console (Web Inspector, Firebug etc).
If you want to log with print you should add print: true key:
echo('', print: true)If you want to setup print: true for specific levels:
echo.definePrint
0: false
3: true
error: trueOr you can you advanced rules:
all - Set true to all levels.
only - Set true to only …
except - Set true to all except …
greaterThan (alias: gt) - Greater than.
greaterThanOrEqualTo (aliases: gte, gteq) - Greater than or equal to.
lessThan (alias: lt) - Less than.
lessThanOrEqualTo (aliases: lte, lteq) - Less than or equal to.
Always print:
echo.definePrint('all')
## equal to
echo.definePrint(all: true)
## equal to
echo.defaultOptions.print = trueOnly for specific levels:
echo.definePrint('only', [1, 'warn'])Print log with level great than 4 (but 7 and 9):
echo.definePrint
gt: 4
except: [7, 9]
## equal to
echo.definePrint
gt: 4
7: false
9: false
## equal to
echo.definePrint
gt: 4
except: 7
9: falseetc
By default Echoes use console.log (if defined) for logs with level 0, console.info for 1, console.warn for 2, console.error for 3.
But you can setup you own print function:
ownPrint = (log, options) ->
alert(log.body)
echo.setPrintFunction(ownPrint)All objects and arrays clone on log:
obj =
qwe: 1
asd: 2
obj: qwe: 1, asd: 2
echo obj
loggedObj = echo.logs.first().body[0]
loggedObj == obj #=> false, because obj was cloned
loggedObj.obj == obj #=> true, but not deeplyIf you want to save link to object instead of clone it, just add clone: false key to options:
obj = qwe: 1, asd: 2
echo obj, clone: false
echo.logs.first().body[0] == obj #=> trueTODO: Add examples
There 3 ways to indeficate object:
- namespacePrefix
- namespace
- id
On log namespacePrefix, namespace and id join with . and save as cid:
echo 'Qwerty', namespacePrefix: 'app', namespace: 'controller', id: 42
echo.logs.first().cid # => "app.controller.42"Get first record:
echo.logs.first()To get all logs (array of log objects):
echo.logs.all()l = echo.logs
l.all()
l.first()TODO: Add more examples
To find logs with 'some' in body:
echo.logs.grep 'some' # => [{ body: ['Something'] }, { body: ['I want some LSD.']}]TODO: Add more examples
TODO: Add more examples
echo.shitHappened # => undefined
echo.define(shitHappened: 8)
echo.shitHappened # Log function with level of importance equal to 8TODO: Add examples
TODO: Add examples
TODO: Add examples
TODO: Add examples
You can create curried function with predefined options, like level, namespacePrefix etc
You can dump logs:
$.post \
'/logs',
log: echo.dump()If you're using an older browser which doesn't have native JSON support (i.e. IE 7), you'll need to include json2.js which adds legacy support.
By default dump level is 1:
echo.dump(0)
## => [ { body: [1, 2, "[object Object]"], …
echo.dump()
## => [ { body: [1, 2, { 1, 2, "[object Object]" }], …
echo.dump(2)
## => [ { body: [1, 2, { 1, 2, { 1, 2, "[object Object]" } }], …
## etcIf you want to get deep dump to serialise objects with circular references you should include cycle.js extension to the JSON object and pass -1 as level (be carefully, making dump may take a time).
echo.dump(-1)And restore dump with initializer:
e = Echo(dump)… or via call restore:
echo.restore(dump)TODO: Add examples
TODO: Add examples
This project uses Semantic Versioning for release numbering.
Currently this project in active development but no any releases yet.
Idea and code by @kossnocorp.
Check out full list of contributors.
Initialy sponsored by Evil Martians special for Wannafun.
The MIT License
Copyright (c) 2012 Sasha Koss
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.