mirror of
https://github.com/psychopy/psychojs.git
synced 2025-05-10 10:40:54 +00:00
156 lines
6.0 KiB
HTML
156 lines
6.0 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>JSDoc: Source: util/Logger.js</title>
|
|
|
|
<script src="scripts/prettify/prettify.js"> </script>
|
|
<script src="scripts/prettify/lang-css.js"> </script>
|
|
<!--[if lt IE 9]>
|
|
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
<![endif]-->
|
|
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="main">
|
|
|
|
<h1 class="page-title">Source: util/Logger.js</h1>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<section>
|
|
<article>
|
|
<pre class="prettyprint source linenums"><code>/**
|
|
* Logger
|
|
*
|
|
* @author Alain Pitiot
|
|
* @version 3.0.1
|
|
* @copyright (c) 2019 Ilixa Ltd. ({@link http://ilixa.com})
|
|
* @license Distributed under the terms of the MIT License
|
|
*/
|
|
|
|
|
|
import * as util from '../util/Util';
|
|
|
|
|
|
/**
|
|
* <p>This class handles a variety of loggers, e.g. a browser console one (mostly for debugging), a remote one, etc.</p>
|
|
*
|
|
* <p>Note: we use log4javascript.</p>
|
|
*
|
|
* @name module:util.Logger
|
|
* @class
|
|
* @param {*} threshold - the logging threshold, e.g. log4javascript.Level.ERROR
|
|
*/
|
|
export class Logger {
|
|
|
|
constructor(threshold) {
|
|
// browser console logger:
|
|
this.consoleLogger = log4javascript.getLogger('psychojs');
|
|
|
|
const appender = new log4javascript.BrowserConsoleAppender();
|
|
appender.setLayout(this._customConsoleLayout());
|
|
appender.setThreshold(threshold);
|
|
|
|
this.consoleLogger.addAppender(appender);
|
|
this.consoleLogger.setLevel(threshold);
|
|
|
|
|
|
/*
|
|
let appender = new log4javascript.AjaxAppender('https://pavlovia.org/server?command=log');
|
|
appender.setBatchSize(5);
|
|
appender.setSendAllOnUnload(true);
|
|
//appender.setFailCallback();
|
|
|
|
let jsonLayout = new log4javascript.JsonLayout([false, true]);
|
|
appender.setLayout(jsonLayout);*/
|
|
}
|
|
|
|
|
|
/**
|
|
* Create a custom console layout.
|
|
*
|
|
* @name module:util.Logger#_customConsoleLayout
|
|
* @private
|
|
* @return {*} the custom layout
|
|
*/
|
|
_customConsoleLayout() {
|
|
const customLayout = new log4javascript.PatternLayout("%p %f{1} | %m");
|
|
|
|
customLayout.setCustomField('location', function (layout, loggingReference) {
|
|
// we throw a fake exception to retrieve the stack trace
|
|
try { (0)() } catch (e) {
|
|
const stackEntries = e.stack.replace(/^.*?\n/, '').replace(/(?:\n@:0)?\s+$/m, '').replace(/^\(/gm, '{anon}(').split("\n");
|
|
|
|
let relevantEntry;
|
|
const browser = util.detectBrowser();
|
|
if (browser == 'Firefox') {
|
|
// look for entry immediately after those of log4javascript:
|
|
for (let entry of stackEntries)
|
|
if (entry.indexOf('log4javascript.min.js') <= 0) {
|
|
relevantEntry = entry;
|
|
break;
|
|
}
|
|
|
|
const buf = relevantEntry.split(':');
|
|
const line = buf[buf.length - 2];
|
|
const file = buf[buf.length - 3].split('/').pop();
|
|
const method = relevantEntry.split('@')[0];
|
|
|
|
return method + ' ' + file + ' ' + line;
|
|
}
|
|
else if (browser == 'Safari') {
|
|
return 'unknown';
|
|
}
|
|
else if (browser == 'Chrome') {
|
|
relevantEntry = stackEntries.pop();
|
|
|
|
let buf = relevantEntry.split(' ');
|
|
let fileLine = buf.pop();
|
|
const method = buf.pop();
|
|
buf = fileLine.split(':'); buf.pop();
|
|
const line = buf.pop();
|
|
const file = buf.pop().split('/').pop();
|
|
|
|
return method + ' ' + file + ' ' + line;
|
|
|
|
}
|
|
else
|
|
return 'unknown';
|
|
}
|
|
});
|
|
|
|
return customLayout;
|
|
}
|
|
|
|
}
|
|
</code></pre>
|
|
</article>
|
|
</section>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<nav>
|
|
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-core.html">core</a></li><li><a href="module-data.html">data</a></li><li><a href="module-sound.html">sound</a></li><li><a href="module-util.html">util</a></li><li><a href="module-visual.html">visual</a></li></ul><h3>Classes</h3><ul><li><a href="module-core.BuilderKeyResponse.html">BuilderKeyResponse</a></li><li><a href="module-core.EventManager.html">EventManager</a></li><li><a href="module-core.GUI.html">GUI</a></li><li><a href="module-core.MinimalStim.html">MinimalStim</a></li><li><a href="module-core.Mouse.html">Mouse</a></li><li><a href="module-core.PsychoJS.html">PsychoJS</a></li><li><a href="module-core.ServerManager.html">ServerManager</a></li><li><a href="module-core.Window.html">Window</a></li><li><a href="module-data.ExperimentHandler.html">ExperimentHandler</a></li><li><a href="module-data.TrialHandler.html">TrialHandler</a></li><li><a href="module-sound.Sound.html">Sound</a></li><li><a href="module-sound.TonePlayer.html">TonePlayer</a></li><li><a href="module-sound.TrackPlayer.html">TrackPlayer</a></li><li><a href="module-util.Clock.html">Clock</a></li><li><a href="module-util.Color.html">Color</a></li><li><a href="module-util.CountdownTimer.html">CountdownTimer</a></li><li><a href="module-util.EventEmitter.html">EventEmitter</a></li><li><a href="module-util.Logger.html">Logger</a></li><li><a href="module-util.MixinBuilder.html">MixinBuilder</a></li><li><a href="module-util.MonotonicClock.html">MonotonicClock</a></li><li><a href="module-util.PsychObject.html">PsychObject</a></li><li><a href="module-util.Scheduler.html">Scheduler</a></li><li><a href="module-visual.ImageStim.html">ImageStim</a></li><li><a href="module-visual.MovieStim.html">MovieStim</a></li><li><a href="module-visual.Rect.html">Rect</a></li><li><a href="module-visual.ShapeStim.html">ShapeStim</a></li><li><a href="module-visual.Slider.html">Slider</a></li><li><a href="module-visual.TextStim.html">TextStim</a></li><li><a href="module-visual.VisualStim.html">VisualStim</a></li></ul><h3>Mixins</h3><ul><li><a href="module-core.WindowMixin.html">WindowMixin</a></li><li><a href="module-util.ColorMixin.html">ColorMixin</a></li></ul><h3>Interfaces</h3><ul><li><a href="module-sound.SoundPlayer.html">SoundPlayer</a></li></ul>
|
|
</nav>
|
|
|
|
<br class="clear">
|
|
|
|
<footer>
|
|
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Mar 12 2019 08:55:12 GMT+0100 (CET)
|
|
</footer>
|
|
|
|
<script> prettyPrint(); </script>
|
|
<script src="scripts/linenumber.js"> </script>
|
|
</body>
|
|
</html>
|