How to use the getLogger function from log4js

Find comprehensive JavaScript log4js.getLogger code examples handpicked from public code repositorys.

log4js.getLogger returns an instance of a logger for the specified category.

17
18
19
20
21
22
23
24
25
26
27
28
configuration.parseOptions();


// log4js
const log4js = require('log4js');
const { url } = require('inspector');
var logger = log4js.getLogger();


// The queryCache.
const queryCache = new Map();

fork icon23
star icon90
watch icon13

+ 9 other calls in file

8
9
10
11
12
13
14
15
16
17
18
19
20
21


const fs = require('fs');


// log4js
const log4js = require('log4js');
const logger = log4js.getLogger();


const { Octokit } = require('@octokit/rest');


const yodaAppModule = require('./github-app.js');
fork icon23
star icon90
watch icon13

+ 9 other calls in file

How does log4js.getLogger work?

log4js.getLogger is a function provided by the Log4js library in Node.js that returns a logger object associated with the given category name, which can be used to log messages with different log levels and to define custom appenders and layouts for each logger instance. The logger object returned by getLogger provides methods such as trace, debug, info, warn, error, and fatal to log messages with different levels of severity, and supports configuration options such as output format, log file location, and log rolling policies.

6
7
8
9
10
11
12
13
14
15
16
const { badRequest, convertErrorArrayToObject } = require("@utils/errors");
const isEmpty = require("is-empty");
const controlAccessUtil = require("@utils/control-access");
const constants = require("@config/constants");
const log4js = require("log4js");
const logger = log4js.getLogger(
  `${constants.ENVIRONMENT} -- create-user-controller`
);


const createUser = {
fork icon10
star icon11
watch icon5

+ 2 other calls in file

52
53
54
55
56
57
58
59
60
61
        },
        categories: {
            default: { appenders: ['file'], level }
        }
    });
    return log4js.getLogger(mo.config.name)
};

const getFunctions = s => {
    let functionsHandle = {};
fork icon9
star icon7
watch icon10

+ 3 other calls in file

Ai Example

1
2
3
4
5
6
7
8
const log4js = require("log4js");

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

logger.info("This is an informational message.");
logger.debug("This is a debug message.");
logger.error("This is an error message.");

In this example, log4js.getLogger is used to create a new logger with the name 'myLogger'. The level property is set to 'debug' to enable debug-level logging. The logger object is then used to log messages at various levels of severity, including informational, debug, and error messages.

28
29
30
31
32
33
34
35
36
37
```javascript
log4js.configure({
  appenders: { 'out': { type: 'stdout', layout: { type: 'basic' } } },
  categories: { default: { appenders: ['out'], level: 'info' } }
});
const logger = log4js.getLogger('cheese');
logger.error('Cheese is too ripe!');
```
This will output:
```
fork icon779
star icon0
watch icon0

+ 11 other calls in file

71
72
73
74
75
76
77
78
79
80
        console.warn = logger.warn.bind(logger);
        console.error = logger.error.bind(logger);
        console.debug = logger.debug.bind(logger);
}
exports.getLogger = function (){
        return log4js.getLogger.apply(log4js, Array.prototype.slice.call(arguments));
};
exports.trace = function (){
        return logger.trace.apply(logger, Array.prototype.slice.call(arguments));
};
fork icon182
star icon152
watch icon33

+ 7 other calls in file

37
38
39
40
41
42
43
44
45
46

const loggerCategory = getEnv() === 'test'
  ? 'test'
  : 'default'

const loggerEngine = log4js.getLogger(loggerCategory)

const { logger } = escriba({
  loggerEngine,
  service: 'superbowleto',
fork icon73
star icon597
watch icon101

+ 3 other calls in file

73
74
75
76
77
78
79
80
});


log4j.configure(log4jConfig);

const logger = log4j.getLogger('console');
console.warn = logger.warn.bind(logger);
console.error = logger.error.bind(logger);
fork icon35
star icon137
watch icon11

+ 3 other calls in file

13
14
15
16
17
18
19
20
21
22
      return JSON.stringify(logEvent) + config.separator;
    }
);
const logConf = require('./conf/log.conf');
log4js.configure(logConf);
const logger = log4js.getLogger('chatLog');

// 开发模式热更新
if (process.env.NODE_ENV !== 'production') {
  var webpack = require('webpack');
fork icon25
star icon76
watch icon4

+ 3 other calls in file

23
24
25
26
27
28
29
30
31
32
        log4js.configure(configuration);
    }
    catch(err){
        console.log('Error: ' + err.message);
    }
    this.baseLogger = log4js.getLogger();
}

get logger(){
    return this.baseLogger;
fork icon2
star icon15
watch icon0

34
35
36
37
38
39
40
41
42
43
    },
    categories: {
        default: { appenders: ['out', 'type'], level: 'info' }
    }
})
var logger = log4js.getLogger('json-test')
exports.logger = logger;
exports.use = function (app) {
    app.use(log4js.connectLogger(logger, { level: 'info', format: ':method:url' }))
}
fork icon2
star icon9
watch icon0

+ 7 other calls in file

300
301
302
303
304
305
306
307
308
309
let deviceService = new DeviceService(new AdbWrapper());

log.debug("Registering ipc handlers...");

ipcMain.handle("log", (_event, level, msg) => {
  log4js.getLogger("ui").log(level, msg);
});

ipcMain.on("body-captured", (_event, image) => {
  const fs = require("fs");
fork icon2
star icon15
watch icon0

+ 3 other calls in file

31
32
33
34
35
36
37
38
39
40
41
42
var ResourcePlural = require("./ResourcePlural.js");
var ResourceArray = require("./ResourceArray.js");
var ResourceFactory = require("./ResourceFactory.js");
var TranslationUnit = require("./Xliff.js").TranslationUnit;


var logger = log4js.getLogger("loctool.lib.Tmx");


/**
 * @class A class that represents a tmx translation unit variant.
 *
fork icon4
star icon10
watch icon8

+ 4 other calls in file

27
28
29
30
31
32
33
34
35
36
37
const { Sequelize, DataTypes } = require('sequelize');
const sequelize = new Sequelize('sqlite::memory:', {
    logging: (log) => { sequelize_logger.debug(log) }
}); // Example for sqlite
const { randomFillSync } = require('crypto');
const sequelize_logger = log4js.getLogger('Sequelize');
sequelize_logger.level = 'info';


const Challenge = sequelize.define('Challenge', {
    challenge: {
fork icon4
star icon8
watch icon3

+ 19 other calls in file

4
5
6
7
8
9
10
11
12
13
*/
var express = require('express');
var path = require('path');
//var logger = require('morgan');
const log4js = require('log4js');
const logger = log4js.getLogger('app.js');
logger.level = 'debug';
const log4jex = require('log4js-extend');
log4jex(log4js);

fork icon4
star icon8
watch icon3

+ 9 other calls in file

7
8
9
10
11
12
13
14
15
16
const sequelize = new Sequelize('sqlite::memory:', {
    logging: (log) => { sequelize_logger.debug(log) }
}); // Example for sqlite
const { randomFillSync } = require('crypto');
const log4js = require('log4js');
const logger = log4js.getLogger('tokenmanager.js');
logger.level = 'info';
const sequelize_logger = log4js.getLogger('Sequelize');
sequelize_logger.level = 'info';

fork icon4
star icon8
watch icon3

+ 19 other calls in file

10
11
12
13
14
15
16
17
18
19
//const { request } = require('./app');
const tokenManager = require('./tokenmanager');
const keyManager = require('./keymanager');
const log4js = require('log4js');
const { match } = require('assert');
const logger = log4js.getLogger('teep-p.js');
logger.level = 'debug';
const rats = require('./rats');
const tam_config = require('./config.json');

fork icon4
star icon8
watch icon3

+ 9 other calls in file

40
41
42
43
44
45
46
47
48
        }
    }
});


const logger = log4js.getLogger('test-cat');

logger.debug('done', new Error('salim'), 'test', { a: 1, b: 2 });

fork icon1
star icon0
watch icon1

+ 3 other calls in file

27
28
29
30
31
32
33
34
35
36
37
const envConfig = require('../../config/envConfig');
let logger;
if (envConfig.NODE_ENV === 'prod') {
  logger = log4js.getLogger('production');
} else {
  logger = log4js.getLogger();
}


module.exports = {
  productCreate: async (req, res) => {
fork icon0
star icon2
watch icon0

38
39
40
41
42
43
44
45
46
47
      enableCallStack: true
    }
  }
});

const logger = log4js.getLogger('TestLogNode');

function main() {
  logger.info('main start...');
  logger.info('main end.');
fork icon0
star icon2
watch icon2