21
21
### ㊙️ Secrets ###
22
22
#######################################
23
23
24
+ """
25
+ In case, you use 1Password to store your settings, you can use :file:`.secrets.toml`
26
+ to retrieve and store your settings from a notesPlain item.
27
+ more info: https://support.1password.com/command-line-getting-started/
28
+
29
+ in order to use 1Password, you need to add the following to your :file:`.env` file:
30
+ - OP_SERVICE_ACCOUNT_TOKEN: your 1Password service account token
31
+ - OP_VAULT: your 1Password vault
32
+ - OP_ITEM: your 1Password item
33
+ - OP_PATH: your one 1Password path (optional and default value `/usr/bin/op`)
34
+
35
+ The :file:`.secrets.toml` will be located in :file:`/tt/.secrets.toml` and
36
+ be created by the OP client via `op read op://vault/item/notesPlain > .secrets.toml`
37
+
38
+ """
39
+
24
40
if os .getenv ("OP_SERVICE_ACCOUNT_TOKEN" ) and os .path .exists (os .getenv ("OP_PATH" )):
25
41
loguru_logger .debug ("Using OnePassword" )
26
42
command = [
39
55
### ⚙️ Settings ###
40
56
#######################################
41
57
58
+ """
59
+ Settings are loaded via dynaconf
60
+ Dynaconf is a powerful and easy-to-use
61
+ management library for Python.
62
+ It supports TOML settings file, .env file or environment variable, and other types.
63
+ Refer to https://github.com/dynaconf/dynaconf for more information.
64
+
65
+ More than 100 settings customizable via settings.toml or .env.
66
+ Most of them are predefined and you only need to
67
+ update the credentials related to your exchange and chat platform
68
+
69
+ Config will load:
70
+ - talky default: talky_settings.toml
71
+ - default from library if the library support it: default_settings.toml
72
+ - user settings: settings.toml
73
+ - user secrets: .secrets.toml
74
+
75
+ Your settings should be setup in
76
+ settings.toml,
77
+ .secrets.toml,
78
+ .env or
79
+ environment variable.
80
+ Settings.toml or .env can be located in :file:`/app/settings.toml`
81
+ or :file:`/app/.env` for docker.
82
+ If deployed locally, place your file in :file:`/tt/` folder.
83
+
84
+ """
85
+
42
86
ROOT = os .path .dirname (__file__ )
43
87
44
88
settings = Dynaconf (
67
111
### ⏱️ Scheduling ###
68
112
########################################
69
113
114
+ """
115
+ Scheduling is managed via asyncz lib
116
+ More info: https://github.com/tarsil/asyncz
117
+
118
+ It allows you to schedule tasks at plugin level.
119
+ Refer to the plugin documentation
120
+ :file:`tt.plugins.plugin_manager`
121
+
122
+ """
123
+
70
124
scheduler = AsyncIOScheduler ()
71
125
72
126
73
127
########################################
74
128
### 🧐 Logging ###
75
129
########################################
76
130
131
+ """
132
+ Logging is managed via loguru
133
+ """
134
+
77
135
78
136
class InterceptHandler (logging .Handler ):
137
+ """
138
+ InterceptHandler is a loguru handler
139
+ that intercepts all log records.
140
+ It can be used as a replacement for logging.basicConfig()
141
+ """
142
+
79
143
def emit (self , record ):
144
+ """
145
+ Emit a log record.
146
+
147
+ Args:
148
+ record (logging.LogRecord): The log record to emit.
149
+
150
+ Returns:
151
+ None
152
+ """
80
153
# Get corresponding Loguru level if it exists.
81
154
try :
82
155
level = logger .level (record .levelname ).name
@@ -95,6 +168,12 @@ def emit(self, record):
95
168
96
169
97
170
def loguru_setup ():
171
+ """
172
+ Set up the loguru logger with custom configurations.
173
+
174
+ Returns:
175
+ loguru.logger: The configured loguru logger instance.
176
+ """
98
177
loguru_logger .remove ()
99
178
log_filters = {
100
179
"discord" : settings .thirdparty_lib_loglevel ,
@@ -113,7 +192,14 @@ def loguru_setup():
113
192
filter = log_filters ,
114
193
)
115
194
if settings .loglevel == "DEBUG" :
116
- loguru_logger .warning ("DEBUG ENABLED" )
195
+ loguru_logger .warning (
196
+ """
197
+ DEBUG ENABLED,
198
+ You can disable it
199
+ loglevel='INFO' in settings.toml
200
+ TT_LOGLEVEL=INFO in your .env or vars.
201
+ """
202
+ )
117
203
return loguru_logger
118
204
119
205
0 commit comments