Skip to content

Commit

Permalink
feat(backend): improve logger and reduce logs
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelDeimos committed May 31, 2024
1 parent 522664d commit 46f13f9
Show file tree
Hide file tree
Showing 19 changed files with 99 additions and 64 deletions.
16 changes: 15 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
]
},
"dependencies": {
"json-colorizer": "^3.0.1",
"uuid": "^9.0.1"
}
}
4 changes: 3 additions & 1 deletion packages/backend/src/Kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Kernel extends AdvancedBase {
// Temporary logger for boot process;
// LoggerService will be initialized in app.js
const bootLogger = new BootLogger();
this.bootLogger = bootLogger;

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

const services = new Container();
const services = new Container({ logger: this.bootLogger });
this.services = services;
// app.set('services', services);

const root_context = Context.create({
services,
config,
logger: this.bootLogger,
}, 'app');
globalThis.root_context = root_context;

Expand Down
10 changes: 1 addition & 9 deletions packages/backend/src/filesystem/FSNodeContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ module.exports = class FSNodeContext {
return;
}

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

const callback = (resolver) => {
// NOTE: commented out for now because it's too verbose
this.log.noticeme(`resolved by ${resolver}`, {
debug: fetch_entry_options.debug,
});
resolved = true;
detachables.detach();
rslv();
Expand Down Expand Up @@ -273,13 +269,10 @@ module.exports = class FSNodeContext {
}
});

this.log.debug('got past the promise')

if ( resourceService.getResourceInfo(this.uid) ) {
entry = await fsEntryService.get(this.uid, fetch_entry_options);
this.log.debug('got an entry from the future');
} else {
this.log.debug('resource is already free');
entry = await fsEntryFetcher.find(
this.selector, fetch_entry_options);
}
Expand Down Expand Up @@ -734,7 +727,6 @@ module.exports = class FSNodeContext {
this.log.warn('null app');
continue;
}
this.log.debug('app?', { value: app });
delete app.owner_user_id;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/filesystem/storage/ResourceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ResourceService {
}

free (uid) {
this.log.info(`freeing`, uid);
this.log.info(`freeing`, { uid });
const entry = this.uidToEntry[uid];
if ( ! entry ) return;
delete this.uidToEntry[uid];
Expand Down
4 changes: 0 additions & 4 deletions packages/backend/src/om/entitystorage/ESBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,13 @@ class ESBuilder {
let last_was_cons = false;
while ( ! last_was_cons ) {
const item = stack.pop();
console.log('item?', item)
if ( typeof item === 'function' ) {
console.log('last was cons')
last_was_cons = true;
}
args.unshift(item);
}

const cls = args.shift();
console.log('cls?', cls)
head = new cls({
...(args[0] ?? {}),
...(head ? { upstream: head } : {}),
Expand All @@ -55,7 +52,6 @@ class ESBuilder {
// Print the classes in order
let current = head;
while ( current ) {
console.log(current.constructor.name);
current = current.upstream;
}

Expand Down
2 changes: 0 additions & 2 deletions packages/backend/src/om/entitystorage/MaxLimitES.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class MaxLimitES extends BaseES {

options.limit = limit;

console.log('SELECT options (1)', options);

return await this.upstream.select(options);
}
};
Expand Down
14 changes: 4 additions & 10 deletions packages/backend/src/routers/filesystem_api/batch/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,13 @@ module.exports = eggspress('/batch', {
return;
}

// log fileinfos
console.log('HERE ARE THE FILEINFOS');
console.log(JSON.stringify(fileinfos, null, 2));

const indexes_to_remove = [];

for ( let i=0 ; i < pending_operations.length ; i++ ) {
const op_spec = pending_operations[i];
if ( ! operation_requires_file(op_spec) ) {
indexes_to_remove.push(i);
console.log(`EXEUCING OP ${op_spec.op}`)
log.info(`executing ${op_spec.op}`);
response_promises.push(
batch_exe.exec_op(req, op_spec)
);
Expand Down Expand Up @@ -231,7 +227,6 @@ module.exports = eggspress('/batch', {
batch_widget.ic = pending_operations.length;
on_first_file();
}
console.log(`GOT A FILE`)

if ( fileinfos.length == 0 ) {
request_errors_.push(
Expand All @@ -256,7 +251,6 @@ module.exports = eggspress('/batch', {
stream.on('end', () => {
stream.destroy();
});
console.log('DISCARDED A FILE');
return;
}

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

busboy.on('close', () => {
console.log('GOT DONE READING');
log.info('busboy close');
still_reading.resolve();
});

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

log.noticeme('WAITING ON OPERATIONS')
log.info('waiting for operations')
let responsePromises = response_promises;
// let responsePromises = batch_exe.responsePromises;
const results = await Promise.all(responsePromises);
log.noticeme('RESPONSE GETS SENT!');
log.info('sending response');

frame.done();

Expand Down
2 changes: 0 additions & 2 deletions packages/backend/src/routers/whoami.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ const WHOAMI_GET = eggspress('/whoami', {

const is_user = actor.type instanceof UserActorType;

console.log('user?', req.user);

// send user object
const details = {
username: req.user.username,
Expand Down
8 changes: 0 additions & 8 deletions packages/backend/src/services/AppInformationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,6 @@ class AppInformationService {
[origin + '%']
))[0];

if ( app.uid === 'app-eeec9a28-0eb1-5b63-a2dd-b99a8a3cf4c3' ) {
console.log('app?', app);
console.log('REFERRAL COUNT', referral_count, {
sql,
index_url: app.index_url,
});
}

kv.set(key_referral_count, referral_count);
}

Expand Down
8 changes: 5 additions & 3 deletions packages/backend/src/services/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const config = require("../config");
const { Context } = require("../util/context");
const { CompositeError } = require("../util/errorutil");
const { TeePromise } = require("../util/promise");

// 17 lines of code instead of an entire dependency-injection framework
class Container {
constructor () {
constructor ({ logger }) {
this.logger = logger;
this.instances_ = {};
this.ready = new TeePromise();
}
Expand Down Expand Up @@ -83,12 +85,12 @@ class Container {

async init () {
for ( const k in this.instances_ ) {
console.log(`constructing ${k}`);
this.logger.info(`constructing ${k}`);
await this.instances_[k].construct();
}
const init_failures = [];
for ( const k in this.instances_ ) {
console.log(`initializing ${k}`);
this.logger.info(`initializing ${k}`);
try {
await this.instances_[k].init();
} catch (e) {
Expand Down
8 changes: 7 additions & 1 deletion packages/backend/src/services/DevWatcherService.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,18 @@ class DevWatcherService extends BaseService {
// but hey at least we have this convenient event listener.
async ['__on_ready.webserver'] () {
const { root, commands } = this.args;
let promises = [];
for ( const entry of commands ) {
const { directory } = entry;
const fullpath = this.modules.path.join(
root, directory);
this.start_({ ...entry, fullpath });
promises.push(this.start_({ ...entry, fullpath }));
}
await Promise.all(promises);

// It's difficult to tell when webpack is "done" its first
// run so we just wait a bit before we say we're ready.
await new Promise((resolve) => setTimeout(resolve, 3000));
}

log_ (name, isErr, line) {
Expand Down
1 change: 0 additions & 1 deletion packages/backend/src/services/EmailService.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ class Emailservice extends BaseService {
}

_init () {
console.log('the config', this.config);
}

get_transport_ () {
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/services/PrintPuterLogoService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const BaseService = require("./BaseService");

class PrintPuterLogoService extends BaseService {
//
}
5 changes: 2 additions & 3 deletions packages/backend/src/services/WebServerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class WebServerService extends BaseService {
const services = this.services;
await services.emit('start.webserver');
await services.emit('ready.webserver');
this.print_puter_logo_();
}

async ['__on_start.webserver'] () {
Expand Down Expand Up @@ -132,7 +133,7 @@ class WebServerService extends BaseService {
const lines = [
"",
`Puter is now live at: ${link}`,
`Type web:dismiss to dismiss this message`,
`Type web:dismiss to un-stick this message`,
"",
];
const lengths = [
Expand All @@ -149,8 +150,6 @@ class WebServerService extends BaseService {
if ( svc_devConsole ) svc_devConsole.add_widget(this.startup_widget);
}

this.print_puter_logo_();

server.timeout = 1000 * 60 * 60 * 2; // 2 hours
server.requestTimeout = 1000 * 60 * 60 * 2; // 2 hours
server.headersTimeout = 1000 * 60 * 60 * 2; // 2 hours
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/services/auth/ACLService.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class ACLService extends BaseService {
`fs:${await perm_fsNode.get('uid')}:${mode}`
);
if ( perm ) {
console.log('TRUE BECAUSE PERMISSION', perm)
console.log(`fs:${await perm_fsNode.get('uid')}:${mode}`)
// console.log('TRUE BECAUSE PERMISSION', perm)
// console.log(`fs:${await perm_fsNode.get('uid')}:${mode}`)
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ class BaseImplementation extends AdvancedBase {
sla_key
);

console.log('SLA KEY', sla_key, 'USER KEY', user_is_verified ? 'user_verified' : 'user_unverified');

const user_method_key = `actor:${actor.uid}:${method_key}`;

// short-term rate limiting
Expand Down
Loading

0 comments on commit 46f13f9

Please sign in to comment.