Posts

Showing posts with the label Logging

CloudFlare And Logging Visitor IP Addresses Via In PHP

Answer : Extra server variables that are available to cloud flare are: $_SERVER["HTTP_CF_CONNECTING_IP"] real visitor ip address, this is what you want $_SERVER["HTTP_CF_IPCOUNTRY"] country of visitor $_SERVER["HTTP_CF_RAY"] $_SERVER["HTTP_CF_VISITOR"] this can help you know if its http or https you can use it like this: if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) { $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"]; } If you do this, and the validity of the visiting IP address is important, you might need to verify that the $_SERVER["REMOTE_ADDR"] contains an actual valid cloudflare IP address, because anyone can fake the header if he was able to connect directly to the server IP. Update : CloudFlare has released a module mod_cloudflare for apache, the module will log and display the actual visitor IP Addresses rather than those accessed by cloudflare! https://www.cloudfla...

C# Serilog: How To Log With String Interpolation And Keep Argument Names In Message Templates?

Answer : Add this file to your project. It has ILogger extension methods VerboseInterpolated() , DebugInterpolated() and so on. There are also unit tests here. Usage with format string string name = "John"; // add 'Interpolated' to method name: InformationInterpolated() instead of Information() // add name of the property after the expression. Name is passed to the logger logger.InformationInterpolated($"length of name '{name:name}' is {name.Length:Length}"); But be careful : it's all too easy to use the wrong method. If you accidentally use the Serilog's method, for example logger.Debug($"length = {length:propertyNameForLogger}") , it will log length = propertyNameForLogger , so no argument value will be logged. This is due to propertyNameForLogger is format for your value. Usage with anonymous types string name = "John"; // add 'Interpolated' to method name: InformationInterpolated() instead of...

Can't Turn Off HtmlUnit Logging Messages

Answer : I too had issues with this.. The answer depends on what logging system commons-logging is using under the hood. (since common-logging is just a wrapper). See the following http://commons.apache.org/proper/commons-logging/guide.html#Configuring_The_Underlying_Logging_System The attribute you mention above (org.apache.commons.logging.simplelog.defaultlog) should only be valid if the simple logger is been used. If you are running on JDK 1.4 or higher however it should default to using the JDK logging. In which case it defaults to using the lib/logging.properties from the JRE install location. In my case I had Log4j in the classpath, so it defaulted to that. To take away the randomness of all this you can explicitly set the Logger yourself. Create a commons-logging.properties file in the classpath and pass in the logger to use e.g. # JDK Logging #org.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger # Log4j logging (also required log4j.jar to be in ...