Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging API support? #134

Open
SilentAntenna opened this issue Aug 7, 2022 · 3 comments
Open

Logging API support? #134

SilentAntenna opened this issue Aug 7, 2022 · 3 comments
Assignees

Comments

@SilentAntenna
Copy link

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.

@appy-one
Copy link
Owner

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

@appy-one appy-one self-assigned this Aug 15, 2022
@Azarattum
Copy link

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.

@appy-one
Copy link
Owner

I think this a pretty good workaround proposed by @Azarattum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants