Skip to content

Commit c8bfecd

Browse files
author
bastien eichenberger
committed
variables declaration
1 parent e242260 commit c8bfecd

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/helper/log/log.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/** * Module to log stuff<br> * @license Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) http://creativecommons.org/licenses/by-sa/3.0/ <br> * {@link http://www.indd-skript.de/ | idshelper original code} * @namespace Log * @memberOf H * @author Gregor Fellenz * @author Bastien Eichenberger (add some modifications) * @todo clean up the code, separate translations */H.Log = (function (my) { // ------------------------------------------- private --------------------------------------------------- var info_str = {en: "Info", fr: "Information"}; var warn_str = {en: "Warning", fr: "Avertissement"}; var error_str = {en: "Error", fr: "Erreur"}; var consult_log_file_str = {en: "for more informations read the log file", fr: "pour plus d'informations consultez le fichier log"}; /** * The different log levels * @type {Array} */ var SEVERITY = []; SEVERITY["OFF"] = 4; SEVERITY["ERROR"] = 3; SEVERITY["WARN"] = 2; SEVERITY["INFO"] = 1; SEVERITY["DEBUG"] = 0; /** * The log file * @type {File} the file where the logs are written */ var logFile = null; /** * the log level as Number * @type {number} */ var logLevel = null; /** * This function write a log with its severity and its content in the log file * @param {String} _message the message to log * @param {String} _severity the severity [DEBUG, INFO, WARN, ERROR, OFF] */ function writeLog (_message, _severity) { try { logFile.open("e"); logFile.seek(logFile.length); } catch (ex) { alert('the log file do not exist, please init the Logger before using it \n' + 'line: ' + $.line + '\n' + 'file: ' + $.fileName + '\n' ); } try { logFile.writeln(Date() + " [" + _severity + "] " + ((_severity.length == 4) ? " [" : "[") + app.activeScript.name + "] " + _message); } catch (e) { //We're running from ESTK logFile.writeln(Date() + " [" + _severity + "] " + ((_severity.length == 4) ? " [" : "[") + "ESTK] " + _message); } logFile.close(); } // ------------------------------------------- public --------------------------------------------------- /** * Function to init the logger * @function init * @memberOf H.Log * @param {Folder} log_dir * @param {Number} log_level */ my.init = function (log_dir, log_level) { if (!log_dir.exists) { log_dir.create(); } if (!logFile) { logFile = new File(log_dir + '/log.log'); } logLevel = log_level; } /** * Function to writes a debug log message * @function debug * @memberOf H.Log * @param {String} _message Message to log. */ my.debug = function (_message) { if (logLevel <= 0) writeLog(_message, "DEBUG"); }; /** * Function to writes a info log message * @function info * @memberOf H.Log * @param {String} _message Message to log. */ my.info = function (_message) { if (logLevel <= 1) writeLog(_message, "INFO"); }; /** * Function to writes a info message and alert the user * @function infoAlert * @memberOf H.Log * @param {String} _message Message to log. */ my.infoAlert = function (_message) { if (logLevel <= 1) { writeLog(_message, "INFO"); alert(localize(info_str) + "\n" + _message + "\n\n" + localize(consult_log_file_str) + ":\n" + logFile); } }; /** * Function to writes a warn log message * @function warn * @memberOf H.Log * @param {String} _message Message to log. */ my.warn = function (_message) { if (logLevel <= 2) writeLog(_message, "WARN"); }; /** * Function to writes a warn log message and displays an Alert-Window * @function warnAlert * @memberOf H.Log * @param {String} _message Message to log. */ my.warnAlert = function (_message) { if (logLevel <= 2) { writeLog(_message, "WARN"); alert(localize(warn_str) + "\n" + _message + "\n\n" + localize(consult_log_file_str) + ":\n" + logFile); } }; /** * Function to writes an error log message * @function error * @memberOf H.Log * @param {String} _message Message to log. */ my.error = function (_message) { if (logLevel <= 3) writeLog(_message, "ERROR"); }; /** * Function to writes an error message and displays an alert * @function errorAlert * @memberOf H.Log * @param {String} _message Message to log. */ my.errorAlert = function (_message) { if (logLevel <= 3) { writeLog(_message, "ERROR"); alert(localize(error_str) + "\n" + _message + "\n\n" + localize(consult_log_file_str) + ":\n" + logFile); } }; return my;})(H.Log || {});
1+
/** * Module to log stuff<br> * @license Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) http://creativecommons.org/licenses/by-sa/3.0/ <br> * {@link http://www.indd-skript.de/ | idshelper original code} * @namespace Log * @memberOf H * @author Gregor Fellenz * @author Bastien Eichenberger (add some modifications) * @requires {@String H} */H.Log = (function (my) { /*********************************************** * Privates ***********************************************/ var log_file, log_level; /** * This function write a log with its severity and its content in the log file * @param {String} message the message to log * @param {String} severity the severity [DEBUG, INFO, WARN, ERROR, OFF] */ function write_log (message, severity) { var str; try { log_file.open("e"); log_file.seek(log_file.length); } catch (ex) { throw { name: 'InvalidArgumentError', message: 'the log file do not exist, please init the Logger before using it', fileName: $.fileName, lineNumber: $.line }; } try { str = '%s [%s] [%s] %s'; str = str.printf(Date(), severity, app.activeScript.name, message); }catch (e) { //We're running from ESTK str = '%s [%s] [ESTK] %s'; str = str.printf(Date(), severity, message); } log_file.writeln(str); log_file.close(); } /*********************************************** * Publics ***********************************************/ /** * Function to init the logger * @function init * @memberOf H.Log * @param {Folder} log_dir * @param {Number} log_level */ my.init = function (log_dir, log_level) { if (!log_dir.exists) { log_dir.create(); } if (!log_file) { log_file = new File(log_dir + '/log.log'); } log_level = log_level; } /** * Function to writes a debug log message * @function debug * @memberOf H.Log * @param {String} _message Message to log. */ my.debug = function (message) { if (log_level <= 0) { write_log(message, 'DEBUG'); } }; /** * Function to writes a info log message * @function info * @memberOf H.Log * @param {String} _message Message to log. */ my.info = function (message) { if (log_level <= 1) { write_log(message, 'INFO'); } }; /** * Function to writes a warn log message * @function warn * @memberOf H.Log * @param {String} _message Message to log. */ my.warn = function (message) { if (log_level <= 2) { write_log(message, 'WARN'); } }; /** * Function to writes an error log message * @function error * @memberOf H.Log * @param {String} _message Message to log. */ my.error = function (message) { if (log_level <= 3) { write_log(message, 'ERROR'); } }; return my;})(H.Log || {});

0 commit comments

Comments
 (0)