EzDevInfo.com

log4js-node

A port of log4js to node.js

Is log4js library asynchronous?

I have small question to know whether log4js library is asynchronous. I tried to find the log4js document but no luck. I want to use this in my node js app's but before that i want to know is its asynchronous or not?


Source: (StackOverflow)

Logging server status

I am currently adding logs in my application using log4js (not the default sails logger). I'd like to be able to keep track of the server status : when it's up and down. Where should I put the logs to be able to know when the server is down?

Thanks for bringing me out of darkness


Source: (StackOverflow)

Advertisements

write logs in file using log4js in node js

my code is:

log4js.loadAppender('file');
log4js.addAppender(log4js.appenders.file('logs/cheese.log'), 'cheese');
logger.setLevel('DEBUG');

logger.trace('Entering cheese testing');
logger.debug('Got cheese.');
logger.info('Cheese is Gouda.');
logger.warn('Cheese is quite smelly.');
logger.error('Cheese is too ripe!');
logger.fatal('Cheese was breeding ground for listeria.');

it's creating a file named as 'cheese' but nothing is there inside that. How to write content in that?


Source: (StackOverflow)

Disable console printing in Log4js

I just enabled logging using Log4js in my Node.js application. I have used the config option from https://github.com/nomiddlename/log4js-node and it's working fine.

It writes the logs in the log file, as well as in the console. I do not want this to be printed in the console. Not able to figure out how to configure this. awfully sorry to ask this silly question.


Source: (StackOverflow)

how to use log4js in test case with karma?

currently I need to add log4js support in my test case, like below:

it(' QuestionController saveQuestion method Testing ',  inject(function(localStorageService) {
    ***var log4js = require('log4js');
    var logger = log4js.getLogger();
    logger.debug("Some debug messages");***

    expect({}).toEqual(localStorageService.get('questionInfoStorage'));

  }));

I have tried to include the log4js js and repire js file in karma.conf.js file, it is not working and giving some error like "Module name "events" has not been loaded yet for context" something.

Is there anybody coming the same issue previously? thanks advance!


Source: (StackOverflow)

How can I make log4js print objects like console.log does

I have a project that has JavaScript in 2 places. One is using node.js on the server-side while the other is obviously the browser JavaScript. I am required to support any browser and I'd like to have a single logging framework for all of them. I picked log4js which works great for logging strings but for objects it has a bit of difficulty.

In node when I do Logger.debug(someObject); I get a beautiful printout of the object. When I try to do this with my browser JavaScript I get [object Object] which is useless.

Anyone know how to do this?

(node is using the terminal as the output console and the browser JavaScript is using the Browser's (Chrome) Console)


Source: (StackOverflow)

Configurable rolling log file name

I am using log4js to log in my node js application. I have configured logger to create a log file when the file size reaches certain max size. The logger creates a file with same filename and '.' and index number is appended to the file name where index number is incremented every time a new file is created.

I use current timestamp when file is created in the filename as: 20150730060112.log then next files created are as 20150730060112.log.1, 20150730060112.log.2 20150730060112.log.3 and so on...

I want a next file to be created with current timestamp. For e.g. if 20150730060112.log file reaches maxLogSize at lets say on 2015-07-31at 07:04:13 then the filename of new file I want to be as 20150731070413.log.

Please let me know if this is possible or any work around to get to this.


Source: (StackOverflow)

log4js ConsoleAppender initialization

I'm wondering if anyone happens to have some experience using Log4js? It seems its normal ConsoleAppender isn't always ready to use immediately after it's added to a logger object... If I have two sequential script tags in a document like:

//Initialize logger
<script type="text/javascript">                   
      var logger = new Log4js.getLogger("JSLOG");
      logger.addAppender(new Log4js.ConsoleAppender(logger, false));
      logger.setLevel(Log4js.Level.INFO);         
</script>


//Use logger
<script type="text/javascript">
     logger.info('Test test');
</script>

... It causes the console pop-up (pop-up window) to appear with an error message on page load:

12:58:23 PM WARN Log4js - Could not run the listener function () {
    return fn.apply(object, arguments);
}. 
TypeError: this.outputElement is null

The console is still initialised, it's there afterward, but for just that first logger call it doesn't seem to be there fully. If I make the first logger call setTimeout("logger.info('test test')", 1000), it doesn't have the error. So it's like it's not ready immediately. Anyone see this before or know what a workaround might be?

Cheers


Source: (StackOverflow)

How to use non SMTP transport in log4js smtp appender?

If you read the log4js documentation for SMTP appender, you'll see example for SMTP transport, which even does not work well with latest nodemailer (I'm using nodemailer 1.3.0 at the time of writting).

Docs show this bad config as an example:

{ "appenders": [
    {
        "type": "smtp",
        "recipients": "foo@bar.com",
        "sendInterval": 60,
        "transport": "SMTP",
        "SMTP": {
            "host": "smtp.gmail.com",
            "secureConnection": true,
            "port": 465,
            "auth": {
                "user": "foo@bar.com",
                "pass": "bar_foo"
            }
        }
    }
] }

How to change config to use transport other than SMTP? What I want is to configure log4js to work with SendGrid.


Source: (StackOverflow)

How to exclude a log4js category from being logged to the default appenders

I'm using node-log4js. (it's log4JS, not log4J!) I thought of the loggers 'categories' to be just like the Strings you put in Log4J into the constructor of a logger (normally you put your fqn class name there), so that log4j can put logged things to the right location.

I got the following config:

{
    "appenders": [
        {
            "type": "console",
        },
        {
            "type": "file",
            "absolute": true,
            "filename": "/tmp/app.log",
            "maxLogSize": 20480,
            "backups": 10     
        },
        {
            "type": "console",
            "category": "app.access"
        }
    ]
}

The desired behaviour would be that all "app.access" stuff only goes to the last appender (which is, at the moment, the console, too, but could change in future). At the moment, all loggings with the category 'app.access' will be logged twice to console and once to file.

Is there a way to give those other two appenders a "all but app.access"-category? How?

Thank you very much in advance


Source: (StackOverflow)

Configure fileName of log4js in RollingFileStream

I am using log4js to log in my node js application. I have configured logger to create a new file when the file size reaches certain max size. The logger creates a file with same filename and '.' and index number is appended to the file name where index number is incremented every time a new file is created.

For e.g., running file is having filename as: 20150730060112.log then next files created are as

20150730060112.log.1, 
20150730060112.log.2
20150730060112.log.3 and so on...

I want a next file to be created with current timestamp and not with '.1'.


Source: (StackOverflow)

How to configure log4js in protractor

Can anyone suggest how to configure log4js in protractor config. When i use

var log4js = require('log4js');var logger = log4js.getLogger();

im able to print the logs in the console. But i want to configure the log4js to get the logs to a file.


Source: (StackOverflow)

WMB 7.0 : Can not locate 'Input' terminal on node 'Log4jLoggingPlugin'

I am getting error with 'Log4jLoggingPlugin' Node in WMB 7.0 on Windows 7 OS

Error Message:

Can not locate 'Input' terminal on node 'Log4jLoggingPlugin' PRT_CREIDOC.msgflow PRT_CREIDOC Unknown Message Flow Connection Problem

Could anybody help me to resolve this issue.


Source: (StackOverflow)

log4js (node) cannot send via SMTP appender with no auth

I'm using a port of log4js designed for javascript in node and am having some trouble using the SMTP appender where the SMTP relay does not use authentication

Here is my configuration:

"appenders": [ {
    "type": "smtp",
    "recipients": "recipient@gmail.com",
    "sendInterval": 60,
    "transport": "SMTP",
    "SMTP": {
        "host": "smtp.noauth.relay",
        "secureConnection": false,
        "port": 25,
        "auth": {
            "user": "anyemail@anydomain.com",
            "pass": ""
        }
    }
} ]

has anyone had any success with this? it works fine if I use gmail relay and put in my gmail credentials but other than that I can't work it.

edit okay so I'm getting some responses from the server saying authentication failed. so it seems like it is trying to authenticate itself with a blank password when the server expects no authentication. I removed the auth portion of from the config and the server gave an OK response. BUT... now I have to figure out how to send the sender address because they're just coming through as anonymous...

so here is the working config for no authentication:

"appenders": [ {
    "type": "smtp",
    "sender": "anyemail@anydomain.com"
    "recipients": "recipient@gmail.com",
    "sendInterval": 60,
    "transport": "SMTP",
    "SMTP": {
        "host": "smtp.noauth.relay",
        "secureConnection": false,
        "port": 25,
    }
} ]

hope this helps someone in the future


Source: (StackOverflow)

Log4js takes hours to write logfile

I am using log4js in my code to log the results and errors. The program runs for about 2,5 hours before the final console output is made and afterwards needs several hours to complete writing the logfile. The log is writing for 6 hours now (since the algorithm itself finished) and the filesize is 100mb. The log will be about 1,5 million lines (when done).

Is it normal for the log to be written as slow as this? Are there "standard" mistakes to make when using log4js that I could check?

In case you want to know: The program is running on an Intel i5 with 8gb RAM and an SSD drive, so the hardware shouldn't be the problem I guess.

I am not sure what other information I can give you, just ask ahead if you need to know something.


Source: (StackOverflow)