Skip to content

Commit

Permalink
feat!: Update logging to use winston
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
The existing logging solution was a bit simple. With winston we can log
to multiple places (file, stdout etc) and different formats (like json).
This is ultimately better for deployments that will send their logs to
other services.

For any plugins, they will likely error on trying to log something.
Plugins will need to be updated so that they are aware of the newer
logger.
  • Loading branch information
popstarfreas committed Mar 25, 2024
1 parent 08dafda commit 5516d8e
Show file tree
Hide file tree
Showing 15 changed files with 574 additions and 218 deletions.
30 changes: 23 additions & 7 deletions app/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
import Dimensions from "dimensions";
import Logger from "dimensions/logger";
import { ConfigSettings } from 'dimensions/configloader';
import * as winston from "winston";

let logging = new Logger();
let errorLogging = new Logger("error-log.txt");
let logging = winston.createLogger({
level: 'info',
format: winston.format.json(),
transports: [
new winston.transports.File({ filename: 'dimensions.log', level: 'info' }),
new winston.transports.File({ filename: 'error.log', level: 'error' }),
]
})

if (ConfigSettings.options.log.outputToConsole) {
logging.add(new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.printf(info => {
return `${info.message}`;
})
)
}));
}

process.on('unhandledRejection', (reason: any, promise: any) => {
errorLogging.appendLine('Reason: ' + reason);
errorLogging.appendLine(promise);
logging.error('Reason: ' + reason, promise);
});

process.on('uncaughtException', function(e: any) {
errorLogging.appendLine(e);
errorLogging.appendLine(e.stack);
logging.error(e, e.stack);
});

var dimensions = new Dimensions(logging);
Expand Down
22 changes: 5 additions & 17 deletions app/node_modules/dimensions/client.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app/node_modules/dimensions/clientargs.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 10 additions & 20 deletions app/node_modules/dimensions/extensions.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 14 additions & 17 deletions app/node_modules/dimensions/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5516d8e

Please sign in to comment.