1
+ '''
2
+ /*
3
+ * EJERCICIO:
4
+ * Explora el concepto de "logging" en tu lenguaje. Configúralo y muestra
5
+ * un ejemplo con cada nivel de "severidad" disponible.
6
+ *
7
+ * DIFICULTAD EXTRA (opcional):
8
+ * Crea un programa ficticio de gestión de tareas que permita añadir, eliminar
9
+ * y listar dichas tareas.
10
+ * - Añadir: recibe nombre y descripción.
11
+ * - Eliminar: por nombre de la tarea.
12
+ * Implementa diferentes mensajes de log que muestren información según la
13
+ * tarea ejecutada (a tu elección).
14
+ * Utiliza el log para visualizar el tiempo de ejecución de cada tarea.
15
+ */
16
+ '''
17
+ #https://docs.python.org/3/library/logging.html
18
+ import logging
19
+ #https://docs.python.org/3/library/logging.html#logging.basicConfig
20
+ logging .basicConfig (level = logging .DEBUG , format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' )
21
+
22
+ logging .debug ('This is a debug message' ) #https://docs.python.org/3/library/logging.html#logging.debug
23
+ logging .info ('This is an info message' ) #https://docs.python.org/3/library/logging.html#logging.info
24
+ logging .warning ('This is a warning message' ) #https://docs.python.org/3/library/logging.html#logging.warning
25
+ logging .error ('This is an error message' ) #https://docs.python.org/3/library/logging.html#logging.error
26
+ logging .critical ('This is a critical message' ) #https://docs.python.org/3/library/logging.html#logging.critical
27
+
28
+ #DIFICULTAD EXTRA, GESTION DE TAREAS
29
+ import time
30
+ class Tarea :
31
+ def __init__ (self , nombre , descripcion ):
32
+ self .nombre = nombre
33
+ self .descripcion = descripcion
34
+
35
+ def __str__ (self ):
36
+ return f'{ self .nombre } - { self .descripcion } '
37
+
38
+ class GestorTareas :
39
+ def __init__ (self ):
40
+ self .tareas = []
41
+
42
+ def agregar_tarea (self , tarea ):
43
+ logging .info (f'Tarea añadida: { tarea } ' )
44
+ self .tareas .append (tarea )
45
+
46
+ def eliminar_tarea (self , nombre ):
47
+ for tarea in self .tareas :
48
+ if tarea .nombre == nombre :
49
+ self .tareas .remove (tarea )
50
+ logging .info (f'Tarea eliminada: { tarea } ' )
51
+ break
52
+
53
+ gestor = GestorTareas ()
54
+ logging .info ('Gestor de tareas creado' )
55
+ time .sleep (2 )
56
+ tarea1 = Tarea ('Tarea 1' , 'Salir a correr' )
57
+ gestor .agregar_tarea (tarea1 )
58
+ time .sleep (1 )
59
+ tarea2 = Tarea ('Tarea 2' , 'Terminar mi sitio web' )
60
+ gestor .agregar_tarea (tarea2 )
61
+ time .sleep (1 )
62
+ tarea3 = Tarea ('Tarea 3' , 'Estudiar Python' )
63
+ gestor .agregar_tarea (tarea3 )
64
+ time .sleep (2 )
65
+ logging .info ('Tareas añadidas' )
66
+ time .sleep (1 )
67
+ logging .info ('Eliminando tareas' )
68
+ time .sleep (2 )
69
+ gestor .eliminar_tarea ('Tarea 2' )
70
+ time .sleep (1 )
71
+ gestor .eliminar_tarea ('Tarea 1' )
72
+ time .sleep (1 )
73
+ gestor .eliminar_tarea ('Tarea 3' )
74
+ time .sleep (1 )
0 commit comments