Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tuning arguments and logger #242

Merged
merged 1 commit into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,28 @@ $ npm start -- -h
Usage: npm start -- (options)

Options:
--listen, -l set binding interface [string] [default: "0.0.0.0"]
--https use https [default: false]
--port set listen port [required] [default: 3000]
--env, -e Select environment (development,test,production)
[string] [default: "development"]
--verbose, -v verbose level [count]
--silent, -s Silent mode [default: false]
--listen, -l set binding interface [string]
--https use https
--port set listen port
--verbose, -v verbose level [count]
--silent, -s Silent mode
--log log path. Use "null" or "/dev/null" to supress file
logging [string]
--autoInstallAddonDeps automatically install dependencies when startup server
[default: true]
--config, -c config file [string] [default: "config.json"]
--db mongodb connection string [string]
--auto-reload, -r Automatically restart workers when changes detected in
server directory
```

**https:**
Generate self-signed ssl certifications:
* `./scripts/gencerts.sh`
* start daemon with `--https` -options (`npm start -- -https`)

**NOTE:** Not recommended to use self-signed certificates in production usage!

## Clustered mode

OpenTMI support [clustered mode](doc/cluster.md) which gives some benefits in production environment:
Expand All @@ -105,7 +113,7 @@ Available [here](doc/APIs)

By default opentmi is started as development mode. You can configure environment using [`--config <file>`](`config.example.json`) -option.

**note**:
**note**:
* `"mongo"` options overwrites defaults and is pypassed to [MongoClient](http://mongodb.github.io/node-mongodb-native/3.0/api/MongoClient.html).
* `"smtp"` options is pypassed to [nodemailer](https://nodemailer.com/smtp/) transport configurations. To activate smpt use `enabled` property.

Expand Down
2 changes: 1 addition & 1 deletion app/addons/addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class Addon {
*/
static _installDependencies(addon) {
if (!Addon._autoInstallAddonDeps()) {
logger.debug('Skip addon dependency installation');
logger.info('Skip addon dependency installation');
return Promise.resolve();
}
const command = 'npm install';
Expand Down
2 changes: 1 addition & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ const mongoAdapter = require('socket.io-adapter-mongo');
const Promise = require('bluebird');

// application modules
const logger = require('./tools/logger');
const express = require('./express');
const Server = require('./server');
const models = require('./models');
const routes = require('./routes');
const Emailer = require('./controllers/emailer');
const AddonManager = require('./addons');
const logger = require('./tools/logger');
const config = require('./tools/config');
const eventBus = require('./tools/eventBus');
const DB = require('./db');
Expand Down
12 changes: 11 additions & 1 deletion app/tools/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ const args = {
type: 'bool',
describe: 'Silent mode'
},
log: {
type: 'string',
describe: 'log path. Use "null" or "/dev/null" to supress file logging'
},
autoInstallAddonDeps: {
default: true,
type: 'bool',
describe: 'automatically install dependencies when startup server'
},
config: {
alias: 'c',
default: 'config.json',
Expand All @@ -53,7 +62,8 @@ const args = {
alias: 'r',
type: 'bool',
describe: 'Automatically restart workers when changes detected in server directory'
}
},
parseValues: true
};

const sampleFile = path.resolve(__dirname, '../../config.example.json');
Expand Down
39 changes: 26 additions & 13 deletions app/tools/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ const config = require('./config');
const verbose = config.get('verbose');
const silent = config.get('silent') || process.env.NODE_ENV === 'test';

const logDir = path.resolve(__dirname, '..', '..', 'log');
if (!fs.existsSync(logDir)) {
fs.mkdirSync(logDir);
const customLogPath = config.get('log');
const logDir = customLogPath || path.resolve(__dirname, '..', '..', 'log');
if (!customLogPath) {
// create default log path if custom is not given
if (!fs.existsSync(logDir)) {
fs.mkdirSync(logDir);
}
}

function _parseError(error) {
Expand Down Expand Up @@ -55,16 +59,25 @@ class MasterLogger {
}));
}
// Add winston file logger, which rotates daily
const fileLevel = 'silly';
this.logger.add(
new DailyRotateFile({
filename: `opentmi_%DATE%_${process.pid}.log`,
dirname: logDir,
level: fileLevel,
datePatter: 'yyyy-MM-dd_HH-mm',
maxSize: '100m',
maxFiles: '10d'
}));
if (customLogPath === '/dev/null' || customLogPath === null) {
// allows to suppress file logging e.g. when journalctl is in use
this.logger.add(
new transports.Stream({
stream: fs.createWriteStream('/dev/null')
})
);
} else {
const fileLevel = 'debug';
this.logger.add(
new DailyRotateFile({
filename: `opentmi_%DATE%_${process.pid}.log`,
dirname: logDir,
level: fileLevel,
datePatter: 'yyyy-MM-dd_HH-mm',
maxSize: '100m',
maxFiles: '3d'
}));
}
}
set level(level) {
this.logger.level = level;
Expand Down
Loading