From bf78e1ffd3f6ce42a8964f63c0db458145f30ff5 Mon Sep 17 00:00:00 2001 From: FunctionsAPI Date: Tue, 28 Jan 2025 12:02:37 +0000 Subject: [PATCH] Automatic push from FunctionsAPI --- README.md | 3 +-- index.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 index.js diff --git a/README.md b/README.md index 757def8..ac78096 100644 --- a/README.md +++ b/README.md @@ -1,2 +1 @@ -# 14ac687eab7243d7800b380ed9156cf3 - +# commonjs hello-world diff --git a/index.js b/index.js new file mode 100644 index 0000000..1dd5215 --- /dev/null +++ b/index.js @@ -0,0 +1,31 @@ +const winston = require('winston'); + +// Configure logging using winston +const logger = winston.createLogger({ + level: 'info', + format: winston.format.combine( + winston.format.timestamp(), + winston.format.printf(({ timestamp, level, message }) => `${timestamp} - ${level.toUpperCase()}: ${message}`) + ), + transports: [ + new winston.transports.Console(), + new winston.transports.File({ filename: 'app.log' }) + ] +}); + +// Main function to add two numbers and log the result +function addNumbers(a, b) { + logger.info(`Function called with inputs: a=${a}, b=${b}`); + + const result = a + b; + + logger.info(`The result of adding ${a} and ${b} is: ${result}`); + return result; +} + +// Example usage +const num1 = 5; +const num2 = 8; +const sum = addNumbers(num1, num2); + +console.log(`Sum: ${sum}`); \ No newline at end of file