Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

acho

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

acho - npm Package Compare versions

Comparing version 3.3.2 to 4.0.0

lib/Util.coffee

33

CHANGELOG.md

@@ -0,1 +1,34 @@

<a name="4.0.0"></a>
# 4.0.0 (2017-09-16)
* Add CNAME ([24b0839](https://github.com/achohq/acho/commit/24b0839))
* Add docs ([5f7bae2](https://github.com/achohq/acho/commit/5f7bae2))
* Add favicon ([3d186a9](https://github.com/achohq/acho/commit/3d186a9))
* Add more examples ([84dfb20](https://github.com/achohq/acho/commit/84dfb20))
* Add new colors ([8cd0a97](https://github.com/achohq/acho/commit/8cd0a97))
* Add skin cli example ([9efff8d](https://github.com/achohq/acho/commit/9efff8d))
* Adjust node version ([7aad823](https://github.com/achohq/acho/commit/7aad823))
* Expose constant ([63227d2](https://github.com/achohq/acho/commit/63227d2))
* Improve responsive ([00e3e77](https://github.com/achohq/acho/commit/00e3e77))
* Meta tweaks ([8e97b25](https://github.com/achohq/acho/commit/8e97b25))
* Move test inside package ([deefa92](https://github.com/achohq/acho/commit/deefa92))
* Prevent modify defaults ([3aa9e8e](https://github.com/achohq/acho/commit/3aa9e8e))
* Refactor docs ([a6b6ec8](https://github.com/achohq/acho/commit/a6b6ec8))
* Refactor examples ([0de11aa](https://github.com/achohq/acho/commit/0de11aa))
* Refactor tests ([9b7b540](https://github.com/achohq/acho/commit/9b7b540))
* Remove specific color comparison ([76ca470](https://github.com/achohq/acho/commit/76ca470))
* Remove unnecessary code ([68d49ea](https://github.com/achohq/acho/commit/68d49ea))
* Rename example ([3dff986](https://github.com/achohq/acho/commit/3dff986))
* timestamp → trace ([9163710](https://github.com/achohq/acho/commit/9163710))
* Tweaks ([55ee8da](https://github.com/achohq/acho/commit/55ee8da))
* Tweaks ([44041fc](https://github.com/achohq/acho/commit/44041fc))
* Tweaks ([bebf082](https://github.com/achohq/acho/commit/bebf082))
* Unify colorize methods ([2006c84](https://github.com/achohq/acho/commit/2006c84))
* Update cli example ([e8b2c7f](https://github.com/achohq/acho/commit/e8b2c7f))
* Update docs ([9296cab](https://github.com/achohq/acho/commit/9296cab))
* Use an collection of colors ([bffbc8e](https://github.com/achohq/acho/commit/bffbc8e))
* fix(package): update chalk to version 2.1.0 ([16b352e](https://github.com/achohq/acho/commit/16b352e))
<a name="3.3.2"></a>

@@ -2,0 +35,0 @@ ## 3.3.2 (2017-07-19)

1

index.js

@@ -1,3 +0,2 @@

'use strict'
require('coffee-script/register')
module.exports = require('./lib/Acho')
{
"name": "acho",
"description": "Simple & hackable log system for NodeJS.",
"homepage": "https://documentup.com/achohq/acho",
"version": "3.3.2",
"description": "The Hackable Log",
"homepage": "https://acho.js.org",
"version": "4.0.0",
"main": "./index.js",

@@ -30,3 +30,3 @@ "author": {

"dependencies": {
"chalk": "~1.1.1",
"chalk": "~2.1.0",
"coffee-script": "~1.12.4",

@@ -38,11 +38,12 @@ "fmt-obj": "~2.0.0",

"devDependencies": {
"acho-skin-cli": "latest",
"coveralls": "latest",
"date-utils": "latest",
"git-dirty": "latest",
"husky": "latest",
"lint-staged": "latest",
"mocha": "latest",
"nyc": "latest",
"set-dateout": "latest",
"prettier-standard": "latest",
"should": "latest",
"standard": "latest"
"standard": "latest",
"standard-markdown": "latest"
},

@@ -59,7 +60,20 @@ "engines": {

"coveralls": "nyc report --reporter=text-lcov | coveralls",
"lint": "standard lib",
"lint": "standard-markdown && standard",
"precommit": "lint-staged",
"pretest": "npm run lint",
"pretty": "prettier-standard index.js examples/**/*.js --single-quote",
"test": "nyc mocha"
},
"license": "MIT"
"license": "MIT",
"lint-staged": {
"*.js": [
"prettier-standard",
"git add"
]
},
"standard": {
"env": [
"mocha"
]
}
}
# acho
<p align="center">
<br>
<img src="https://i.imgur.com/qdpBpnw.gif" alt="acho">
<br>
</p>
![Last version](https://img.shields.io/github/tag/achohq/acho.svg?style=flat-square)

@@ -17,10 +11,10 @@ [![Build Status](http://img.shields.io/travis/achohq/acho/master.svg?style=flat-square)](https://travis-ci.org/achohq/acho)

> Simple & hackable log system for NodeJS.
> The &#x3C;hackeable /&#x3E; Log
# Why
# Features
* Easy to use, customize and extend.
* Expressive API with chaineable methods.
* Mininum dependencies, just focussing on one thing.
* Compatible with AMD/CommonJS or just global object in the browser.
* Different log levels skins.
* Beauty object interpolation.
* Diff & log trace support.
* Easy to customize, easy to hack.

@@ -33,69 +27,78 @@ ## Install

If you want to use it in the browser (powered by [Browserify](http://browserify.org/)):
## Usage
```bash
bower install acho --save
```
### Logging levels
and later add it to your HTML:
<p><details>
<summary>
<b>Examples</b>
</summary>
<ul><li><a href="./examples/levels.js">Defaults</a></li><li><a href="./examples/skin-cli.js">Skin CLI</a></li><li><a href="./examples/skin-syslog.js">Skin Syslog</a></li></ul>
</details></p>
```html
<script src="bower_components/acho/dist/acho.js"></script>
```
<p align="center">
<br>
<img src="docs/images/10.png" alt="acho">
<br>
</p>
## Usage
The first thing you need to do is create a new log instance:
### First steps
```js
const acho = require('acho')
const log = acho()
```
Acho exports itself according to UMD best practices, which means that no matter where you are using the library, you get a version tailored for your environment.
Then you can print a log based on the level:
If you're using a module loader (or Node), simple require the library as you would any other module.
```js
const acho = require('acho')
const log = acho()
If you're using a browser, the library falls back to attaching itself to window as the global `Acho`.
acho.info('hello world')
```
#### CommonJS
All methods are chainables:
```js
var Acho = require('acho');
var acho = Acho();
const acho = require('acho')
const log = acho()
acho
.info('hello world')
.error('something bad happens')
```
#### Global/Browser
Establishing the loglevel is a good way to filter out undesired information from output. The available levels by default are:
```js
var acho = Acho();
```
- `fatal` : Display calls to `.fatal()` messages.
- `error` : Display calls to `.fatal()`, `.error()` messages.
- `warn` : Display calls from `.fatal()`, `.error()`, `.warn()` messages.
- `info` : Display calls from `.fatal()`, `.error()`, `.warn()`, `info()` messages.
- `debug` : Display calls from `.fatal()`, `.error()`, `.warn()`, `info()`, `debug()` messages.
#### AMD
Additionally exists two special levels:
I don't personally use AMD, so I can't conjure an example, but it should work fine as well.
- `muted` : Avoid all output.
- `all` : Allow print all message types.
It's time to use it!
The default log level is `all`. You can define it in the constructor:
<p align="center">
<br>
<img src="docs/images/00.png" alt="acho">
<br>
</p>
```js
acho.info('hello world');
const acho = require('acho')
const log = acho({level: 'debug'})
```
All public methods are chainable:
or at runtime:
<p align="center">
<br>
<img src="docs/images/01.png" alt="acho">
<br>
</p>
```js
acho
.info('hello world')
.error('something bad happens');
log.level = 'debug'
```
Maybe you don't want to output the message, but store it for later use:
### Internal Store
Sometimes, when you are interacting with a logger you need to store the logs to be used later instead of print all of them.
We define `.push` as accumulator for store the log internally:
<p align="center">

@@ -108,7 +111,10 @@ <br>

```js
acho.push('success', 'good job', 'well done', 'great!');
console.log(acho.messages.success);
const acho = require('acho')
const log = acho()
log.push('success', 'good job', 'well done', 'great!')
console.log(log.messages.success)
```
If you want to print previously stored messages, just call the method `print`:
If you want to print previously stored messages, just call the method `.print`:

@@ -121,7 +127,5 @@ <p align="center">

```js
acho.print()
```
or you can retrieve the logs programatically from the internal storage at `acho.messages`
You might be thinking: Can I combine both, to store and both print a message? Absolutely!
The method `.add` combine `.push` and `.print` actions in one: It store the message internally but also print the log.

@@ -135,73 +139,22 @@ <p align="center">

```js
acho.add('info', 'this message is printed and stored');
log.add('info', 'this message is printed and stored')
console.log(acho.messages.info)
```
### Defining the level
### Formatters
Establishing the loglevel is a good way to filter out undesired information from output. The available levels by default are:
<p><details>
<summary>
<b>Examples</b>
</summary>
<ul><li><a href="./examples/interpolation.js">Interpolation</a></li></ul>
</details></p>
- `fatal` : Display calls to `.fatal()` messages.
- `error` : Display calls to `.fatal()`, `.error()` messages.
- `warn` : Display calls from `.fatal()`, `.error()`, `.warn()` messages.
- `info` : Display calls from `.fatal()`, `.error()`, `.warn()`, `info()` messages.
- `debug` : Display calls from `.fatal()`, `.error()`, `.warn()`, `info()`, `debug()` messages.
Additionally exists two special levels:
- `muted` : Avoid all output.
- `all` : Allow print all message types.
The default log level is `all`. You can define it in the constructor:
```js
var acho = Acho({level: 'debug'})
```
or at runtime:
```js
acho.level = 'debug';
```
See more at [examples/levels](https://github.com/achohq/acho/blob/master/examples/levels.js).
### Customization
You can completely customize the library to your requirements: changes colors, add more types, sort the priorities... the internal structure of the object is public and you can edit it dynamically. **You have the power**.
By default the messages structure is brief: Just the message type followed by the message itself.
But you can easily modify the output. For example, let's add a timestamp to each message:
<p align="center">
<br>
<img src="docs/images/05.png" alt="acho">
<img src="docs/images/09.png" alt="acho">
<br>
</p>
```js
var acho = Acho({
color: true,
level: 'debug',
// Customize how to print the 'type' of each message
outputType: function(type) {
return '[' + type + '] » ';
},
// Customize how to print the message.
// Add things before and/or after.
outputMessage: function(message) {
return Date() + ' :: ' + message;
}
});
acho.info('I am hungry');
```
If you need customize more the output you can setup `.print` `.generateMessage` (see below) that are a more low level methods for generate and print the output message.
## Formatters
We use [printf-style](https://wikipedia.org/wiki/Printf_format_string) formatting. Below are the officially supported formatters:

@@ -220,3 +173,6 @@

```js
acho.info({hello: 'world', foo: 'bar'})
const acho = require('acho')
const log = acho()
log.info({hello: 'world', foo: 'bar'})
// => 'info hello=world foo=bar'

@@ -228,3 +184,6 @@ ```

```js
acho.info('formatting with object interpolation %J', {
const acho = require('acho')
const log = acho()
log.info('formatting with object interpolation %J', {
hello: 'world',

@@ -237,28 +196,53 @@ foo: 'bar',

})
```
// info formatting with object interpolation
// hello: "world"
// foo: "bar"
// deep:
// foo: "bar"
// arr:
// 0: 1
// 1: 2
// 2: 3
// 3: 4
// 4: 5
### Customization
<p><details>
<summary>
<b>Examples</b>
</summary>
<ul><li><a href="./examples/trace.js">Trace & Diff</a></li><li><a href="./examples/uppercase.js">Uppercase</a></li></ul>
</details></p>
One of the **acho** compromise is be easy to adapt. You can completely customize all the library functionalities.
For example, suppose you want to add a timestamp before your logs:
<p align="center">
<br>
<img src="docs/images/05.png" alt="acho">
<br>
</p>
```js
const acho = require('acho')
const log = acho({
// Customize how to print the 'type' of each message
outputType: type => `[${type}]`,
// Customize how to print the message.
// Add things before and/or after.
outputMessage: message => `${Date.now()} :: ${message}`
})
acho.info('I am hungry')
```
See more at [examples/formatter](https://github.com/achohq/acho/blob/master/examples/formatter.js).
That's all.
## API
### Acho({Object} [options])
### acho([options])
Create a logger. Available options:
It creates a logger instance.
<img src="docs/images/07.png" align="right">
#### options
##### **{String}** keyword
##### keyword
![](docs/images/07.png)
Type: `string`</br>
Default: `loglevel`

@@ -270,6 +254,7 @@

<img src="docs/images/08.png" align="right">
##### align
##### **{String}** align
![](docs/images/08.png)
Type: `string`</br>
Default: `' '`

@@ -281,30 +266,34 @@

<img src="docs/images/06.png" align="right">
##### diff
##### **{Boolean}** diff
![](docs/images/06.png)
Type: `boolean`</br>
Default: `false`
Prints timestamp between log from the same level. Specially useful to debug timmings.
Prints trace between log from the same level. Specially useful to debug timings.
##### **{Boolean}** color
##### upperCase
![](docs/images/12.png)
Type: `boolean`</br>
Default: `false`.
Enable or disable colorized output.
Enable or disable print log level in upper case.
##### **{Boolean}** upperCase
##### trace
![](docs/images/11.png)
Type: `boolean`|`number`</br>
Default: `false`.
Enable or disable print log level in upper case.
Prints a numeric counter trace associated with each log line.
##### **{Number}** timestamp
The value provided is the minimum quantity of time in milliseconds to consider print a different counter.
Default: `0`.
##### offset
Prints a counter timestamp associated with each log line. Useful for debug log traces.
##### **{Number}** offset
Type: `number`</br>
Default: `2`.

@@ -316,4 +305,5 @@

##### **{Number}** depth
##### depth
Type: `number`</br>
Default: `Infinity`.

@@ -325,4 +315,5 @@

##### **{String}** level
##### level
Type: `string`</br>
Default: `all`

@@ -334,4 +325,5 @@

##### **{Function}** transport
##### transport
Type: `function`</br>
Default: `console.log`

@@ -341,38 +333,68 @@

##### **{Object}** types
##### types
Type: `object`
You can provide the types and priorities.
##### **{Object}** messages
##### messages
Type: `object`
It provides a initial internal store state per each log level. This option is useful when you want to integrate the logger with the ouptut of a delayed function.
##### **{Function}** print
##### print
Type: `function`
Provides a function that determines how to print the messages. By default uses `.generateMessage` for generate the mesage that will be outputted.
##### **{Function}** outputType
##### outputType
Type: `function`
Provides a function to customize the type in the output.
##### **{Function}** outputMessage
##### outputMessage
Type: `function`
Provides a function to customize the message in the output.
##### **{Function}** generateMessage
##### generateMessage
Type: `function`
Provides a function that generate the message to be outputted. It combines other internal methods for generate the output (as `.isPrintable` or `.colorize`) and normally you are not interested in the definition of it, but you can provide it as option as well.
##### **{Function}** generateTypeMessage
##### generateTypeMessage
Type: `function`
Provides a function used to generate the type message.
### .push({String} &lt;type&gt;, {String} &lt;message&gt;)
### .push(&lt;type&gt;, &lt;message&gt;)
Store a message of given `type` internally.
### .add({String} &lt;type&gt;, {String} &lt;message&gt;)
#### type
Type: `string`
#### message
Type: `string`
### .add(&lt;type&gt;, &lt;message&gt;)
Store a message of given `type` internally and also output it.
#### type
Type: `string`
#### message
Type: `string`
For each level you have a function following the pattern:

@@ -384,8 +406,15 @@

### .\[loglevel\]({String} &lt;message&gt;)
### .\[loglevel\](&lt;message&gt;)
For each log level that you declared in the constructor (or the default log levels provides by the library if you don't declare nothing) will be created a function with the same name to output a message with these log level.
#### message
Type: `string`
## License
MIT © [Kiko Beats](http://www.kikobeats.com)
**acho** © [Kiko Beats](https://kikobeats.com), Released under the [MIT](https://github.com/achohq/acho/pulls/blob/master/LICENSE.md) License.<br>
Authored and maintained by Kiko Beats with help from [contributors](https://github.com/achohq/acho/pulls/contributors).
> [kikobeats.com](https://kikobeats.com) · GitHub [Kiko Beats](https://github.com/kikobeats) · Twitter [@kikobeats](https://twitter.com/kikobeats)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc