本文整理匯總了TypeScript中log4js.connectLogger函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript connectLogger函數的具體用法?TypeScript connectLogger怎麽用?TypeScript connectLogger使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了connectLogger函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: setup
function setup(app: express.Express) {
// View engine setup
app.set("views", path.join(__dirname, "/../views"));
app.set("view engine", "pug");
// uncomment after placing your favicon in /public
// app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
// Body parser setup
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// Cookie parser setup
app.use(cookieParser());
// Log4js setup
app.use(log4js.connectLogger(log4js.getLogger("http"), { level: "auto" }));
// Passport setup when using
// app.use(setupedPassport.initialize());
// app.use(setupedPassport.session());
// Static dir setup
app.use(express.static(path.join(__dirname, "/../public")));
// Rooting setup
setupRoutes(app);
app.use((req, res, next) => {
const err = new HttpErrors.NotFound();
next(err);
});
app.use((err: Error, req, res, next) => {
const error = err as HttpErrors.HttpError;
res.status(error.status || 500);
const params = {
error: (process.env.NODE_ENV !== "production") ? error : null,
message: error.message
};
if (/^\/api/.test(req.originalUrl)) {
res.send(params);
} else {
res.render("error", params);
}
});
}
示例2: init
static init(config: any, app: express.Application): any {
var log4js: any = require('log4js');
log4js.configure('config/log4js_setting.json');
var logger = log4js.getLogger('app');
logger.setLevel(config.log.level); // ALL, TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF
logger.info('Logging start. ');
logger.info('Log Level:' + config.log.level);
app.use(log4js.connectLogger(logger, {
level: config.log.level
}));
return logger;
}
示例3:
import * as fs from 'fs';
import * as path from 'path';
import * as log4js from 'log4js';
import * as constants from '../config/constants';
const LOG_METADATA = path.parse(constants.LOG_FILE);
if (!fs.existsSync(LOG_METADATA.dir)) {
fs.mkdirSync(LOG_METADATA.dir);
}
log4js.configure({
appenders: [
{
type: 'dateFile',
filename: constants.LOG_FILE,
category: 'main',
pattern: '-yyyy-MM-dd',
alwaysIncludePattern: true
}
],
replaceConsole: false
});
export const logger = log4js.getLogger('main');
export const loggerConnect = log4js.connectLogger(logger, { level: log4js.levels.DEBUG, format: ':method - :url - :status - :response-timems' });
示例4: express
let logger = log4js.getLogger('server-config');
export let app = express();
//configuracion express, middleware y setters
app.set(_.PORT, process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
//conecta logger con express para pintar los accesos
app.use(log4js.connectLogger(log4js.getLogger("http"), { level: 'auto' }));
app.get('/', routes.index);
app.use("/api/v1/users", userController.usersRouter);
// captura todos los errores procedentes de los middleware
app.use((err:Error, req: express.Request, res: express.Response, next: express.NextFunction)=> {
logger.error(err.message);
res.status(500);
res.send( {
error: err.message
});
});
示例5:
maxLogSize: config.log4js.maxLogSize,
backups: config.log4js.backups,
category: [ 'server', 'console' ]
},
],
replaceConsole: true
});
var logger = log4js.getLogger('server');
app.use(log4js.connectLogger(logger, {
level: log4js.levels.DEBUG,
nolog: [ '\\.css', '\\.js', ],
format: JSON.stringify({
'date': ':date',
'remote-addr': ':remote-addr',
'method': ':method',
'url': ':url',
'http-version': ':http-version',
'status': ':status',
'content-length': ':content-length',
'user-agent': ':user-agent'
})
}));
app.set('port', process.env.PORT || config.server.listenPort);
app.enable('trust proxy');
app.use(methodOverride());
app.use(cookieParser('jrpcMockServer'));
app.use(bodyParser.json());
app.use(session({
secret: 'jrpcMockServer',