10
10
11
11
12
12
class ResurfaceWarning (UserWarning ):
13
- pass
13
+ def __init__ (self , warning_type , environment_var = None , required_type = None ):
14
+ self .warning_type = warning_type
15
+ self .env_var = environment_var
16
+ self .required_type = required_type
17
+ def __str__ (self ):
18
+ if self .warning_type == "argwarn" :
19
+ warn = f"Invalid type for { self .env_var } " + \
20
+ f"(argument should be a { self .required_type } ). " + \
21
+ "Logger won't be enabled."
22
+ elif self .warning_type == "nologgerwarn" :
23
+ warn = "Logger is not enabled."
24
+ return warn
14
25
15
26
16
27
class HttpLogger (BaseLogger ):
@@ -29,14 +40,10 @@ def __init__(
29
40
rules : Optional [str ] = None ,
30
41
) -> None :
31
42
32
- argtype_warn = (
33
- "Resurface: Invalid type for {} "
34
- "(argument should be a {}). Logger won't be enabled."
35
- )
36
43
if url and not isinstance (url , str ):
37
- warnings .warn (argtype_warn . format ( " url" , "string" ), ResurfaceWarning )
44
+ warnings .warn (ResurfaceWarning ( "argwarn" , " url" , "string" ))
38
45
if rules and not isinstance (rules , str ):
39
- warnings .warn (argtype_warn . format ( " rules" , "string" ), ResurfaceWarning )
46
+ warnings .warn (ResurfaceWarning ( "argwarn" , " rules" , "string" ))
40
47
41
48
super ().__init__ (
42
49
self .AGENT ,
@@ -63,7 +70,7 @@ def __init__(
63
70
self ._enabled = False
64
71
65
72
if not self .enabled :
66
- warnings .warn ("Resurface: Logger is not enabled." , ResurfaceWarning )
73
+ warnings .warn (ResurfaceWarning ( "nologgerwarn" ) )
67
74
68
75
@property
69
76
def rules (self ) -> HttpRules :
0 commit comments