8000 TypeError: log4js.getLogger is not a function · Issue #1410 · log4js-node/log4js-node · GitHub
[go: up one dir, main page]

Skip to content

TypeError: log4js.getLogger is not a function #1410

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

Open
TheChilliPL opened this issue Jan 4, 2024 · 6 8000 comments
Open

TypeError: log4js.getLogger is not a function #1410

TheChilliPL opened this issue Jan 4, 2024 · 6 comments

Comments

@TheChilliPL
Copy link

Trying to use anything in log4js causes a TypeError. IDE sees all the methods correctly, but TypeScript itself does not.

D:\Projects\eng_to_ipa>npm start -- trans

> eng-to-ipa@0.1.0 start
> npx tsx src/cli.ts trans

D:\Projects\eng_to_ipa\src\main.ts:3
export let defaultLogger = log4js.getLogger();
                                  ^


TypeError: log4js.getLogger is not a function
    at <anonymous> (D:\Projects\eng_to_ipa\src\main.ts:3:35)
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async loadESM (node:internal/process/esm_loader:28:7)
    at async handleMainPromise (node:internal/modules/run_main:120:12)

Node.js v21.5.0

D:\Projects\eng_to_ipa>

Importing with import { getLogger } from "log4js" doesn't work either

@lamweili
Copy link
Contributor
lamweili commented Jan 4, 2024

What's your import statement?
Could you show what's in your main.ts?

Did you try this?

import * as log4js from "log4js";
log4js.configure({
  appenders: { cheese: { type: "file", filename: "cheese.log" } },
  categories: { default: { appenders: ["cheese"], level: "error" } },
});

const logger = log4js.getLogger();
logger.level = "debug";
logger.debug("Some debug messages");

(src: https://github.com/log4js-node/log4js-node?tab=readme-ov-file#typescript)

@TheChilliPL
Copy link
Author

The whole main.ts is just

import * as log4js from "log4js";

export let defaultLogger = log4js.getLogger();

If I do configure first, it just does

TypeError: log4js.configure is not a function

@relandboyle
8000 Copy link

@TheChilliPL @lamweili
What was the resolution here? I'm running into the same issue, I think.

@TheChilliPL
Copy link
Author

@relandboyle Never fixed it, just never started using this logger, because I don't have the time necessary to debug this issue. If you find a way to fix it, however, please do let know!

@MizuYaYa
Copy link
import log4js from "log4js";

const logger = log4js.getLogger();
logger.level = "debug";

Now I was able to do it.
Hope this is useful.

@cjsilva-umich
Copy link
import log4js from "log4js";

const logger = log4js.getLogger();
logger.level = "debug";

Now I was able to do it. Hope this is useful.

This is the correct way to import. The documentation really needs to be updated. Just lost a lot of time trying to understand why I was getting the "log4js.[blank] is not a function" errors.

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

Successfully merging a pull request may close this issue.

5 participants
0