From 7210883c7652f715a24f96dfa0f02734e6007795 Mon Sep 17 00:00:00 2001 From: Jekabs Karklins Date: Mon, 9 Oct 2023 20:49:28 +0200 Subject: [PATCH] feat(initializeLogger.js): add module to initialize logger with ConsoleLogger and GrayLogLogger feat(example.env): add commented out GRAYLOG_SERVER and GRAYLOG_PORT variables for configuring Graylog logger feat(index.js): add logger initialization and log message to indicate that all jobs are running --- config/initializeLogger.js | 22 ++++++++++++++++++++++ example.env | 4 +++- index.js | 4 ++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 config/initializeLogger.js diff --git a/config/initializeLogger.js b/config/initializeLogger.js new file mode 100644 index 0000000..6a60b06 --- /dev/null +++ b/config/initializeLogger.js @@ -0,0 +1,22 @@ +const { + setLogger, + ConsoleLogger, + GrayLogLogger, +} = require('@user-office-software/duo-logger'); + +const initializeLogger = () => { + const server = process.env.GRAYLOG_SERVER; + const port = process.env.GRAYLOG_PORT; + const env = process.env.NODE_ENV || 'unset'; + setLogger([ + new ConsoleLogger(), // Log to console + new GrayLogLogger( // Log to Graylog + server, + parseInt(port), + { facility: 'DMSC', environment: env, service: 'duo-cron-job' }, + [] + ), + ]); +}; + +module.exports = initializeLogger; diff --git a/example.env b/example.env index 7f93849..ef9cd3c 100644 --- a/example.env +++ b/example.env @@ -8,4 +8,6 @@ API_URL=[duo-backend-url] # - UserQueries.getAll # - FeedbackMutations.requestFeedback # - UserMutations.delete -API_AUTH_TOKEN=[duo-backend-auhentication-token] \ No newline at end of file +API_AUTH_TOKEN=[duo-backend-auhentication-token] +# GRAYLOG_SERVER= +# GRAYLOG_PORT= \ No newline at end of file diff --git a/index.js b/index.js index 6550e0e..b92c684 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,14 @@ require('./config/configureAndValidate'); +const { logger } = require('@user-office-software/duo-logger'); +const initializeLogger = require('./config/initializeLogger'); const ALLJOBS = require('./lib/allJobs'); const runAllJobs = require('./lib/runAllJobs'); const bootstrap = () => { // NOTE: Run all predefined jobs runAllJobs(ALLJOBS); + logger.logInfo('Cronjob', { msg: 'All jobs are running' }); }; +initializeLogger(); bootstrap();