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

[QUESTION] How to change the NLP dock logger ? #1323

Open
dooznvcs opened this issue Jun 11, 2023 · 2 comments
Open

[QUESTION] How to change the NLP dock logger ? #1323

dooznvcs opened this issue Jun 11, 2023 · 2 comments

Comments

@dooznvcs
Copy link

dooznvcs commented Jun 11, 2023

I would like to change the dock logger so I can use my own
I use the example given here to register my own logger

import { defaultContainer, dockStart } from '@nlpjs/basic';
import { MyCustomLoggerClass } from './some-file';

defaultContainer.register('logger', new MyCustomLoggerClass());

const dock = await dockStart(this.options.dock);
const manager = dock.get('nlp');

manager.addCorpus(corpusFilePath);

await manager.train();
export class MyCustomLoggerClass {
    public constructor() {}

    public trace(...messages: string[]): void {
        console.trace('[TRACE]', ...messages);
    }

    public debug(...messages: string[]): void {
        console.debug('[DEBUG]', ...messages);
    }

    public info(...messages: string[]): void {
        console.info('[INFO]', ...messages);
    }

    public log(...messages: string[]): void {
        console.log('[LOG]', ...messages);
    }

    public warn(...messages: string[]): void {
        console.warn('[WARN]', ...messages);
    }

    public error(...messages: string[]): void {
        console.error('[ERROR]', ...messages);
    }

    public fatal(...messages: string[]): void {
        console.error('[FATAL]', ...messages);
    }
}

But the logs still remain unchanged

image

@dooznvcs dooznvcs reopened this Jun 13, 2023
@dooznvcs
Copy link
Author

I reopen this issue because I still don’t have the solution... Even using the Adding your own logger to the container example, the instance of my logger is still not active. Even copying the example, the custom logger didn’t work.

I changed my code this way:

import { dockStart } from '@nlpjs/basic';
import { MyCustomLoggerClass } from './some-file';

const dock = await dockStart(this.options.dock);

const container = dock.getContainer();
const manager = dock.get('nlp');

container.register('logger', new MyCustomLoggerClass());
manager.addCorpus(corpusFilePath);

await manager.train();

@jesus-seijas-sp
Copy link
Contributor

Hello,
You're correctly changing the logger.
The problem is that the neural trainer does not use the logger from the container.
When the neural trainer is created it accepts a setting "log" that can be true to use the default console, false to don't log or a function to use this function to log.
https://github.com/axa-group/nlp.js/blob/master/packages/neural/src/neural-network.js#L40

You can change the function that logs the neural trainer:

const { dockStart } = require('@nlpjs/basic');

(async () => {
  const config = {
    settings: {
      nlp: {
        nlu: {
          log: (status, time) => console.log(`custom log: ${status.iterations} ${status.error} ${time}ms`),
        },
        corpora: [
          "./corpus-en.json"
        ]
      }
    },
    use: ["Basic"]
  }

  const dock = await dockStart(config);

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

No branches or pull requests

2 participants