Ghost/core/server/config/utils.js
Katharina Irrgang 0e13ef8767 🎨 logging improvements (#7597)
* 🎨  rotation config
  - every parameter is configureable
  - increase default number of files to 100
* 🎨  ghost.log location
  - example: content/logs/http___my_ghost_blog_com_ghost.log
  - user can change the path to something custom by setting logging.path
* 🛠   add response-time as dependency
* 🎨  readable PrettyStream
  - tidy up
  - generic handling (was important to support more use cases, for example: logging.info({ anyKey: anyValue }))
  - common log format
  - less code 🕵🏻
* 🎨  GhostLogger cleanup
  - remove setLoggers -> this function had too much of redundant code
  - instead: add smart this.log function
  - remove logging.request (---> GhostLogger just forwards the values, it doesn't matter if that is a request or not a request)
  - make .warn .debug .info .error small and smart
* 🎨  app.js: add response time as middleware and remove logging.request
* 🎨  setStdoutStream and setFileStream
  - redesign GhostLogger to add CustomLoggers very easily

----> Example CustomLogger

function CustomLogger(options) {
  // Base iterates over defined transports
  // EXAMPLE: ['stdout', 'elasticsearch']
  Base.call(this, options);
}
util.inherits(...);

// OVERRIDE default stdout stream and your own!!!
CustomLogger.prototype.setStdoutStream = function() {}

// add a new stream
// get's called automatically when transport elasticsearch is defined
CustomLogger.prototype.setElasticsearchStream = function() {}

* 🎨  log into multiple file by default
  - content/logs/domain.error.log --> contains only the errors
  - content/logs/domain.log --> contains everything
  - rotation for both files
* 🔥  remove logging.debug and use npm debug only
*   shortcuts for mode and level
* 🎨  jshint/jscs
* 🎨  stdout as much as possible for an error
* 🎨  fix tests
* 🎨  remove req.ip from log output, remove response-time dependency
* 🎨  create middleware for logging
  - added TODO to move logging middleware to ignition
2016-10-25 12:17:43 +01:00

77 lines
2.5 KiB
JavaScript

var path = require('path'),
_ = require('lodash'),
errors = require('../errors');
exports.isPrivacyDisabled = function isPrivacyDisabled(privacyFlag) {
if (!this.get('privacy')) {
return false;
}
if (this.get('privacy').useTinfoil === true) {
return true;
}
return this.get('privacy')[privacyFlag] === false;
};
/**
* transform all relative paths to absolute paths
* @TODO: imagesRelPath is a dirty little attribute (especially when looking at the usages)
* @TODO: re-write this function a little bit so we don't have to add the parent path - that is hard to understand
*
* Path must be string.
* Path must match minimum one / or \
* Path can be a "." to re-present current folder
*/
exports.makePathsAbsolute = function makePathsAbsolute(obj, parent) {
var self = this;
if (!obj) {
throw new errors.IncorrectUsageError({
message: 'makePathsAbsolute: Object is missing.'
});
}
if (!parent) {
throw new errors.IncorrectUsageError({
message: 'makePathsAbsolute: Parent is missing.'
});
}
_.each(obj, function (configValue, pathsKey) {
if (_.isObject(configValue)) {
makePathsAbsolute.bind(self)(configValue, parent + ':' + pathsKey);
} else {
if (_.isString(configValue) &&
(configValue.match(/\/+|\\+/) || configValue === '.') &&
(configValue[0] !== '/' && configValue[0] !== '\\') &&
pathsKey !== 'imagesRelPath'
) {
self.set(parent + ':' + pathsKey, path.join(__dirname + '/../../../', configValue));
}
}
});
};
/**
* we can later support setting folder names via custom config values
*/
exports.getContentPath = function getContentPath(type) {
switch (type) {
case 'storage':
return path.join(this.get('paths:contentPath'), 'storage/');
case 'images':
return path.join(this.get('paths:contentPath'), 'images/');
case 'apps':
return path.join(this.get('paths:contentPath'), 'apps/');
case 'themes':
return path.join(this.get('paths:contentPath'), 'themes/');
case 'scheduling':
return path.join(this.get('paths:contentPath'), 'scheduling/');
case 'logs':
return path.join(this.get('paths:contentPath'), 'logs/');
default:
throw new Error('getContentPath was called with: ' + type);
}
};