Skip to content

Commit 4bdad75

Browse files
committed
feat(backend): improve logger and reduce logs
1 parent 522664d commit 4bdad75

File tree

18 files changed

+94
-64
lines changed

18 files changed

+94
-64
lines changed

package-lock.json

+15-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
]
4444
},
4545
"dependencies": {
46+
"json-colorizer": "^3.0.1",
4647
"uuid": "^9.0.1"
4748
}
4849
}

packages/backend/src/Kernel.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Kernel extends AdvancedBase {
4242
// Temporary logger for boot process;
4343
// LoggerService will be initialized in app.js
4444
const bootLogger = new BootLogger();
45+
this.bootLogger = bootLogger;
4546

4647
// Determine config and runtime locations
4748
const runtimeEnv = new RuntimeEnvironment({
@@ -83,13 +84,14 @@ class Kernel extends AdvancedBase {
8384
// === START: Initialize Service Registry ===
8485
const { Container } = require('./services/Container');
8586

86-
const services = new Container();
87+
const services = new Container({ logger: this.bootLogger });
8788
this.services = services;
8889
// app.set('services', services);
8990

9091
const root_context = Context.create({
9192
services,
9293
config,
94+
logger: this.bootLogger,
9395
}, 'app');
9496
globalThis.root_context = root_context;
9597

packages/backend/src/filesystem/FSNodeContext.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,7 @@ module.exports = class FSNodeContext {
208208
return;
209209
}
210210

211-
// NOTE: commented out for now because it's too verbose
212-
this.log.info('fetching entry: ' + this.selector.describe(true));
211+
this.log.info('fetching entry: ' + this.selector.describe());
213212
// All services at the top (DEVLOG-401)
214213
const {
215214
traceService,
@@ -239,9 +238,6 @@ module.exports = class FSNodeContext {
239238

240239
const callback = (resolver) => {
241240
// NOTE: commented out for now because it's too verbose
242-
this.log.noticeme(`resolved by ${resolver}`, {
243-
debug: fetch_entry_options.debug,
244-
});
245241
resolved = true;
246242
detachables.detach();
247243
rslv();
@@ -273,13 +269,10 @@ module.exports = class FSNodeContext {
273269
}
274270
});
275271

276-
this.log.debug('got past the promise')
277-
278272
if ( resourceService.getResourceInfo(this.uid) ) {
279273
entry = await fsEntryService.get(this.uid, fetch_entry_options);
280274
this.log.debug('got an entry from the future');
281275
} else {
282-
this.log.debug('resource is already free');
283276
entry = await fsEntryFetcher.find(
284277
this.selector, fetch_entry_options);
285278
}
@@ -734,7 +727,6 @@ module.exports = class FSNodeContext {
734727
this.log.warn('null app');
735728
continue;
736729
}
737-
this.log.debug('app?', { value: app });
738730
delete app.owner_user_id;
739731
}
740732
}

packages/backend/src/filesystem/storage/ResourceService.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class ResourceService {
7474
}
7575

7676
free (uid) {
77-
this.log.info(`freeing`, uid);
77+
this.log.info(`freeing`, { uid });
7878
const entry = this.uidToEntry[uid];
7979
if ( ! entry ) return;
8080
delete this.uidToEntry[uid];

packages/backend/src/om/entitystorage/ESBuilder.js

-4
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,13 @@ class ESBuilder {
2525
let last_was_cons = false;
2626
while ( ! last_was_cons ) {
2727
const item = stack.pop();
28-
console.log('item?', item)
2928
if ( typeof item === 'function' ) {
30-
console.log('last was cons')
3129
last_was_cons = true;
3230
}
3331
args.unshift(item);
3432
}
3533

3634
const cls = args.shift();
37-
console.log('cls?', cls)
3835
head = new cls({
3936
...(args[0] ?? {}),
4037
...(head ? { upstream: head } : {}),
@@ -55,7 +52,6 @@ class ESBuilder {
5552
// Print the classes in order
5653
let current = head;
5754
while ( current ) {
58-
console.log(current.constructor.name);
5955
current = current.upstream;
6056
}
6157

packages/backend/src/om/entitystorage/MaxLimitES.js

-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ class MaxLimitES extends BaseES {
3535

3636
options.limit = limit;
3737

38-
console.log('SELECT options (1)', options);
39-
4038
return await this.upstream.select(options);
4139
}
4240
};

packages/backend/src/routers/filesystem_api/batch/all.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,13 @@ module.exports = eggspress('/batch', {
141141
return;
142142
}
143143

144-
// log fileinfos
145-
console.log('HERE ARE THE FILEINFOS');
146-
console.log(JSON.stringify(fileinfos, null, 2));
147-
148144
const indexes_to_remove = [];
149145

150146
for ( let i=0 ; i < pending_operations.length ; i++ ) {
151147
const op_spec = pending_operations[i];
152148
if ( ! operation_requires_file(op_spec) ) {
153149
indexes_to_remove.push(i);
154-
console.log(`EXEUCING OP ${op_spec.op}`)
150+
log.info(`executing ${op_spec.op}`);
155151
response_promises.push(
156152
batch_exe.exec_op(req, op_spec)
157153
);
@@ -231,7 +227,6 @@ module.exports = eggspress('/batch', {
231227
batch_widget.ic = pending_operations.length;
232228
on_first_file();
233229
}
234-
console.log(`GOT A FILE`)
235230

236231
if ( fileinfos.length == 0 ) {
237232
request_errors_.push(
@@ -256,7 +251,6 @@ module.exports = eggspress('/batch', {
256251
stream.on('end', () => {
257252
stream.destroy();
258253
});
259-
console.log('DISCARDED A FILE');
260254
return;
261255
}
262256

@@ -269,7 +263,7 @@ module.exports = eggspress('/batch', {
269263
});
270264

271265
busboy.on('close', () => {
272-
console.log('GOT DONE READING');
266+
log.info('busboy close');
273267
still_reading.resolve();
274268
});
275269

@@ -284,11 +278,11 @@ module.exports = eggspress('/batch', {
284278
return;
285279
}
286280

287-
log.noticeme('WAITING ON OPERATIONS')
281+
log.info('waiting for operations')
288282
let responsePromises = response_promises;
289283
// let responsePromises = batch_exe.responsePromises;
290284
const results = await Promise.all(responsePromises);
291-
log.noticeme('RESPONSE GETS SENT!');
285+
log.info('sending response');
292286

293287
frame.done();
294288

packages/backend/src/routers/whoami.js

-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ const WHOAMI_GET = eggspress('/whoami', {
4141

4242
const is_user = actor.type instanceof UserActorType;
4343

44-
console.log('user?', req.user);
45-
4644
// send user object
4745
const details = {
4846
username: req.user.username,

packages/backend/src/services/AppInformationService.js

-8
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,6 @@ class AppInformationService {
170170
[origin + '%']
171171
))[0];
172172

173-
if ( app.uid === 'app-eeec9a28-0eb1-5b63-a2dd-b99a8a3cf4c3' ) {
174-
console.log('app?', app);
175-
console.log('REFERRAL COUNT', referral_count, {
176-
sql,
177-
index_url: app.index_url,
178-
});
179-
}
180-
181173
kv.set(key_referral_count, referral_count);
182174
}
183175

packages/backend/src/services/Container.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
*/
1919
const config = require("../config");
20+
const { Context } = require("../util/context");
2021
const { CompositeError } = require("../util/errorutil");
2122
const { TeePromise } = require("../util/promise");
2223

2324
// 17 lines of code instead of an entire dependency-injection framework
2425
class Container {
25-
constructor () {
26+
constructor ({ logger }) {
27+
this.logger = logger;
2628
this.instances_ = {};
2729
this.ready = new TeePromise();
2830
}
@@ -83,12 +85,12 @@ class Container {
8385

8486
async init () {
8587
for ( const k in this.instances_ ) {
86-
console.log(`constructing ${k}`);
88+
this.logger.info(`constructing ${k}`);
8789
await this.instances_[k].construct();
8890
}
8991
const init_failures = [];
9092
for ( const k in this.instances_ ) {
91-
console.log(`initializing ${k}`);
93+
this.logger.info(`initializing ${k}`);
9294
try {
9395
await this.instances_[k].init();
9496
} catch (e) {

packages/backend/src/services/DevWatcherService.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,18 @@ class DevWatcherService extends BaseService {
5454
// but hey at least we have this convenient event listener.
5555
async ['__on_ready.webserver'] () {
5656
const { root, commands } = this.args;
57+
let promises = [];
5758
for ( const entry of commands ) {
5859
const { directory } = entry;
5960
const fullpath = this.modules.path.join(
6061
root, directory);
61-
this.start_({ ...entry, fullpath });
62+
promises.push(this.start_({ ...entry, fullpath }));
6263
}
64+
await Promise.all(promises);
65+
66+
// It's difficult to tell when webpack is "done" its first
67+
// run so we just wait a bit before we say we're ready.
68+
await new Promise((resolve) => setTimeout(resolve, 3000));
6369
}
6470

6571
log_ (name, isErr, line) {

packages/backend/src/services/EmailService.js

-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ class Emailservice extends BaseService {
161161
}
162162

163163
_init () {
164-
console.log('the config', this.config);
165164
}
166165

167166
get_transport_ () {

packages/backend/src/services/WebServerService.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class WebServerService extends BaseService {
5757
const services = this.services;
5858
await services.emit('start.webserver');
5959
await services.emit('ready.webserver');
60+
this.print_puter_logo_();
6061
}
6162

6263
async ['__on_start.webserver'] () {
@@ -132,7 +133,7 @@ class WebServerService extends BaseService {
132133
const lines = [
133134
"",
134135
`Puter is now live at: ${link}`,
135-
`Type web:dismiss to dismiss this message`,
136+
`Type web:dismiss to un-stick this message`,
136137
"",
137138
];
138139
const lengths = [
@@ -149,8 +150,6 @@ class WebServerService extends BaseService {
149150
if ( svc_devConsole ) svc_devConsole.add_widget(this.startup_widget);
150151
}
151152

152-
this.print_puter_logo_();
153-
154153
server.timeout = 1000 * 60 * 60 * 2; // 2 hours
155154
server.requestTimeout = 1000 * 60 * 60 * 2; // 2 hours
156155
server.headersTimeout = 1000 * 60 * 60 * 2; // 2 hours

packages/backend/src/services/auth/ACLService.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ class ACLService extends BaseService {
100100
`fs:${await perm_fsNode.get('uid')}:${mode}`
101101
);
102102
if ( perm ) {
103-
console.log('TRUE BECAUSE PERMISSION', perm)
104-
console.log(`fs:${await perm_fsNode.get('uid')}:${mode}`)
103+
// console.log('TRUE BECAUSE PERMISSION', perm)
104+
// console.log(`fs:${await perm_fsNode.get('uid')}:${mode}`)
105105
return true;
106106
}
107107
}

packages/backend/src/services/drivers/implementations/BaseImplementation.js

-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ class BaseImplementation extends AdvancedBase {
109109
sla_key
110110
);
111111

112-
console.log('SLA KEY', sla_key, 'USER KEY', user_is_verified ? 'user_verified' : 'user_unverified');
113-
114112
const user_method_key = `actor:${actor.uid}:${method_key}`;
115113

116114
// short-term rate limiting

0 commit comments

Comments
 (0)