UNPKG

@attivio/suit

Version:

Attivio SUIT, the Search UI Toolkit, is a library for creating search clients for searching the Attivio platform.

104 lines (76 loc) 4.01 kB
'use strict'; exports.__esModule = true; var _class, _temp; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _Configurable = require('./Configurable'); var _Configurable2 = _interopRequireDefault(_Configurable); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var Logger = (_temp = _class = function (_React$Component) { _inherits(Logger, _React$Component); Logger.info = function info(message) { var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'general'; var error = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; Logger.instance.sendInfo('info', message, context, error); }; Logger.error = function error(message) { var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'general'; var _error = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; Logger.instance.sendInfo('error', message, context, _error); }; Logger.debug = function debug(message) { var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'general'; var error = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; Logger.instance.sendInfo('debug', message, context, error); }; Logger.warn = function warn(message) { var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'general'; var error = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; Logger.instance.sendInfo('warn', message, context, error); }; function Logger(props) { _classCallCheck(this, Logger); var _this = _possibleConstructorReturn(this, _React$Component.call(this, props)); Logger.instance = _this; return _this; } Logger.prototype.sendInfo = function sendInfo(level, message, context) { var error = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; var headers = new Headers({ Accept: 'application/json', 'Content-Type': 'application/json' }); var payload = { level: level, message: message, context: context, error: error }; var body = JSON.stringify(payload); var params = { method: 'POST', headers: headers, body: body }; var uri = this.props.baseUri + '/rest/loggingApi/log'; var request = new Request(uri, params); fetch(request).then(function (result) { if (!result.ok) { console.log('Failed to log error to the server:\n' + message, result.statusText); // eslint-disable-line no-console } }).catch(function (e) { console.log('Failed to log error to the server:\n' + message, e); // eslint-disable-line no-console }); }; Logger.prototype.render = function render() { return null; }; return Logger; }(_react2.default.Component), _class.defaultProps = { baseUri: '' }, _class.displayName = 'Logger', _temp); exports.default = (0, _Configurable2.default)(Logger); module.exports = exports['default'];