Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien Motte committed Oct 11, 2017
0 parents commit eec28ca
Show file tree
Hide file tree
Showing 23 changed files with 12,836 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"presets": [
"es2015"
],
"plugins": [
"add-module-exports",
"transform-object-rest-spread"
],
"env": {
"development": {
"sourceMaps": "inline",
"plugins": [
"transform-runtime"
]
}
}
}
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
coverage
docs
lib
.nyc_output
.history
.vscode
*.log
.DS_Store
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
coverage
docs
.nyc_output
.history
.vscode
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
language: node_js
cache:
directories:
- node_modules
notifications:
email: false
node_js:
- 'node'
before_script:
- npm prune
script:
- npm test
after_success:
- npm run semantic-release
branches:
except:
- /^v\d+\.\d+\.\d+$/
25 changes: 25 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
The MIT License (MIT)
=====================

Copyright © 2017 Heng Patrick, Fabien Motte

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.
258 changes: 258 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
# [<img src="logo.png" alt="quark-log" width="200">](https://github.com/fm-ph/quark-log)

Simple configurable logging module.

___This package is part of `quark` framework but it can be used independently.___

![Preview](preview.png)

## Features

- **Levels** : Defaults (`log`, `info`, `warn`, `error`) and custom
- **Plugins** : Defaults and custom
- **Styling** : Per level/plugin
- **More** : Timer, group, reset...

## Installation

```sh
npm install quark-log --save
```

## Usage

### Basic

```js
import { Logger } from 'quark-log'

const logger = new Logger()

logger.log('Test')
logger.log('Test', { test: true })
logger.log('Test', 10, true)
```

#### Enable/disable logging

```js
import { Logger } from 'quark-log'

const logger = new Logger()

logger.off()
logger.log('This test will not be logged')
logger.on()
```

#### Grouping

```js
import { Logger } from 'quark-log'

const logger = new Logger()

logger.group('Group')
logger.log('Test grouping')
logger.groupEnd()
```

#### Timer

```js
import { Logger } from 'quark-log'

const logger = new Logger()

logger.time('timer')
// ...
logger.timeEnd('timer')
```

#### Handler

```js
import { Logger } from 'quark-log'

const logger = new Logger()

logger.setHandler(msgs => {
// msgs = ['Test', true]
})

logger.log('Test', true)
```

#### Reset

Reset levels and plugins.

```js
import { Logger, plugins } from 'quark-log'

const logger = new Logger()
logger.plugin('time', plugins.time)

logger.log('Test') // [15:00:00] Test
logger.reset()
logger.log('Test') // Test
```

### Levels

#### Defaults levels

```js
import { Logger } from 'quark-log'

const logger = new Logger()
logger.log('Log')
logger.info('Info')
logger.warn('Warn')
logger.error('Error')
```

#### Add a custom level

```js
import { Logger } from 'quark-log'

const logger = new Logger()
logger.level('custom')

logger.custom('My custom level')
```

#### Configure level options

```js
import { Logger } from 'quark-log'

const logger = new Logger()
logger.level('custom', {
styles: {
color: 'blue'
}
})

logger.custom('Test') // Will be logged in blue
```

### Plugins

#### Defaults plugins list

- [**time**](./src/plugins/time.js) : Append current time before user message
- [**namespace**](./src/plugins/namespace.js) : Append a custom namespace before user message

#### Use a default plugin

```js
import { Logger, plugins } from 'quark-log'

const logger = new Logger()
logger.plugin('time', plugins.time)

logger.log('Test') // [15:00:00] Test
```

#### Configure plugin options

```js
import { Logger, plugins } from 'quark-log'

const logger = new Logger()
logger.plugin('namespace', plugins.namespace, { name: 'test' })
logger.log('Test') // [test] Test

logger.plugin('namespace', { enabled: false })
logger.log('Test') // Test
```

#### Create a custom plugin

```js
import { Logger } from 'quark-log'

/**
* Plugin callback signature
*
* @param {Array} msgs User messages
* @param {Object} options Plugin options
* @param {Object} level Level
* @param {String} level.name Level name
* @param {Object} level.options Level options
*/
const myPlugin = (msgs, options, level) => {
return { before: `${options.myOption}:`, msgs, after: '', styles: {} }
}

const logger = new Logger()
logger.plugin('myPlugin', myPlugin, { myOption: 'My plugin' }) // This plugin append a custom string before each message

logger.log('Test') // My plugin: Test
```

## API

See [https://fm-ph.github.io/quark-log/](https://fm-ph.github.io/quark-log/)

## Build

To build the sources with `babel` in `./lib` directory :

```sh
npm run build
```

## Documentation

To generate the `JSDoc` :

```sh
npm run docs
```

To generate the documentation and deploy on `gh-pages` branch :

```sh
npm run docs:deploy
```

To serve the `JSDoc` :

```sh
npm run docs:serve
```

## Testing

To run the tests, first clone the repository and install its dependencies :

```sh
git clone https://github.com/fm_ph/quark-log.git
cd quark-log
npm install
```

Then, run the tests :

```sh
npm test
```

To watch (test-driven development) :

```sh
npm run test:watch
```

For coverage :

```sh
npm run test:coverage
```

## License

MIT [License](LICENSE.md) © [Patrick Heng](http://hengpatrick.fr/) [Fabien Motte](http://fabienmotte.com/)
5 changes: 5 additions & 0 deletions demo/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "quark-log-demo",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "MIT",
"browserify": {
"transform": [
"babelify"
]
}
}
17 changes: 17 additions & 0 deletions demo/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>quark-log</title>

<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">

<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<link rel="stylesheet" type="text/css" href="./style.css">
</head>

<body>
<script src="./bundle.js"></script>
</body>
</html>
Empty file added demo/public/style.css
Empty file.
Loading

0 comments on commit eec28ca

Please sign in to comment.