diff --git a/controllers/authentication/oauth/google.js b/controllers/authentication/oauth/google.js index 911448e..390a16c 100644 --- a/controllers/authentication/oauth/google.js +++ b/controllers/authentication/oauth/google.js @@ -45,11 +45,11 @@ export async function getToken(code, scope) { return { error: true, ...AUTH_OAUTH_ERR_GOOGLE_FAILED_TOKEN_FETCH }; } - console.log(accessToken); + logger.log(`accessToken: ${accessToken}`); const id = jsonwebtoken.decode(accessToken.token.id_token); - console.log(id); + logger.log(`jsonwebtoken.${id}`); return id; } diff --git a/controllers/devices.js b/controllers/devices.js index 0f467d7..6bd94c0 100644 --- a/controllers/devices.js +++ b/controllers/devices.js @@ -195,7 +195,7 @@ async function getDrives(dongleId, includeDeleted, includeMeta) { async function getDrive(identifier) { const drive = await orm.models.drives.findOne({ where: { identifier } }); - console.log(drive); + logger.log(drive); if (drive.dataValues) return drive.dataValues; return null; @@ -273,7 +273,7 @@ async function updateOrCreateDrive(dongleId, identifier, data) { logger.info('updateOrCreate Drive', dongleId, identifier, data); const check = await orm.models.drives.findOne({ where: { dongle_id: dongleId, identifier } }); - console.log('checking for existing drive....', check); + logger.log('checking for existing drive....', check); if (check) { return orm.models.drives.update( diff --git a/controllers/users.js b/controllers/users.js index a0ce4a9..87d838b 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -17,7 +17,7 @@ export async function getAccountFromEmail(email) { } export async function _dirtyCreateAccount(email, password, created, admin) { - console.log('creating acount: ', email, password, created, admin); + logger.log('creating acount: ', email, password, created, admin); return orm.models.accounts.create({ email, password, created, admin, }); diff --git a/routes/administration/adminApi.js b/routes/administration/adminApi.js index f09c894..0a033e1 100644 --- a/routes/administration/adminApi.js +++ b/routes/administration/adminApi.js @@ -44,8 +44,6 @@ router.get('/user/:userId/get/devices', runAsyncWrapper(async (req, res) => { })); router.get('/user/', runAsyncWrapper(async (req, res) => { - console.warn('PROCESSED'); - return res.status(200).json({ success: true, data: await controllers.users.getAllUsers() }); })); @@ -71,7 +69,6 @@ router.get('/device/:dongle_id/pair/:user_id', runAsyncWrapper(async (req, res) router.get('/device', runAsyncWrapper(async (req, res) => { const filteredDevices = await controllers.devices.getAllDevicesFiltered(); - console.log('fil', filteredDevices); return res.status(200).json({ success: true, data: filteredDevices }); })); diff --git a/routes/api.js b/routes/api.js index 988c680..c32a539 100644 --- a/routes/api.js +++ b/routes/api.js @@ -268,10 +268,9 @@ async function upload(req, res) { const drive = await deviceController.getDriveFromidentifier(dongleId, driveName).catch((err)=>{ logger.warn("drive failed to make", err) }) - console.log("drive value", drive) - console.log("drive name:", driveName) - + logger.log("drive value", drive) + logger.log("drive name:", driveName) if (drive === undefined || drive === null) { logger.info("CREATING NEW DRIVE") diff --git a/routes/api/authentication/oauth.js b/routes/api/authentication/oauth.js index 4ee825c..36573c2 100644 --- a/routes/api/authentication/oauth.js +++ b/routes/api/authentication/oauth.js @@ -1,9 +1,10 @@ import express from 'express'; -import jsonwebtoken from 'jsonwebtoken'; import { getURL, getToken } from '../../../controllers/authentication/oauth/google'; import authenticationController from '../../../controllers/authentication'; +import log4js from 'log4js'; const router = express.Router(); +const logger = log4js.getLogger('default'); async function isAuthenticated(req, res, next) { const account = await authenticationController.getAuthenticatedAccount(req); @@ -22,14 +23,13 @@ async function isAuthenticated(req, res, next) { } router.get('/authentication/oauth/callback', async (req, res) => { - console.log(req.query); - + logger.log(req.query); res.json(await getToken(req.query.code, req.query.scope)); }); router.get('/authentication/oauth/:provider', async (req, res) => { const { provider } = req.params; - console.log('provider', provider); + logger.log('provider', provider); let url; switch (provider) { case 'google': @@ -48,9 +48,7 @@ router.get('/authentication/oauth/:provider', async (req, res) => { }); router.get('/authentication/oauth/pair/:provider', isAuthenticated, async (req, res) => { - - - + res.status(200); }); export default router; diff --git a/routes/api/devices.js b/routes/api/devices.js index 254cbc1..78905af 100644 --- a/routes/api/devices.js +++ b/routes/api/devices.js @@ -3,9 +3,13 @@ import crypto from 'crypto'; import dirTree from 'directory-tree'; import bodyParser from 'body-parser'; import deviceSchema from '../../schema/routes/devices'; +import log4js from 'log4js'; import deviceController from '../../controllers/devices'; import authenticationController from '../../controllers/authentication'; + +const logger = log4js.getLogger('default'); + const router = express.Router(); async function isAuthenticated(req, res, next) { const account = await authenticationController.getAuthenticatedAccount(req); @@ -50,7 +54,7 @@ router.put('/retropilot/0/device/:dongle_id/', [isAuthenticated, bodyParser.json } const { body } = req; - console.log(deviceSchema.MutateDevice.isValid(body)); + logger.log(deviceSchema.MutateDevice.isValid(body)); }); router.get('/retropilot/0/device/:dongle_id/drives/:drive_identifier/segment', isAuthenticated, async (req, res) => { diff --git a/routes/useradmin.js b/routes/useradmin.js index b31d260..630ba54 100644 --- a/routes/useradmin.js +++ b/routes/useradmin.js @@ -27,7 +27,7 @@ function runAsyncWrapper(callback) { router.post('/useradmin/auth', bodyParser.urlencoded({ extended: true }), runAsyncWrapper(async (req, res) => { const signIn = await authenticationController.signIn(req.body.email, req.body.password); - console.log(signIn); + logger.log(signIn); if (signIn.success) { res.cookie('jwt', signIn.jwt); @@ -130,7 +130,7 @@ router.post('/useradmin/register/token', bodyParser.urlencoded({ extended: true console.error(error); } - console.log(result); + logger.log(result); if (result.dataValues) { logger.info(`USERADMIN REGISTRATION - created new account #${result.lastID} with email ${email}`); diff --git a/server.js b/server.js index 5b2546a..2e872e0 100644 --- a/server.js +++ b/server.js @@ -26,6 +26,7 @@ process.on('unhandledRejection', (error, p) => { console.log(error.promise, p); console.dir(error.stack); }); + log4js.configure({ appenders: { logfile: { type: 'file', filename: 'server.log' }, out: { type: 'console' } /* {type: "file", filename: "server1.log"} */ }, categories: { default: { appenders: ['out', 'logfile'], level: 'info' } },