exports.makeLogger = function(logfile) { if(!logfile) { return tracer.colorConsole({level:'debug'}); } return tracer.console({ level : 'info', format : [ "{{timestamp}} [{{title}}] [{{file}}:{{line}}:{{method}}] {{message}}", {error : "{{timestamp}} [{{title}}] [{{file}}:{{line}}:{{method}}] {{message}}"} ], dateformat : "yyyy-mm-dd HH:MM:ss,L", transport : function(data){ //TODO: Make this not look idiotic, do try catch //Open File fs.open(logfile, 'a', '0644', function(e, id) { if(e) { //Dir doesn't exist if(e.code === 'ENOENT') { fs.mkdir(path.dirname(logfile), '0755', function(err) { //Can't make dir exit if(err) { throw new Error(err); } fs.open(logfile, 'a', '0644', function(error, id) { if(error) { throw new Error(error); } fs.write(id, data.output+"\n", null, 'utf8', function() { fs.close(id, function() { }); }); }); }); } else { //Not ENOENT throw new Error(e); } } else { //No Errors fs.write(id, data.output+"\n", null, 'utf8', function() { fs.close(id, function() { }); }); } }); } }); };
var debugLogger = function(moduleName) { moduleName = moduleName.toUpperCase(); if (!debugFunctions[moduleName]) { var logLevel = 'error'; if (debugNames.indexOf(moduleName) > -1 || debugNames.indexOf('*') > -1) { logLevel = 'log'; } /* else{ if(debugEnvironmentVar.length != 0) logLevel = debugEnvironmentVar; } */ debugFunctions[moduleName] = tracer.console({ level: logLevel, // for details on format, see: https://www.npmjs.com/package/tracer format: moduleName + ' ' + '{{timestamp}} {{file}}:{{line}} {{message}}', }); } return debugFunctions[moduleName]; };
var net = require('net'); var http = require('http'); var url = require('url'); var extend = require('./lib/extend'); var http2 = require('./lib/node-http2'); var removeDeprecatedHeaders = require('./lib/header').removeDeprecatedHeaders; var tracer = require('tracer'); var log = tracer.console({ dateformat : "yyyy-mm-dd HH:MM:ss.L", format : "{{timestamp}} [{{title}}] - {{message}}" }); function Server(options) { var _ = this; _.clients = {}; _.domains = []; _.options = { domain: 'daleks.top', httpPort: 10824, controlPort: 10825, proxyPort: 10826, debug: false }; _.options = extend(_.options, options);
import express from 'express'; let router = express.Router(); import passport from 'passport'; import bodyParser from 'body-parser'; import colorOut from '../util/colorOut.js'; import tracer from 'tracer'; let logger = tracer.console(colorOut()); import db from '../models/index'; import crypto from 'crypto'; import bcrypt from 'bcryptjs'; import email from '../api/email'; // Bypass ensuredLogged in for dev let bypass = () => { return ( req, res, next ) => { next(); }; }; let ensureLoggedIn = ( process.env.NODE_ENV === 'development' ) ? bypass : require('connect-ensure-login').ensureLoggedIn; router.use(bodyParser.json()); /** * Generates and send reset password tokens * @param userEmail string email of user * @param newUser bool * @param res object */ let generateToken = ( userEmail, newUser, res ) => {
exports.runJobs = function(jobsCallback) { var async = require('async'); var process = require('process'); var IcecastToMySQL = require('icecast-log-to-mysql'); var plog, tracer = require('tracer'); plog = tracer.console(getLogConfig("logs/reports.log")); var optionsAccessLog = { name : 'access.log', date: getYesterday(), logDiffDays: 3, //date: moment('2016-01-01'), retryTimesOnFail: 5, retryIntervalOnFail: 10000 }; var optionsPlaylistLog = { name : 'playlist.log', date: getYesterday(), logDiffDays: 3, //date: moment('2016-01-01'), retryTimesOnFail: 5, retryIntervalOnFail: 10000 }; var timeOfProcessingPlaylistLogs = -1; var timeOfProcessingAccessLogs = -1; var access_errors = []; var playlist_errors = []; async.waterfall([ function(cb) { plog.info("Begin of playlist logs parsing"); var timeTookToParsePlaylistLogs = process.hrtime(); var parsePlaylistLog = new IcecastToMySQL(optionsPlaylistLog); parsePlaylistLog.run(function(err, res) { plog.info("TheEnd of playlist logs parsing"); parsePlaylistLog.freeLogStream(); access_errors = res.error_messages; timeOfProcessingPlaylistLogs = getTimeOfProcessing(timeTookToParsePlaylistLogs); plog.info("Parsing of playlist log files takes: " + timeOfProcessingPlaylistLogs + " seconds"); cb(err, res); }); }, function(res, cb) { plog.info("Begin of access logs parsing"); var timeTookToParseAccessLogs = process.hrtime(); var parseAccessLog = new IcecastToMySQL(optionsAccessLog); parseAccessLog.run(function(err, res) { plog.info("TheEnd of access logs parsing"); parseAccessLog.freeLogStream(); playlist_errors = res.error_messages; timeOfProcessingAccessLogs = getTimeOfProcessing(timeTookToParseAccessLogs); plog.info("Parsing of access log files takes: " + timeOfProcessingAccessLogs + " seconds"); cb(err, res); }); }, ], function(err, res) { if (err) plog.error(err); logr(plog, err, res); plog.info("TheEnd of parsing."); if (err) jobsCallback(err, null); else { var result = {}; result.state = "Parsing Success!"; result.timeParsingAccessLogs = timeOfProcessingAccessLogs; result.timeParsingPlaylistLogs = timeOfProcessingPlaylistLogs; result.access_errors = access_errors; result.playlist_errors = playlist_errors; jobsCallback(null, result); } }); };
// @flow weak import express from 'express'; import logger from 'morgan'; import cookieParser from 'cookie-parser'; import bodyParser from 'body-parser'; import passport from 'passport'; import {Strategy as LocalStrategy} from 'passport-local'; import routes from './routes/index'; import bcrypt from 'bcryptjs'; import colorOut from './util/colorOut.js'; import _tracer from 'tracer'; const tracer = _tracer.console(colorOut()); import config from 'config'; import db from './models/index'; import debug from 'debug'; debug('graphql:server'); import http from 'http'; import expressSession from 'express-session'; /** * Creates the Express server using the provided middlewares * @param {Array} customMiddlewares array with middlewares to add to the express instance */ export default function (customMiddlewares) { db.sequelize.sync().then( () => { // Seed an admin user bcrypt.genSalt(10, ( err, salt ) => { bcrypt.hash(config.get('password'), salt, ( err, hash ) => { if ( err ) { tracer.error('Error while hashing password: %j', { error: err });
function TraceLog(options) { 'use strict'; var self; self = this; this.level = 'error'; this.writeStreams = []; this.waitStreams = []; this.stackindex = 1; this.noconsole = false; this.finish_need_counts = 0; this.finish_counts = 0; this.real_finish_callback = null; this.finish_callback = function (err) { self.finish_counts += 1; if (err) { if (self.real_finish_callback !== null) { self.real_finish_callback(err); } } if (self.finish_counts === self.finish_need_counts) { if (self.real_finish_callback !== null) { self.real_finish_callback(null); } } return; }; this.finish = function (callback) { var ws; self.finish_need_counts = self.writeStreams.length; self.finish_counts = 0; self.real_finish_callback = callback; //var idx; while (self.writeStreams.length > 0) { ws = self.writeStreams[0]; self.writeStreams.splice(0, 1); ws.end('', self.finish_callback); } if (self.finish_need_counts === 0) { /*nothing to wait*/ callback(null); } }; this.format = "<{{title}}>:{{file}}:{{line}} {{message}}\n"; if (typeof options.format === 'string' && options.format.length > 0) { this.format = options.format; } if (typeof options.level === 'string') { this.level = options.level; } if (util.isArray(options.files)) { add_write_streams(self, options.files, false); } if (util.isArray(options.appendfiles)) { add_write_streams(self, options.appendfiles, true); } if (options.noconsole) { this.noconsole = true; } this.innerLogger = tracer.console({ format: [self.format], stackIndex: self.stackindex, transport: function (data) { if (!self.noconsole) { process.stderr.write(data.output); } self.writeStreams.forEach(function (elm) { elm.write(data.output); }); } }); tracer.setLevel(this.level); return this; }