Skip to content

Commit d598a99

Browse files
#25 - javascript
1 parent 0f4b28d commit d598a99

File tree

1 file changed

+167
-0
lines changed

1 file changed

+167
-0
lines changed
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
// #25 - LOGS
2+
/* EJERCICIO:
3+
* Explora el concepto de "logging" en tu lenguaje. Configúralo y muestra
4+
* un ejemplo con cada nivel de "severidad" disponible.
5+
*
6+
* DIFICULTAD EXTRA (opcional):
7+
* Crea un programa ficticio de gestión de tareas que permita añadir, eliminar
8+
* y listar dichas tareas.
9+
* - Añadir: recibe nombre y descripción.
10+
* - Eliminar: por nombre de la tarea.
11+
* Implementa diferentes mensajes de log que muestren información según la
12+
* tarea ejecutada (a tu elección).
13+
* Utiliza el log para visualizar el tiempo de ejecución de cada tarea. */
14+
15+
16+
//(Node.js is required to run the Extra Dificulty Exercise example)
17+
18+
let log = console.log;
19+
log("Retosparaprogramadores #14.");
20+
21+
const logDebug = (message) => console.debug(`DEBUG: ${message}`);
22+
const logInfo = (message) => console.info(`INFO: ${message}`);
23+
const logWarning = (message) => console.warn(`WARNING: ${message}`);
24+
const logError = (message) => console.error(`ERROR: ${message}`);
25+
const logCritical = (message) => console.error(`CRITICAL: ${message}`);
26+
27+
logDebug("This is a debug message.");
28+
logInfo("This is an informational message.");
29+
logWarning("This is a warning message.");
30+
logError("This is an error message.");
31+
logCritical("This is a critical message.");
32+
33+
34+
//EXTRA DIFICULTY EXERCISE (Node.js is required to run this example)
35+
36+
const readline = require('readline');
37+
38+
const rl = readline.createInterface({
39+
input: process.stdin,
40+
output: process.stdout
41+
});
42+
43+
class TaskManager {
44+
constructor() {
45+
this.tasks = {};
46+
}
47+
48+
addTask(name, description) {
49+
const startTime = Date.now();
50+
if (this.tasks[name]) {
51+
logWarning(`The task '${name}' already exists.`);
52+
this.promptEditTask(name);
53+
return;
54+
}
55+
this.tasks[name] = description;
56+
logInfo(`Task added: ${name} - ${description}`);
57+
const endTime = Date.now();
58+
logDebug(`Execution time for adding task: ${(endTime - startTime) / 1000} seconds`);
59+
}
60+
61+
promptEditTask(name) {
62+
rl.question(`The task '${name}' already exists. Do you want to edit it? (yes/no): `, (answer) => {
63+
if (answer.toLowerCase() === 'yes') {
64+
rl.question('Enter the new description: ', (newDescription) => {
65+
this.editTask(name, newDescription);
66+
rl.close();
67+
});
68+
} else {
69+
logInfo(`No changes made to the task '${name}'.`);
70+
rl.close();
71+
}
72+
});
73+
}
74+
75+
editTask(name, newDescription) {
76+
const startTime = Date.now();
77+
if (!this.tasks[name]) {
78+
logError(`Could not edit the task '${name}' because it does not exist.`);
79+
return;
80+
}
81+
this.tasks[name] = newDescription;
82+
logInfo(`Task edited: ${name} - New Description: ${newDescription}`);
83+
const endTime = Date.now();
84+
logDebug(`Execution time for editing task: ${(endTime - startTime) / 1000} seconds`);
85+
}
86+
87+
removeTask(name) {
88+
const startTime = Date.now();
89+
if (!this.tasks[name]) {
90+
logError(`Could not remove the task '${name}' because it does not exist.`);
91+
return;
92+
}
93+
delete this.tasks[name];
94+
logInfo(`Task removed: ${name}`);
95+
const endTime = Date.now();
96+
logDebug(`Execution time for removing task: ${(endTime - startTime) / 1000} seconds`);
97+
}
98+
99+
listTasks() {
100+
const startTime = Date.now();
101+
if (Object.keys(this.tasks).length === 0) {
102+
logWarning("No tasks to display.");
103+
return;
104+
}
105+
logInfo("Task list:");
106+
for (const [name, description] of Object.entries(this.tasks)) {
107+
logInfo(`- ${name}: ${description}`);
108+
}
109+
const endTime = Date.now();
110+
logDebug(`Execution time for listing tasks: ${(endTime - startTime) / 1000} seconds`);
111+
}
112+
}
113+
114+
const manager = new TaskManager();
115+
manager.addTask("Implement User Authentication", "Develop a user authentication system that allows users to register, log in, and log out securely.");
116+
manager.addTask("Fix Bug in Feature Resize window", "Fix Bug in Feature Resize window");
117+
manager.addTask("Write Unit Tests", "Write Unit Tests - Create tests for the user authentication module using Jest.");
118+
manager.addTask("Refactor Code for Module Lang_translation", "Refactor Code for Module Lang_translation - Simplify the logic and remove redundant code.");
119+
manager.addTask("Deploy Application to Production", "Deploy Application to Production - Set up CI/CD pipeline and deploy the latest build.");
120+
manager.listTasks();
121+
manager.removeTask("Implement User Authentication");
122+
manager.editTask("Fix Bug in Feature Resize window", "Fix Bug in Feature Resize window - Resolve the issue causing the application to crash on submission." );
123+
manager.listTasks();
124+
125+
/* Output: DEBUG: This is a debug message.
126+
INFO: This is an informational message.
127+
WARNING: This is a warning message.
128+
ERROR: This is an error message.
129+
CRITICAL: This is a critical message.
130+
INFO: Task added: Implement User Authentication - Develop a user authentication system that allows users to register, log in, and log out securely.
131+
DEBUG: Execution time for adding task: 0 seconds
132+
INFO: Task added: Fix Bug in Feature Resize window - Fix Bug in Feature Resize window
133+
DEBUG: Execution time for adding task: 0 seconds
134+
INFO: Task added: Write Unit Tests - Write Unit Tests - Create tests for the user authentication module using Jest.
135+
DEBUG: Execution time for adding task: 0 seconds
136+
INFO: Task added: Refactor Code for Module Lang_translation - Refactor Code for Module Lang_translation - Simplify the logic and remove redundant code.
137+
DEBUG: Execution time for adding task: 0.001 seconds
138+
INFO: Task added: Deploy Application to Production - Deploy Application to Production - Set up CI/CD pipeline and deploy the latest build.
139+
DEBUG: Execution time for adding task: 0.001 seconds
140+
INFO: Task list:
141+
INFO: - Implement User Authentication: Develop a user authentication system that allows users to register, log in, and log out securely.
142+
INFO: - Fix Bug in Feature Resize window: Fix Bug in Feature Resize window
143+
INFO: - Write Unit Tests: Write Unit Tests - Create tests for the user authentication module using Jest.
144+
INFO: - Refactor Code for Module Lang_translation: Refactor Code for Module Lang_translation - Simplify the logic and remove redundant code.
145+
INFO: - Deploy Application to Production: Deploy Application to Production - Set up CI/CD pipeline and deploy the latest build.
146+
DEBUG: Execution time for listing tasks: 0.006 seconds
147+
INFO: Task removed: Implement User Authentication
148+
DEBUG: Execution time for removing task: 0 seconds
149+
INFO: Task edited: Fix Bug in Feature Resize window - New Description: Fix Bug in Feature Resize window - Resolve the issue causing the application to crash on submission.
150+
DEBUG: Execution time for editing task: 0.004 seconds
151+
INFO: Task list:
152+
INFO: - Fix Bug in Feature Resize window: Fix Bug in Feature Resize window - Resolve the issue causing the application to crash on submission.
153+
INFO: - Write Unit Tests: Write Unit Tests - Create tests for the user authentication module using Jest.
154+
INFO: - Refactor Code for Module Lang_translation: Refactor Code for Module Lang_translation - Simplify the logic and remove redundant code.
155+
INFO: - Deploy Application to Production: Deploy Application to Production - Set up CI/CD pipeline and deploy the latest build.
156+
DEBUG: Execution time for listing tasks: 0.005 seconds */
157+
158+
159+
/*Info Note:
160+
Continuous Integration is a development practice where developers frequently integrate their code changes into a shared repository, usually several times a day.
161+
Each integration is automatically tested to detect errors quickly. This helps ensure that the codebase remains stable and that new changes do not break existing functionality.
162+
Tools commonly used for CI include Jenkins, Travis CI, CircleCI, GitHub Actions, and GitLab CI.
163+
CD (Continuous Delivery or Continuous Deployment):
164+
165+
Continuous Delivery is an extension of CI that ensures that the code is always in a deployable state. This means that after passing automated tests, the code can be deployed to production at any time.
166+
Continuous Deployment takes it a step further by automatically deploying every change that passes the tests to production without manual intervention.
167+
This practice allows for faster release cycles and more frequent updates to the application. */

0 commit comments

Comments
 (0)