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

cedar

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cedar - npm Package Compare versions

Comparing version 0.0.19 to 0.1.0

lib/common/emitter.js

29

cedar.js
/**
* Get a logger with one or more transports.
* Create and return a logger with one or more transports.
*/
var cedar = module.exports = function (transport, options) {
if (!(transport instanceof Array)) {
transport = [transport || 'console'];
var cedar = module.exports = function (arg, config) {
// The default transport is `console`.
var transport = arg || 'console';
// If Cedar is called with an Array, it's a multi-transport config list.
if (arg instanceof Array) {
config = arg;
transport = 'multi';
}
return require('./lib/' + transport[0])(options);
// Make sure a config exists and a transport is specified.
config = config || {};
config.transport = transport;
return require('./lib/transports/' + transport)(config);
};
/**
* Expose the version to module users.
* Expose the Cedar version via package.json lazy loading.
*/
cedar.version = require('./package.json').version;
Object.defineProperty(cedar, 'version', {
get: function () {
return require('./package.json').version;
}
});
{
"name": "cedar",
"version": "0.1.0",
"description": "User-friendly logging",
"dependencies": {},
"devDependencies": {
"exam": "^0.1.3",
"zeriousify": "^0.1.10",
"istanbul": "0.2.11",
"coveralls": "2.10.0"
},
"keywords": [

@@ -15,7 +23,15 @@ "cedar",

],
"version": "0.0.19",
"main": "cedar.js",
"homepage": "https://github.com/lighterio/cedar",
"engines": {
"node": ">=0.2.6"
},
"scripts": {
"test": "./node_modules/exam/exam.js",
"cover": "./node_modules/istanbul/lib/cli.js cover ./node_modules/exam/exam.js",
"report": "open coverage/lcov-report/index.html",
"coveralls": "./node_modules/istanbul/lib/cli.js cover ./node_modules/exam/exam.js && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage"
},
"repository": "https://github.com/lighterio/cedar.git",
"bugs": "https://github.com/lighterio/cedar/issues",
"homepage": "https://github.com/lighterio/cedar",
"author": "Sam Eubank <sameubank@gmail.com>",

@@ -25,20 +41,3 @@ "contributors": [

],
"engines": [
"node >= 0.2.6"
],
"scripts": {
"test": "./node_modules/exam/exam.js",
"retest": "./node_modules/exam/exam.js --watch",
"cover": "istanbul cover ./node_modules/exam/exam.js",
"report": "open coverage/lcov-report/index.html",
"coveralls": "istanbul cover ./node_modules/exam/exam.js --report lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage"
},
"dependencies": {},
"devDependencies": {
"exam": "^0.0.7",
"zeriousify": "^0.1.9",
"istanbul": "0.2.11",
"coveralls": "2.10.0"
},
"license": "MIT"
}

@@ -1,4 +0,4 @@

# Cedar
[![NPM Version](https://img.shields.io/npm/v/cedar.svg) ![Downloads](https://img.shields.io/npm/dm/cedar.svg)](https://npmjs.org/package/cedar)
# <a href="http://lighter.io/cedar" style="font-size:40px;text-decoration:none;color:#000"><img src="https://cdn.rawgit.com/lighterio/lighter.io/master/public/cedar.svg" style="width:90px;height:90px"> Cedar</a>
[![NPM Version](https://img.shields.io/npm/v/cedar.svg)](https://npmjs.org/package/cedar)
[![Downloads](https://img.shields.io/npm/dm/cedar.svg)](https://npmjs.org/package/cedar)
[![Build Status](https://img.shields.io/travis/lighterio/cedar.svg)](https://travis-ci.org/lighterio/cedar)

@@ -9,8 +9,20 @@ [![Code Coverage](https://img.shields.io/coveralls/lighterio/cedar/master.svg)](https://coveralls.io/r/lighterio/cedar)

Cedar is a Node.js logging library that is designed to be fast, simple and
pretty. Its console transport shows color symbols before your log messages.
## TL;DR
## Getting started
Cedar is a Node.js logger, designed to be fast, extensible, and super useful.
### Powerful features
* Modifiable logging prefixes, formatters, and stringify functions.
* Loggers which are functions, allowing shorthand calls.
* A `console` transport with color unicode symbols and helpful code snippets
inside stack traces.
* A `file` transport that can rotate by day, hour or minute.
* A `multi` transport, which supports `cluster`, sending worker logs to the
master process.
### Quick Start
Add `cedar` to your dependencies.

@@ -21,41 +33,58 @@ ```bash

Create a stdout logger, and use it.
```javascript
var log = require('cedar')();
Create a logger, and use it.
```js
var log = require('cedar')([
{
transport: 'console' // Default.
level: 'trace' // Default.
},
{
transport: 'file',
level: 'info',
path: 'log/${YYYY}/${MM}/${DD}/app_${HOST}.log'
}
]);
log('Use a string.');
log('Log a string'); // Shorthand.
log.debug(['or', 'an', 'array']);
log.trace({or: 'JSON of course'});
log.log('and', 'multiple', 'arguments', 'are', 'supported.', true);
log.info('This message will also log to file, based on `level`.')
log(['Or'], ['an'], ['array']);
log.trace('This gets formatted as a trace message, with a stack trace');
log.debug('This gets formatted as a debug message.');
log.log('This gets formatted as a log message.');
log.info('This gets formatted as an info message.');
log.warn('This gets formatted as a warning message.', error);
log.error('This gets formatted as an error message.', error);
log.alert('This gets formatted as an alerting message.', error);
```
log({or: 'json, obviously'});
## Convention & Configuration
Each Cedar transport has properties with defaults that can be
overridden using a config object. They also have getters and
setters, allowing you to change them later.
log.debug('This will be preceded by a magenta diamond thingy.');
log.trace('This will be preceded by a cyan plus.');
log.log('This will be preceded by a grey arrow, as above.');
log.info('This will be preceded by a green check mark.');
log.warn('This will be preceded by a thick yellow asterisk.');
log.error('This will be preceded by a thick red X.');
```
For example:
```js
// Set the log `level` in a configuration object.
var log = require('cedar')({level: 'warn'}); // "warn", "error" and "alert".
## Logger customization
log('log'); // Ignore.
log.error('error'); // Log "error".
#### log.setFormat(function callback[, string type])
// Assign the `level`, thereby invoking its setter.
log.level = 'debug';
Customize the message format.
```javascript
var log = require('cedar')();
log.setFormat(function (message, prefix, type) {
return prefix + message + '!';
});
log('log'); // Log "log".
log.error('error'); // Log "error".
log.trace('trace'); // Ignore.
```
If you specify the optional `type` parameter, it will only change the formatter
for that type.
#### log.level `string`
#### log.setLevel(string level)
Change the level of log that is shown (default: `log`).
```javascript
Configures the minimum level of logging that is shown (default: `trace`).
```js
var log = require('cedar')();
log.setLogLevel('trace');
log.level = 'debug';
```

@@ -67,28 +96,26 @@

#### log.setPrefixes(object prefixes)
#### log.prefixes `object`
Customize prefixes for the console log messages.
```javascript
Customize prefixes for the color log messages.
```js
require('colors');
var log = require('cedar')();
log.setPrefixes({
debug: 'DEBUG '.magenta,
trace: 'TRACE '.cyan,
log: 'LOG '.grey,
info: 'INFO '.green,
warn: 'WARN '.yellow,
error: 'ERROR '.red
});
// You can also get the prefixes:
var prefixes = log.getPrefixes();
log.prefixes = {
trace: 'TRACE: '.cyan,
debug: 'DEBUG: '.magenta,
log: 'LOG: '.grey,
info: 'INFO: '.green,
warn: 'WARN: '.yellow,
error: 'ERROR: '.red,
alert: 'ALERT: '.red
};
```
#### log.setJsonSpace(string whitespace)
#### log.space `string`
Customize the spacing that JSON.stringify uses.
```javascript
Configures the spacing that stringify uses.
```js
var log = require('cedar')();
log.setJsonSpace(' ');
log.space = ' ';
```

@@ -98,33 +125,160 @@ The default is two spaces.

#### log.format `function`
Customize the message format, given 3 arguments.
```js
var log = require('cedar')();
log.format = function (message, prefix, type) {
return prefix + message + ' from log.' + type + '!';
});
log.info('Hello'); // "INFO Hello from log.info!"
```
## Transports
Cedar currently supports "console" and "file" transports.
Cedar currently supports 4 main transports: "base", "console", "file" and
"multi". Each transport takes an optional configuration object.
### Base
The base transport writes to a stream, and other transports extend it.
```js
var fs = require('fs');
var writeStream = fs.createWriteStream('my.log');
var base = require('cedar')('base', {stream: writeStream});
base.log('Write this string to `my.log`');
```
### Console
The console logger writes to `process.stdout` with pretty colors.
The `console` logger writes to `process.stdout` with pretty colors.
Console is the default transport, so the following are equivalent:
```javascript
```js
logger = require('cedar')();
logger = require('cedar')('console');
logger = require('cedar')('color');
```
### Base
### File
The base logger writes to a stream.
```javascript
var fs = require('fs');
var ws = fs.createWriteStream('my.log');
var logger = require('cedar')('base', {stream: ws});
logger.log('Write this string to a file');
The `file` logger writes JSON messages to a file. In addition, it acts as a
simple event emitter so you can receive notifications when file rotation
events occur.
```js
var file = require('cedar')('file', {
path: 'log/app_${YYYY}-${MM}-${DD}_${HH}:${NN}_${HOST}.log'
});
file.info('This will go into a file.');
var console = require('cedar')();
file.on('open', function (path) {
console.log('Opened "' + path + '" for logging.');
});
file.on('close', function (path) {
console.log('Closed "' + path + '".');
});
```
### File
The file logger writes JSON arrays to a file.
The default file path is `logs/cedar.log`.
```javascript
var logger = require('cedar')('file', {path: 'logs/cedar.log'});
logger.log('Write this string to a file');
### Multi
The `multi` logger writes to multiple loggers at once. Its configuration object
is an array of configurations with transports specified by a `transport`
property.
```js
var log = require('cedar')([
{transport: 'console'},
{transport: 'file', level: 'info', path: 'log/app_${YYYY}-${MM}-${DD}_${HOST}.log'},
{transport: 'file', level: 'error', path: 'log/${YYYY}/${MM}/${DD}/error_${HOST}.log'}
]);
```
## Acknowledgements
We would like to thank all of the amazing people who use, support,
promote, enhance, document, patch, and submit comments & issues.
Cedar couldn't exist without you.
Additionally, huge thanks go to [TUNE](http://www.tune.com) for employing
and supporting [Cedar](http://lighter.io/cedar) project maintainers,
and for being an epically awesome place to work (and play).
## MIT License
Copyright (c) 2014 Sam Eubank
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.
## How to Contribute
We welcome contributions from the community and are happy to have them.
Please follow this guide when logging issues or making code changes.
### Logging Issues
All issues should be created using the
[new issue form](https://github.com/lighterio/cedar/issues/new).
Please describe the issue including steps to reproduce. Also, make sure
to indicate the version that has the issue.
### Changing Code
Code changes are welcome and encouraged! Please follow our process:
1. Fork the repository on GitHub.
2. Fix the issue ensuring that your code follows the
[style guide](http://lighter.io/style-guide).
3. Add tests for your new code, ensuring that you have 100% code coverage.
(If necessary, we can help you reach 100% prior to merging.)
* Run `npm test` to run tests quickly, without testing coverage.
* Run `npm run cover` to test coverage and generate a report.
* Run `npm run report` to open the coverage report you generated.
4. [Pull requests](http://help.github.com/send-pull-requests/) should be made
to the [master branch](https://github.com/lighterio/cedar/tree/master).
### Contributor Code of Conduct
As contributors and maintainers of Cedar, we pledge to respect all
people who contribute through reporting issues, posting feature requests,
updating documentation, submitting pull requests or patches, and other
activities.
If any participant in this project has issues or takes exception with a
contribution, they are obligated to provide constructive feedback and never
resort to personal attacks, trolling, public or private harassment, insults, or
other unprofessional conduct.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, edits, issues, and other contributions
that are not aligned with this Code of Conduct. Project maintainers who do
not follow the Code of Conduct may be removed from the project team.
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by opening an issue or contacting one or more of the project
maintainers.
We promise to extend courtesy and respect to everyone involved in this project
regardless of gender, gender identity, sexual orientation, ability or
disability, ethnicity, religion, age, location, native language, or level of
experience.
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