First attempt, browser 1st
This commit is contained in:
parent
87d348719b
commit
b350041ab4
48
README.md
48
README.md
|
@ -1,3 +1,49 @@
|
||||||
# tagol
|
# tagol
|
||||||
|
|
||||||
Another logger using template literals for nodejs and browsers
|
Another logger using template literals for nodejs and browsers
|
||||||
|
|
||||||
|
WIP !
|
||||||
|
|
||||||
|
## Load
|
||||||
|
|
||||||
|
### Browsers
|
||||||
|
|
||||||
|
```html
|
||||||
|
<script src="//unpckg.org/tagol/tagol.js"></script>
|
||||||
|
or
|
||||||
|
<script type="module">
|
||||||
|
import log from '//unpckg.org/tagol/tagol.js'
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Nodejs
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
require('tagol')
|
||||||
|
or
|
||||||
|
import 'tagol'
|
||||||
|
or
|
||||||
|
import log from 'tagol'
|
||||||
|
or
|
||||||
|
import { I: info, E: error } from 'tagol'
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
log `Some simple output`
|
||||||
|
|
||||||
|
log.S `Success`
|
||||||
|
log.W `Warning`
|
||||||
|
log.I `Info`
|
||||||
|
log.E `Error`
|
||||||
|
|
||||||
|
log `Some
|
||||||
|
multiline
|
||||||
|
text`
|
||||||
|
|
||||||
|
let substitution = { text: 'foo', obj: {some: 42} }
|
||||||
|
log.E `Error with ${substitution.text}s on object ${substitution.obj}o !`
|
||||||
|
```
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
{
|
||||||
|
"name": "tagol",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Another logger using template literals for nodejs and browsers",
|
||||||
|
"main": "tagol.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://git.p2p.legal/dig/tagol.git"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://git.p2p.legal/dig/tagol/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://git.p2p.legal/dig/tagol",
|
||||||
|
"keywords": [
|
||||||
|
"tagol",
|
||||||
|
"color",
|
||||||
|
"colour",
|
||||||
|
"cli",
|
||||||
|
"log",
|
||||||
|
"logger",
|
||||||
|
"logging",
|
||||||
|
"debug",
|
||||||
|
"message",
|
||||||
|
"error",
|
||||||
|
"tty",
|
||||||
|
"terminal",
|
||||||
|
"console",
|
||||||
|
"shell",
|
||||||
|
"xterm",
|
||||||
|
"ansi",
|
||||||
|
"command-line",
|
||||||
|
"text",
|
||||||
|
"string",
|
||||||
|
"str",
|
||||||
|
"literal",
|
||||||
|
"tag",
|
||||||
|
"tagged",
|
||||||
|
"template",
|
||||||
|
"format",
|
||||||
|
"formatting",
|
||||||
|
"style",
|
||||||
|
"es",
|
||||||
|
"es6",
|
||||||
|
"esnext",
|
||||||
|
"es2015",
|
||||||
|
"es2016",
|
||||||
|
"es6-tag"
|
||||||
|
],
|
||||||
|
"author": {
|
||||||
|
"name": "Thomas Di Grégorio",
|
||||||
|
"email": "dig@p2p.legal"
|
||||||
|
},
|
||||||
|
"license": "GPL-3.0",
|
||||||
|
"dependencies": {
|
||||||
|
"log-symbols": "^3.0.0"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
const syms = require('log-symbols')
|
||||||
|
|
||||||
|
// console fun with tagged String litteralstremplate
|
||||||
|
// To deactivate debug
|
||||||
|
// log.noop()
|
||||||
|
|
||||||
|
;(function( global )
|
||||||
|
{
|
||||||
|
var log = (ss,...pp)=> log.level > 2 && console.log.apply( console, [ss.join('%')].concat(pp) )
|
||||||
|
log.level = 3; // 0> nothing, 1> errors, 2> infos, 3> logs, 4> accessors, 5> proxies
|
||||||
|
log.S = (ss,...pp)=> log.level > 2 && console.info.apply( console, [syms.success+' '+ss.join('%')].concat(pp) )
|
||||||
|
log.W = (ss,...pp)=> log.level > 1 && console.log.apply( console, [syms.warning+' '+ss.join('%')].concat(pp) )
|
||||||
|
log.I = (ss,...pp)=> log.level > 1 && console.info.apply( console, [syms.info+' '+ss.join('%')].concat(pp) )
|
||||||
|
log.E = (ss,...pp)=> log.level > 0 && console.error.apply( console, [syms.error+' '+ss.join('%')].concat(pp) )
|
||||||
|
log.G = (ss,...pp)=> log.level > 2 && console.groupCollapsed.apply( console, [ss.join('%')].concat(pp) )
|
||||||
|
|
||||||
|
log.noop = ()=> { log = o=>o; log.S = log.W = log.I = log.G = log.E = log; global.log = log }
|
||||||
|
global.log = log
|
||||||
|
|
||||||
|
})( global || window )
|
||||||
|
|
Loading…
Reference in New Issue