Skip to content

Commit

Permalink
Implement logApiLevel for dynamic API log formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mauroalexandre committed Oct 7, 2024
1 parent 76b6014 commit 99ce546
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/settings.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ module.exports = {
// Default: '_logs'
// logDir: '_logs',

logApiLevel: 'tiny',
// logApiLevel Configuration for Morgan Logging
//
// This configuration determines the format of logging by Morgan, indirectly acting as a 'level' of logging detail.
// The setting influences which predefined format or custom function Morgan uses to log HTTP requests.
//
// Possible values for logApiLevel:
// - 'dev': Colorful and concise output for development environments, showing the method, URL, status, response length, and response time.
// - 'combined': Apache combined log format. Very detailed, suitable for production environments.
// - 'common': Less detailed than 'combined', omitting the referrer and user-agent.
// - 'short': Shorter format that includes the remote address and request details.
// - 'tiny': Minimalist format, showing just the method, URL, status, response length, and response time.
//
// Default Value:
// - 'combined': By default, logApiLevel is set to 'combined', providing detailed logs suitable for thorough tracking and analysis.

// Used to storage Database like DAQ, User
// Default: '_db'
// dbDir: '_db',
Expand Down
3 changes: 3 additions & 0 deletions server/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

const fs = require('fs');
var express = require('express');
var morgan = require('morgan');
var bodyParser = require('body-parser');
const authJwt = require('./jwt-helper');
const rateLimit = require("express-rate-limit");
Expand All @@ -30,6 +31,8 @@ function init(_server, _runtime) {
return new Promise(function (resolve, reject) {
if (runtime.settings.disableServer !== false) {
apiApp = express();
apiApp.use(morgan(['combined', 'common', 'dev', 'short', 'tiny'].
includes(runtime.settings.logApiLevel) ? runtime.settings.logApiLevel : 'combined'));

var maxApiRequestSize = runtime.settings.apiMaxLength || '35mb';
apiApp.use(bodyParser.json({limit:maxApiRequestSize}));
Expand Down
16 changes: 16 additions & 0 deletions server/settings.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ module.exports = {
// Default: '_logs'
logDir: '_logs',

// logApiLevel Configuration for Morgan Logging
//
// This configuration determines the format of logging by Morgan, indirectly acting as a 'level' of logging detail.
// The setting influences which predefined format or custom function Morgan uses to log HTTP requests.
//
// Possible values for logApiLevel:
// - 'dev': Colorful and concise output for development environments, showing the method, URL, status, response length, and response time.
// - 'combined': Apache combined log format. Very detailed, suitable for production environments.
// - 'common': Less detailed than 'combined', omitting the referrer and user-agent.
// - 'short': Shorter format that includes the remote address and request details.
// - 'tiny': Minimalist format, showing just the method, URL, status, response length, and response time.
//
// Default Value:
// - 'combined': By default, logApiLevel is set to 'combined', providing detailed logs suitable for thorough tracking and analysis.
logApiLevel: 'tiny',

// Used to storage Database like DAQ, User
// Default: '_db'
dbDir: '_db',
Expand Down

0 comments on commit 99ce546

Please sign in to comment.