Skip to content

Commit 135b5ec

Browse files
authored
Merge pull request #448 from HeyPuter/eric/log-update
feat(backend): improve logger and reduce logs
2 parents 522664d + 2d8e624 commit 135b5ec

21 files changed

+219
-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/CoreModule.js

+3
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ const install = async ({ services, app }) => {
222222

223223
const { DetailProviderService } = require('./services/DetailProviderService');
224224
services.registerService('whoami', DetailProviderService);
225+
226+
const { DevTODService } = require('./services/DevTODService');
227+
services.registerService('__dev-tod', DevTODService);
225228
}
226229

227230
const install_legacy = async ({ services }) => {

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/DevConsoleService.js

+36
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class DevConsoleService extends BaseService {
5757
// if a widget throws an error we MUST remove it;
5858
// it's probably a stack overflow because it's printing.
5959
const to_remove = [];
60+
let positions = [];
6061
for ( const w of this.widgets ) {
6162
let output; try {
6263
output = w();
@@ -66,8 +67,43 @@ class DevConsoleService extends BaseService {
6667
continue;
6768
}
6869
output = Array.isArray(output) ? output : [output];
70+
positions.push([this.static_lines.length, output.length]);
6971
this.static_lines.push(...output);
7072
}
73+
74+
const DESIRED_MIN_OUT = 10;
75+
const size_ok = () =>
76+
process.stdout.rows - DESIRED_MIN_OUT > this.static_lines.length;
77+
let n_hidden = 0;
78+
for ( let i = this.widgets.length-1 ; i >= 0 ; i-- ) {
79+
if ( size_ok() ) break;
80+
const w = this.widgets[i];
81+
if ( ! w.unimportant ) continue;
82+
n_hidden++;
83+
const [start, length] = positions[i];
84+
this.static_lines.splice(start, length);
85+
// update positions
86+
for ( let j = i ; j < positions.length ; j++ ) {
87+
positions[j][0] -= length;
88+
}
89+
}
90+
for ( let i = this.widgets.length-1 ; i >= 0 ; i-- ) {
91+
if ( size_ok() ) break;
92+
n_hidden++;
93+
const w = this.widgets[i];
94+
const [start, length] = positions[i];
95+
this.static_lines.splice(start, length);
96+
}
97+
if ( n_hidden && size_ok() ) {
98+
this.static_lines.push(
99+
`\x1B[33m` +
100+
this.generateEnd(
101+
`[ ${n_hidden} widget${n_hidden === 1 ? '' : 's'} hidden ]`
102+
) +
103+
`\x1B[0m`
104+
);
105+
}
106+
71107
if (!this.arrays_equal(initialOutput, this.static_lines)) {
72108
this.mark_updated(); // Update only if outputs have changed
73109
}

0 commit comments

Comments
 (0)