简体   繁体   中英

Log - vb.net to java

Can anybody explain what Log means in vb.net code? Is it the Logarithm function or some other log event. I did some search on this and I understood that this was for the Logarithm part. However, I do not understand the below line of code if I apply Logarithm to it.

tmp=pBuffer(5)+4
Log("tmp:" & tmp)

Can anyone explain this line of code and what is the equivalent java for the same?

This Log means log event,I think. Just for print the tmp value.

That line of code looks to be logging an event to a log file (or console) rather than the Logarithm mathematical operation.

There are many ways to do logging in Java, but the simplest (though not the nicest) is to do the following:

import java.util.logging.Logger;

public class Example {

    private static final Logger log = Logger.getLogger(Example.class.getName());

    static void doStuff(int[] pBuffer) {
        int tmp = pBuffer[5] + 4;
        log.info("tmp:" + tmp);
    }

    public static void main(String[] args) {
        doStuff(new int[] {0, 1, 2, 3, 4, 5});
    }
}

I've translated your example code verbatim as the function doStuff . If you run it, you'll get something like the following printed to the console:

12 17, 2012 4:47:01 PM Example doStuff
INFO: tmp:9

This code uses Java's built-in logging facility, which I have not used. If you need sophisticated logging functionality, I recommend SLF4J or log4j .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM