mirror of
https://github.com/microsoft/TypeScript-Node-Starter.git
synced 2025-11-09 23:57:23 +00:00
replaced logging with Winston
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -39,4 +39,7 @@ env.sh
|
||||
env.cmd
|
||||
|
||||
# coverage reports
|
||||
coverage/**/*
|
||||
coverage/**/*
|
||||
|
||||
# logs
|
||||
debug.log
|
||||
55
package-lock.json
generated
55
package-lock.json
generated
@@ -19,7 +19,8 @@
|
||||
"@types/bluebird": {
|
||||
"version": "3.5.18",
|
||||
"resolved": "https://registry.npmjs.org/@types/bluebird/-/bluebird-3.5.18.tgz",
|
||||
"integrity": "sha512-OTPWHmsyW18BhrnG5x8F7PzeZ2nFxmHGb42bZn79P9hl+GI5cMzyPgQTwNjbem0lJhoru/8vtjAFCUOu3+gE2w=="
|
||||
"integrity": "sha512-OTPWHmsyW18BhrnG5x8F7PzeZ2nFxmHGb42bZn79P9hl+GI5cMzyPgQTwNjbem0lJhoru/8vtjAFCUOu3+gE2w==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/body-parser": {
|
||||
"version": "1.16.8",
|
||||
@@ -123,6 +124,7 @@
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/form-data/-/form-data-2.2.1.tgz",
|
||||
"integrity": "sha1-7is7jqoRwJOCiZU2BrdFtzjFSx4=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/node": "7.0.50"
|
||||
}
|
||||
@@ -311,6 +313,7 @@
|
||||
"version": "2.0.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/request/-/request-2.0.9.tgz",
|
||||
"integrity": "sha1-EluKYNikOejYfm0TNcYczNwYNDo=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/form-data": "2.2.1",
|
||||
"@types/node": "7.0.50"
|
||||
@@ -320,6 +323,7 @@
|
||||
"version": "4.1.39",
|
||||
"resolved": "https://registry.npmjs.org/@types/request-promise/-/request-promise-4.1.39.tgz",
|
||||
"integrity": "sha512-q9/VlE0osQ+EJ/UCF/MzH/xiF+wahQ4LG2i7lKkJuuWeRaM0GlhG29d11HUEFTKSL0gh3T1sJIpbYE7bwku9aQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/bluebird": "3.5.18",
|
||||
"@types/request": "2.0.9"
|
||||
@@ -374,6 +378,15 @@
|
||||
"@types/superagent": "3.5.6"
|
||||
}
|
||||
},
|
||||
"@types/winston": {
|
||||
"version": "2.3.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/winston/-/winston-2.3.7.tgz",
|
||||
"integrity": "sha512-jNhbkxPtt9xbzvihfA0OavjJbpCIyTDSmwE03BVXgCKcz9lwNsq4cg2wsNkY4Av5eH35ttBArhYtVJa6CIrg2A==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/node": "7.0.50"
|
||||
}
|
||||
},
|
||||
"abab": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/abab/-/abab-1.0.4.tgz",
|
||||
@@ -1320,6 +1333,11 @@
|
||||
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
|
||||
"dev": true
|
||||
},
|
||||
"colors": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz",
|
||||
"integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs="
|
||||
},
|
||||
"combined-stream": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.5.tgz",
|
||||
@@ -1583,6 +1601,11 @@
|
||||
"array-find-index": "1.0.2"
|
||||
}
|
||||
},
|
||||
"cycle": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/cycle/-/cycle-1.0.3.tgz",
|
||||
"integrity": "sha1-IegLK+hYD5i0aPN5QwZisEbDStI="
|
||||
},
|
||||
"dashdash": {
|
||||
"version": "1.14.1",
|
||||
"resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz",
|
||||
@@ -2010,6 +2033,11 @@
|
||||
"resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz",
|
||||
"integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU="
|
||||
},
|
||||
"eyes": {
|
||||
"version": "0.1.8",
|
||||
"resolved": "https://registry.npmjs.org/eyes/-/eyes-0.1.8.tgz",
|
||||
"integrity": "sha1-Ys8SAjTGg3hdkCNIqADvPgzCC8A="
|
||||
},
|
||||
"fast-deep-equal": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.0.0.tgz",
|
||||
@@ -7142,6 +7170,11 @@
|
||||
"tweetnacl": "0.14.5"
|
||||
}
|
||||
},
|
||||
"stack-trace": {
|
||||
"version": "0.0.10",
|
||||
"resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz",
|
||||
"integrity": "sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA="
|
||||
},
|
||||
"statuses": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz",
|
||||
@@ -8157,6 +8190,26 @@
|
||||
"resolved": "https://registry.npmjs.org/window-size/-/window-size-0.1.0.tgz",
|
||||
"integrity": "sha1-VDjNLqk7IC76Ohn+iIeu58lPnJ0="
|
||||
},
|
||||
"winston": {
|
||||
"version": "2.4.0",
|
||||
"resolved": "https://registry.npmjs.org/winston/-/winston-2.4.0.tgz",
|
||||
"integrity": "sha1-gIBQuT1SZh7Z+2wms/DIJnCLCu4=",
|
||||
"requires": {
|
||||
"async": "1.0.0",
|
||||
"colors": "1.0.3",
|
||||
"cycle": "1.0.3",
|
||||
"eyes": "0.1.8",
|
||||
"isstream": "0.1.2",
|
||||
"stack-trace": "0.0.10"
|
||||
},
|
||||
"dependencies": {
|
||||
"async": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/async/-/async-1.0.0.tgz",
|
||||
"integrity": "sha1-+PwEyjoTeErenhZBr5hXjPvWR6k="
|
||||
}
|
||||
}
|
||||
},
|
||||
"with": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/with/-/with-5.1.1.tgz",
|
||||
|
||||
@@ -44,7 +44,8 @@
|
||||
"passport-local": "^1.0.0",
|
||||
"pug": "^2.0.0-rc.4",
|
||||
"request": "^2.83.0",
|
||||
"request-promise": "^4.2.2"
|
||||
"request-promise": "^4.2.2",
|
||||
"winston": "^2.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/async": "^2.0.45",
|
||||
@@ -69,8 +70,9 @@
|
||||
"@types/passport-facebook": "^2.1.3",
|
||||
"@types/request": "^2.0.9",
|
||||
"@types/request-promise": "^4.1.39",
|
||||
"@types/supertest": "^2.0.4",
|
||||
"@types/shelljs": "^0.7.7",
|
||||
"@types/supertest": "^2.0.4",
|
||||
"@types/winston": "^2.3.7",
|
||||
"chai": "^4.1.2",
|
||||
"concurrently": "^3.5.1",
|
||||
"jest": "^21.2.1",
|
||||
|
||||
@@ -2,7 +2,7 @@ import * as express from "express";
|
||||
import * as compression from "compression"; // compresses requests
|
||||
import * as session from "express-session";
|
||||
import * as bodyParser from "body-parser";
|
||||
import * as logger from "morgan";
|
||||
import * as logger from "winston";
|
||||
import * as lusca from "lusca";
|
||||
import * as dotenv from "dotenv";
|
||||
import * as mongo from "connect-mongo";
|
||||
@@ -12,7 +12,7 @@ import * as mongoose from "mongoose";
|
||||
import * as passport from "passport";
|
||||
import * as expressValidator from "express-validator";
|
||||
import * as bluebird from "bluebird";
|
||||
import { MONGODB_URI, SESSION_SECRET } from "./util/loadSecrets";
|
||||
import { MONGODB_URI, SESSION_SECRET } from "./util/secrets";
|
||||
|
||||
const MongoStore = mongo(session);
|
||||
|
||||
@@ -43,7 +43,6 @@ app.set("port", process.env.PORT || 3000);
|
||||
app.set("views", path.join(__dirname, "../views"));
|
||||
app.set("view engine", "pug");
|
||||
app.use(compression());
|
||||
app.use(logger("dev"));
|
||||
app.use(bodyParser.json());
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
app.use(expressValidator());
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
// import log from './logger'; TODO
|
||||
import * as dotenv from "dotenv";
|
||||
|
||||
export const ENVIRONMENT = process.env.NODE_ENV;
|
||||
const prod = ENVIRONMENT === "production"; // Anything else is treated as 'dev'
|
||||
|
||||
dotenv.config({ path: ".env.example" });
|
||||
|
||||
export const SESSION_SECRET = process.env["SESSION_SECRET"];
|
||||
export const MONGODB_URI = prod ? process.env["MONGODB_URI"] : process.env["MONGODB_URI_LOCAL"];
|
||||
|
||||
|
||||
|
||||
// if (!GITHUB_CLIENT_SECRET) {
|
||||
// log.fatal("ERROR\tNo client secret. Set TCQ_GH_SECRET.");
|
||||
// process.exit(1);
|
||||
// }
|
||||
|
||||
// if (!GITHUB_CLIENT_ID) {
|
||||
// log.fatal("ERROR\tNo client id. Set TCQ_GH_ID.");
|
||||
// process.exit(1);
|
||||
// }
|
||||
|
||||
// if (!SESSION_SECRET) {
|
||||
// log.fatal("ERROR\tNo session secret. Set TCQ_SESSION_SECRET.");
|
||||
// process.exit(1);
|
||||
// }
|
||||
|
||||
// if (!CDB_SECRET) {
|
||||
// log.fatal("ERROR\tNo CosmosDB secret. Set TCQ_CDB_SECRET.");
|
||||
// process.exit(1);
|
||||
// }
|
||||
|
||||
// if (!AI_IKEY) {
|
||||
// log.fatal("ERROR\tNo Application Insights Instrumentation Key. Set TCQ_AI_IKEY.");
|
||||
// process.exit(1);
|
||||
// }
|
||||
16
src/util/logger.ts
Normal file
16
src/util/logger.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import * as winston from "winston";
|
||||
import { ENVIRONMENT } from "./secrets";
|
||||
|
||||
const logger = new (winston.Logger)({
|
||||
transports: [
|
||||
new (winston.transports.Console)({ level: process.env.NODE_ENV === "production" ? "error" : "debug" }),
|
||||
new (winston.transports.File)({ filename: "debug.log", level: "debug"})
|
||||
]
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
logger.debug("Logging initialized at debug level");
|
||||
}
|
||||
|
||||
export default logger;
|
||||
|
||||
26
src/util/secrets.ts
Normal file
26
src/util/secrets.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import logger from "./logger";
|
||||
import * as dotenv from "dotenv";
|
||||
import * as fs from "fs";
|
||||
|
||||
if (fs.existsSync(".env")) {
|
||||
logger.debug("Using .env file to supply config environment variables");
|
||||
dotenv.config({ path: ".env" });
|
||||
} else {
|
||||
logger.debug("Using .env.example file to supply config environment variables");
|
||||
dotenv.config({ path: ".env.example" }); // you can delete this after you create your own .env file!
|
||||
}
|
||||
export const ENVIRONMENT = process.env.NODE_ENV;
|
||||
const prod = ENVIRONMENT === "production"; // Anything else is treated as 'dev'
|
||||
|
||||
export const SESSION_SECRET = process.env["SESSION_SECRET"];
|
||||
export const MONGODB_URI = prod ? process.env["MONGODB_URI"] : process.env["MONGODB_URI_LOCAL"];
|
||||
|
||||
if (!SESSION_SECRET) {
|
||||
logger.error("No client secret. Set SESSION_SECRET environment variable.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (!MONGODB_URI) {
|
||||
logger.error("No mongo connection string. Set MONGODB_URI environment variable.");
|
||||
process.exit(1);
|
||||
}
|
||||
Reference in New Issue
Block a user