UNPKG

loganalysis

Version:

Collects stdout and stderr messages from Node.js applications and sends them to the IBM SmartCloud Analytics - Log Analysis service.

87 lines (72 loc) 2.36 kB
/* * © Copyright IBM Corp. 2014 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var ScalaClient = require('./scala'); var Logger = require('./logger'); var logger = Logger.newLogger('index'); var loggers = Logger.loggers; var LoggerClass = Logger.Logger; var consoleConfig = require('./console_config'); (function () { try { consoleConfig.setUp(); } catch (e) { consoleConfig.cleanUp(); var message = 'Unable to execute auto config due to ' + (e && e.message ? e.message : ''); logger.error(message); logger.error(e.stack); } })(); /** * Exports those only for backward compatibility */ module.exports.consoleAutoConfig = consoleConfig; module.exports.ScalaClient = ScalaClient; /** * APIs for creating/adding/removing user defined Scala Clients */ module.exports.createScalaClient = ScalaClient.createScalaClient; module.exports.addScalaClient = function(client) { consoleConfig.addScalaClient(client); }; module.exports.removeScalaClient = function(client) { consoleConfig.removeScalaClient(client); }; module.exports.getScalaClients = function() { return consoleConfig.getActiveScalaClients().slice(); }; /** * APIs for setting logger level on the runtime */ module.exports.setLoggerLevel = function (name, level) { var targetLogger = loggers[name]; if(targetLogger && (targetLogger instanceof LoggerClass)) { targetLogger.setLevel(level); } }; module.exports.setDefaultLoggerLevel = function (level) { for(var name in loggers) { if(loggers.hasOwnProperty(name) && (loggers[name] instanceof LoggerClass)) { loggers[name].setLevel(level); } } }; module.exports.setLogToFile = function (logToFile) { for(var name in loggers) { if(loggers.hasOwnProperty(name) && (loggers[name] instanceof LoggerClass)) { loggers[name].setLogToFile(logToFile); } } };