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.10 to 0.0.11

11

cedar.js
/**
* Get a logger with one or more transports.
*/
var cedar = module.exports = function (transport) {
if (!(transport instanceof Array)) {
transport = [transport || 'console'];
}
// TODO: Support multiple transports.
return require('./lib/' + transport[0])();
var cedar = module.exports = function (transport, options) {
if (!(transport instanceof Array)) {
transport = [transport || 'console'];
}
return require('./lib/' + transport[0])(options);
}

@@ -11,0 +10,0 @@

@@ -7,4 +7,6 @@ var logMethods = ['error', 'warn', 'info', 'log', 'trace', 'debug'];

*/
module.exports = function createLogger(transportType) {
module.exports = function createLogger(options) {
var options = options || {};
var logger = function logger() {

@@ -20,4 +22,2 @@ logger.log.apply(logger, arguments);

var stream = process.stdout;
var prefixes = {};

@@ -35,4 +35,6 @@

logger.type = transportType;
logger.type = options.type || 'base';
logger.stream = options.stream || process.stdout;
logger.setLevel = function setLevel(level) {

@@ -134,3 +136,3 @@ var number;

var message = logger.stringifyArguments(args);
stream.write(format[type](message, type) + '\n');
logger.stream.write(format[type](message, type) + '\n');
};

@@ -137,0 +139,0 @@

@@ -7,5 +7,5 @@ var base = require('./base');

module.exports = function createBlackholeLogger() {
var logger = base('blackhole');
var logger = base({type: 'blackhole'});
logger.write = function () {};
return logger;
};

@@ -26,5 +26,5 @@ var fs = require('fs');

var logger = base('console');
var logger = base({type: 'console'});
logger.setPrefixes({
logger.setPrefixes({
debug: magenta + '\u2756 ' + bash,

@@ -31,0 +31,0 @@ trace: cyan + '\u271A ' + bash,

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

var Logger = require('./Logger');
var fs = require('fs');
var base = require('./base');

@@ -6,4 +7,70 @@ /**

*/
module.exports = Logger.extend({
module.exports = function createFileLogger(options) {
});
var options = options || {};
var queuedWrites = [];
var logger = base({type: 'file', stream: {
write: function (message) {
queuedWrites.push(message);
}
}});
logger.setJsonSpace(null);
var format;
logger.write = function (message, type) {
return logger.stream.write(format(message, type) + '\n');
};
logger.setFormat = function (value) {
format = value;
};
logger.setFormat(function(message, type) {
return JSON.stringify([new Date(), type, message]);
});
function createStream(path) {
logger.stream = fs.createWriteStream(path, {flags: 'a'});
queuedWrites.forEach(function (data) {
logger.stream.write(data);
});
delete queuedWrites;
}
var path = options.path || process.cwd() + '/logs/cedar.log';
fs.exists(path, function(exists) {
if (exists) {
createStream(path);
}
else {
var parts = path.split('/');
filename = parts.pop();
directory = '' + parts.shift();
function writePart(done) {
directory += '/' + parts.shift();
fs.mkdir(directory, function madeDirForAssetWrite(err) {
if (parts.length) {
writePart(done);
} else {
var path = directory + '/' + filename;
done();
}
});
}
writePart(function () {
createStream(path);
});
}
});
return logger;
};

@@ -15,3 +15,3 @@ {

],
"version": "0.0.10",
"version": "0.0.11",
"main": "cedar.js",

@@ -18,0 +18,0 @@ "homepage": "http://github.com/zerious/cedar",

@@ -38,3 +38,3 @@ # Cedar

## Default logger customization
## Logger customization

@@ -96,4 +96,33 @@ #### log.setFormat(function callback[, string type])

## Roadmap
## Transports
Cedar will soon support file transports and more.
Cedar currently supports "console" and "file" transports.
### Console
The console logger writes to `process.stdout` with pretty colors.
Console is the default transport, so the following are equivalent:
```javascript
logger = require('cedar')();
logger = require('cedar')('console');
```
### Base
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');
```
### 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');
```
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