UNPKG

nosqldb-oraclejs

Version:

Oracle NoSQL Database JS Driver

233 lines (196 loc) 10.3 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: 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: logger.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>/*- * * This file is part of Oracle NoSQL Database * Copyright (C) 2014, 2018 Oracle and/or its affiliates. All rights reserved. * * If you have received this file as part of Oracle NoSQL Database the * following applies to the work as a whole: * * Oracle NoSQL Database server software is free software: you can * redistribute it and/or modify it under the terms of the GNU Affero * General Public License as published by the Free Software Foundation, * version 3. * * Oracle NoSQL Database is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Affero General Public License for more details. * * If you have received this file as part of Oracle NoSQL Database Client or * distributed separately the following applies: * * Oracle NoSQL Database client software is free software: you can * redistribute it and/or modify it under the terms of the Apache License * as published by the Apache Software Foundation, version 2.0. * * You should have received a copy of the GNU Affero General Public License * and/or the Apache License in the LICENSE file along with Oracle NoSQL * Database client or server distribution. If not, see * &lt;http://www.gnu.org/licenses/> * or * &lt;http://www.apache.org/licenses/LICENSE-2.0>. * * An active Oracle commercial licensing agreement for this product supersedes * these licenses and in such case the license notices, but not the copyright * notice, may be removed by you in connection with your distribution that is * in accordance with the commercial licensing terms. * * For more information please contact: * * berkeleydb-info_us@oracle.com * */ 'use strict' /*global logConfiguration*/ /*global fs*/ var CONFIG_FILE = 'nosqldb.logconf.json'; function getTime() { var date = new Date(); var hour = date.getHours(); hour = (hour &lt; 10 ? '0' : '') + hour; var min = date.getMinutes(); min = (min &lt; 10 ? '0' : '') + min; var sec = date.getSeconds(); sec = (sec &lt; 10 ? '0' : '') + sec; var msec = date.getMilliseconds(); msec = (msec &lt; 10 ? '00' : (msec &lt; 100 ? '0' : '') ) + msec; var year = date.getFullYear(); var month = date.getMonth() + 1; month = (month &lt; 10 ? '0' : '') + month; var day = date.getDate(); day = (day &lt; 10 ? '0' : '') + day; return year + '-' + month + '-' + day + ' ' + hour + ':' + min + ':' + sec + '.' + msec; } function setFile(file, callback) { if (typeof file === 'string') { if (!fs.existsSync(file)) { var firstMessage = '[' + getTime() + '] [INIT] KVStore for node.js log system - file created\n'; fs.writeFile(file, firstMessage, function (err) { if (err) { if (callback) callback(err); else throw err; } else return file; }); } return file; } } function verifyDebugLevel(logLevel) { var result = 0; if (typeof logLevel === 'string') result = levels.levels.indexOf(logLevel); else if (typeof logLevel === 'number') result = logLevel; return result; } function log(logger, level, stringLevel, message, callback) { if (logger.logLevel >= level) { var stack = new Error().stack.split('\n'); if (typeof message !== 'string') { message = JSON.stringify(message); } var logString = '[' + getTime() + '] ' + stringLevel + '[' + stack[3].trim() + '] ' + message + '\n'; if (logger.logToFile) { fs.appendFile(logger.logFile, logString, function (err) { if (err) { if (callback) callback(err); else throw err; } }); } if (logger.logToConsole) console.log(logString); } } var levels = { OFF: 0, FATAL: 1, ERROR: 2, WARN: 3, INFO: 4, DEBUG: 5, TRACE: 6, ALL: 7, levels: ['OFF', 'FATAL', 'ERROR', 'WARN', 'INFO', 'DEBUG', 'TRACE', 'ALL'] } exports.LOG_LEVELS = levels; /** * Creates a new Logger object * @constructor */ function Logger() { var conf = {}; if (fs.existsSync(CONFIG_FILE)) { conf = JSON.parse(fs.readFileSync(CONFIG_FILE)); if (conf) { this.logLevel = conf.logLevel; this.logToFile = conf.logToFile; this.logFile = conf.logFile; this.logToConsole = conf.logToConsole; return; } } else { this.logLevel = conf.logLevel = levels.OFF; this.logToFile = conf.logToFile = true; this.logFile = conf.logFile = 'nosqldb-oraclejs.log'; this.logToConsole = conf.logToConsole = false; fs.writeFileSync(CONFIG_FILE, JSON.stringify(conf, null, 4)); } this.LOG_LEVELS = levels; } exports.Logger = Logger; Logger.prototype.trace = function (message, callback) { log(this, levels.TRACE, '[TRACE] ', message, callback); }; Logger.prototype.debug = function (message, callback) { log(this, levels.DEBUG, '[DEBUG] ', message, callback); }; Logger.prototype.info = function (message, callback) { log(this, levels.INFO, '[INFO] ', message, callback); }; Logger.prototype.warn = function (message, callback) { log(this, levels.WARN, '[WARN] ', message, callback); }; Logger.prototype.error = function (message, callback) { log(this, levels.ERROR, '[ERROR] ', message, callback); }; Logger.prototype.fatal = function (message, callback) { log(this, levels.FATAL, '[FATAL] ', message, callback); }; </code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Configuration.html">Configuration</a></li><li><a href="ConnectionError.html">ConnectionError</a></li><li><a href="Consistency.html">Consistency</a></li><li><a href="DeleteResult.html">DeleteResult</a></li><li><a href="Durability.html">Durability</a></li><li><a href="ExecutionFuture.html">ExecutionFuture</a></li><li><a href="ExecutionId.html">ExecutionId</a></li><li><a href="FieldRange.html">FieldRange</a></li><li><a href="GetResult.html">GetResult</a></li><li><a href="Iterator.html">Iterator</a></li><li><a href="IteratorError.html">IteratorError</a></li><li><a href="KeyPair.html">KeyPair</a></li><li><a href="KeyPairResult.html">KeyPairResult</a></li><li><a href="Logger.html">Logger</a></li><li><a href="ModuleInfo.html">ModuleInfo</a></li><li><a href="MultiGetKeyResult.html">MultiGetKeyResult</a></li><li><a href="MultiGetResult.html">MultiGetResult</a></li><li><a href="NoSQLDBError.html">NoSQLDBError</a></li><li><a href="Operation.html">Operation</a></li><li><a href="ParameterError.html">ParameterError</a></li><li><a href="ProxyConfiguration.html">ProxyConfiguration</a></li><li><a href="PutResult.html">PutResult</a></li><li><a href="Readable.html">Readable</a></li><li><a href="ReadOptions.html">ReadOptions</a></li><li><a href="ReplicaAckPolicy.html">ReplicaAckPolicy</a></li><li><a href="ReturnChoice.html">ReturnChoice</a></li><li><a href="ReturnKey.html">ReturnKey</a></li><li><a href="ReturnRow.html">ReturnRow</a></li><li><a href="Row.html">Row</a></li><li><a href="SimpleConsistency.html">SimpleConsistency</a></li><li><a href="StatementResult.html">StatementResult</a></li><li><a href="Store.html">Store</a></li><li><a href="StoreError.html">StoreError</a></li><li><a href="SyncPolicy.html">SyncPolicy</a></li><li><a href="TimeConsistency.html">TimeConsistency</a></li><li><a href="TimeToLive.html">TimeToLive</a></li><li><a href="UpdateResult.html">UpdateResult</a></li><li><a href="VerifyProperties.html">VerifyProperties</a></li><li><a href="Version.html">Version</a></li><li><a href="VersionConsistency.html">VersionConsistency</a></li><li><a href="WriteOptions.html">WriteOptions</a></li></ul><h3>Events</h3><ul><li><a href="Iterator.html#event:close">close</a></li><li><a href="Iterator.html#event:data">data</a></li><li><a href="Iterator.html#event:done">done</a></li><li><a href="Iterator.html#event:error">error</a></li><li><a href="Readable.html#event:data">data</a></li><li><a href="Readable.html#event:end">end</a></li><li><a href="Readable.html#event:error">error</a></li><li><a href="Store.html#event:close">close</a></li><li><a href="Store.html#event:error">error</a></li><li><a href="Store.html#event:open">open</a></li></ul><h3>Global</h3><ul><li><a href="global.html#AuthenticationFailureException">AuthenticationFailureException</a></li><li><a href="global.html#AuthenticationRequiredException">AuthenticationRequiredException</a></li><li><a href="global.html#ConsistencyException">ConsistencyException</a></li><li><a href="global.html#DurabilityException">DurabilityException</a></li><li><a href="global.html#FaultException">FaultException</a></li><li><a href="global.html#IllegalArgumentException">IllegalArgumentException</a></li><li><a href="global.html#readConfiguration">readConfiguration</a></li><li><a href="global.html#RequestLimitException">RequestLimitException</a></li><li><a href="global.html#RequestTimeoutException">RequestTimeoutException</a></li><li><a href="global.html#startProxy">startProxy</a></li><li><a href="global.html#stopProxy">stopProxy</a></li><li><a href="global.html#TableOpExecutionException">TableOpExecutionException</a></li><li><a href="global.html#TimeUnit">TimeUnit</a></li><li><a href="global.html#UnauthorizedException">UnauthorizedException</a></li><li><a href="global.html#UnknownException">UnknownException</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Thu Aug 01 2019 14:19:18 GMT+0530 (India Standard Time) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>