[GH-ISSUE #134] Logging API support? #75

Open
opened 2026-05-23 08:29:19 -06:00 by gitea-mirror · 3 comments
Owner

Originally created by @SilentAntenna on GitHub (Aug 7, 2022).
Original GitHub issue: https://github.com/appy-one/acebase/issues/134

Originally assigned to: @appy-one on GitHub.

It would be nice if Acebase could provide a logging callback or a logging event. In this way, we may use libraries like log4js to save the logs for future inspection.

Originally created by @SilentAntenna on GitHub (Aug 7, 2022). Original GitHub issue: https://github.com/appy-one/acebase/issues/134 Originally assigned to: @appy-one on GitHub. It would be nice if Acebase could provide a logging callback or a logging event. In this way, we may use libraries like `log4js` to save the logs for future inspection.
gitea-mirror added the
feature request
label 2026-05-23 08:29:19 -06:00
Author
Owner

@appy-one commented on GitHub (Aug 15, 2022):

Thanks for your input, I'll see what I can do! 👍🏼

<!-- gh-comment-id:1215780167 --> @appy-one commented on GitHub (Aug 15, 2022): Thanks for your input, I'll see what I can do! 👍🏼
Author
Owner

@Azarattum commented on GitHub (Nov 27, 2022):

I agree that it would be extremely useful. Currently AceBase uses DebugLogger from acebase-core which does all the logging stuff. I suggest to add an option to acebase, acebase-client and acebase-server for providing your own DebugLogger compatible implementation. So it could look like:

const base = new AceBaseServer("default", {
  host: "localhost",
  port: 8080,
  logger: {
    verbose: (...args) => console.log(...args),
    log: (...args) => console.log(...args),
    warn: (...args) => console.warn(...args),
    error: (...args) => console.error(...args),
    write: (...args) => console.log(...args),
  }
});

Note, that your don't specify the log level here as you are handling all the levels yourself. If an override for a level is not specified, it will not be logged. @appy-one, let me know if you want me to work on PR for this. I guess we'll have to modify all the core, server, client and this package for it to work consistently.

@SilentAntenna if you need a workaround right now, you can write this before instantiating your AceBase client/server:

import { DebugLogger } from "acebase-core";

const logger = {
  verbose: (...args) => console.log(...args),
  log: (...args) => console.log(...args),
  warn: (...args) => console.warn(...args),
  error: (...args) => console.error(...args),
  write: (...args) => console.log(...args),
  setLevel: () => {},
};
Object.assign(DebugLogger.prototype, logger);

With this hack you can override the DebugLogger behavior with your implementation. Note, that you have to specify an empty function for setLevel, otherwise your custom behavior will be overwritten upon initialization.

<!-- gh-comment-id:1328185205 --> @Azarattum commented on GitHub (Nov 27, 2022): I agree that it would be extremely useful. Currently AceBase uses `DebugLogger` from `acebase-core` which does all the logging stuff. I suggest to add an option to `acebase`, `acebase-client` and `acebase-server` for providing your own `DebugLogger` compatible implementation. So it could look like: ```ts const base = new AceBaseServer("default", { host: "localhost", port: 8080, logger: { verbose: (...args) => console.log(...args), log: (...args) => console.log(...args), warn: (...args) => console.warn(...args), error: (...args) => console.error(...args), write: (...args) => console.log(...args), } }); ``` Note, that your don't specify the log level here as you are handling all the levels yourself. If an override for a level is not specified, it will not be logged. @appy-one, let me know if you want me to work on PR for this. I guess we'll have to modify all the `core`, `server`, `client` and this package for it to work consistently. @SilentAntenna if you need a workaround right now, you can write this before instantiating your AceBase client/server: ```ts import { DebugLogger } from "acebase-core"; const logger = { verbose: (...args) => console.log(...args), log: (...args) => console.log(...args), warn: (...args) => console.warn(...args), error: (...args) => console.error(...args), write: (...args) => console.log(...args), setLevel: () => {}, }; Object.assign(DebugLogger.prototype, logger); ``` With this **hack** you can override the `DebugLogger` behavior with your implementation. Note, that you have to specify an empty function for `setLevel`, otherwise your custom behavior will be overwritten upon initialization.
Author
Owner

@appy-one commented on GitHub (Nov 28, 2022):

I think this a pretty good workaround proposed by @Azarattum

<!-- gh-comment-id:1328912320 --> @appy-one commented on GitHub (Nov 28, 2022): I think this a pretty good workaround proposed by @Azarattum
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/acebase#75
No description provided.