Skip to content

Commit 33bf3fd

Browse files
authored
Merge the "release/v1.1.0" branch to the "main" branch
feat: Implement enhanced logging and Dockerignore improvements This change integrates features from the release/v1.1.0 branch. A new modular logging system is introduced using a logDebug function for structured, type-based console output To support this, the project now utilizes ES modules. The .dockerignore file has also been refined to optimize Docker image builds by excluding unnecessary files and removing duplicate entries, which contributes to a smaller image size and faster build times.
2 parents ac06ccb + ef80a1a commit 33bf3fd

File tree

4 files changed

+68
-10
lines changed

4 files changed

+68
-10
lines changed

.dockerignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Docker
22
.dockerignore
33
Dockerfile
4-
Dockerfile
54

65
# Git
76
.git/
@@ -11,6 +10,9 @@ Dockerfile
1110
# License
1211
LICENSE
1312

13+
# README
14+
README.md
15+
1416
# Gemini
1517
.gemini/
1618
GEMINI.md

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
<h1 id="clock" aria-live="polite"></h1>
2727
</div>
2828
<!-- Linking the JavaScript file -->
29-
<script src="index.js" defer></script>
29+
<script type="module" src="index.js" defer></script>
3030
</body>
3131
</html>

index.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
// index.js
44

5+
// Import the logDebug function from the logs module
6+
import { logDebug } from "./modules/logs/index.js";
7+
58
/**
69
* Starts the digital clock with the specified interval.
710
* If no interval is specified, it defaults to 1000 milliseconds (1 second).
@@ -31,23 +34,29 @@ function startClock(interval = 1000) {
3134
// Determine AM or PM
3235
const ampm = hours24 >= 12 ? "PM" : "AM";
3336

37+
// Log the updated time
38+
logDebug("log", `Updating clock: ${hours12}:${minutes}:${seconds} ${ampm}`);
39+
3440
// Update the clock element's text content
3541
clock.textContent = `${hours12}:${minutes}:${seconds} ${ampm}`;
3642
}
3743

38-
// If the clock element is not found, return an error
44+
// If the clock element is not found, log an error
3945
if(!clock){
40-
return console.error("Clock element not found in the DOM.");
46+
logDebug("error", "Clock element not found in the DOM.");
47+
return;
4148
}
42-
// else if the interval is less than or equal to 0, return an error
49+
// else if the interval is less than or equal to 0, log an error
4350
else if(interval <= 0){
44-
return console.error("Interval must be greater than 0.");
51+
logDebug("error", "Interval must be greater than 0.");
52+
return;
4553
}
4654
// else start the clock and update it at the specified interval
4755
else{
48-
// Log success messages
49-
console.log("Clock element found.");
50-
console.log(`Starting clock with an interval of ${interval} milliseconds.`);
56+
// Log success message
57+
logDebug("log", "Clock element found.");
58+
// Log starting message
59+
logDebug("log", `Starting clock with an interval of ${interval} milliseconds.`);
5160
// Initial
5261
update();
5362
// Set interval to update the clock every specified milliseconds
@@ -56,6 +65,6 @@ function startClock(interval = 1000) {
5665
}
5766

5867
// Log initialization message
59-
console.log("Digital Clock Program Initialized.");
68+
logDebug("log", "Initializing Digital Clock Program...");
6069
// Start the clock with default interval
6170
const intervalId = startClock();

modules/logs/index.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Digital Clock Program
2+
3+
// modules/logs/index.js
4+
5+
// Debugging flag
6+
const DEBUG = false;
7+
8+
/**
9+
* Logs a message to the console with a timestamp based on the type.
10+
* If type is "error", logs an error to the console.
11+
* If type is "warn", logs a warning to the console.
12+
* If type is "log" and DEBUG is true, logs to the console.
13+
* If type is invalid and DEBUG is true, logs a warning about invalid type.
14+
* If type is unhandled, logs an error to the console.
15+
* @param {string} type - The type of log message to log (error, warn, log).
16+
* @param {string} message - The message to log.
17+
*/
18+
export function logDebug(type, message){
19+
// Get the current timestamp for logging
20+
const timestamp = new Date().toISOString();
21+
22+
// Log the message based on the type
23+
// if type is "error", log an error, even if DEBUG is false
24+
if(type === "error"){
25+
console.error(`${timestamp} - ${message}`);
26+
}
27+
// else if type is "warn", log a warning, even if DEBUG is false
28+
else if(type === "warn"){
29+
console.warn(`${timestamp} - ${message}`);
30+
}
31+
// else if DEBUG is false, return nothing and do not log
32+
else if(!DEBUG){
33+
return;
34+
}
35+
// else if type is "log" and DEBUG is true, log to the console
36+
else if(type === "log" && DEBUG){
37+
console.log(`${timestamp} - ${message}`);
38+
}
39+
// else if type is invalid and DEBUG is true, log a warning about invalid type
40+
else if(type !== "log" && type !== "error" && type !== "warn" && DEBUG){
41+
console.warn(`${timestamp} - Invalid log type specified: ${type}`);
42+
}
43+
// else log an error for unhandled log types
44+
else{
45+
console.warn(`${timestamp} - Unhandled log type: ${type} with message: ${message}`);
46+
}
47+
}

0 commit comments

Comments
 (0)