Skip to main content

Posts

Showing posts from 2015

How to customize log message using application data in log4Perl using MDC

In log messages it is often need to pass application data which is common to a set of log messages. One example is to log a requestID of an API call which uniquely identifies all log messages belongs to processing a particular API call. One approach is to pass the requestID in all log messages by appending the log message with requestID. Another approach is to use log4Perl::MDC (Mapped Diagnostic Context). Using MDC we can store Thread Specific data and which can be accessed by logger. The thread specific data of a parent thread is accessible to its child thread as well. Below program explains this. use Log::Log4perl; Log::Log4perl::init("log4perl.conf"); method(); sub method { Log::Log4perl::MDC->put("requestId","req00008"); my $logger = Log::Log4perl->get_logger("");   $logger->info("Received a request"); $logger->debug("Received a request"); } Here we have set a Th

How to create a custom log level using log4Perl

This blog explains how to create a auditlog with a custom log level 'AUDIT'. log4perl.rootLogger=TRACE, auditlog   log4perl.filter. AUDITFILTER = Log::Log4perl::Filter::LevelMatch log4perl.filter. AUDITFILTER .LevelToMatch = AUDIT log4perl.filter. AUDITFILTER .AcceptOnMatch = true   log4perl.appender.auditlog=Log::Log4perl::Appender::File log4perl.appender.auditlog.filename=c:/perl/log-dir/audit.log log4perl.appender.auditlog.mode=append log4perl.appender.auditlog.Filter = AUDITFILTER log4perl.appender.auditlog.layout=Log::Log4perl::Layout::PatternLayout log4perl.appender.auditlog.layout.ConversionPattern=%d{ISO8601}|%C|%m%n We have created a custom filter AUDITFILTER  which matches the level AUDIT in the appender. Now we need to create a custom level which need to be done in code as below. use Log::Log4perl; Log::Log4perl::Logger::create_custom_level("AUDIT", "DEBUG"); Log::Log4perl::init("log4perl.con

How to redirect different levels to different log files using log4Perl

It is sometimes required in a project to redirect log messages to different files based on their severity. This can be easily done in log4Perl using the below mentioned configuration file entries. log4perl.rootLogger=TRACE, errorlog, consolelog , debuglog   log4perl.appender.errorlog=Log::Log4perl::Appender::File log4perl.appender.errorlog.filename=c:/perl/log-dir/error.log log4perl.appender.errorlog.mode=append log4perl.appender.errorlog.Threshold = INFO log4perl.appender.errorlog.layout=Log::Log4perl::Layout::PatternLayout log4perl.appender.errorlog.layout.ConversionPattern=%d{ISO8601}|%C|%m%n   log4perl.appender.consolelog=Log::Log4perl::Appender::Screen log4perl.appender.Screen.stderr = 0 log4perl.appender.consolelog.mode=append log4perl.appender.consolelog.layout=Log::Log4perl::Layout::PatternLayout log4perl.appender.consolelog.layout.ConversionPattern=%d{ISO8601}|%C|%m%n   log4perl.appender.debuglog=Log::Log4perl::Appender::File log4perl.

Log::Log4perl - Introduction to logging in Perl

This article will take you to logging in Perl using Log4perl in windows. First check whether perl is installed on your machine. You can do this by running the following command on command prompt. C:\perl>perl -v This is perl 5, version 12, subversion 3 (v5.12.3) built for MSWin32-x86-multi-t hread Copyright 1987-2010, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl".  If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page. C:\perl> If perl is not installed then you can install perl on windows using the below link: http://learn.perl.org/installing/windows.html Next we need to install log4Perl. Open a command prompt and run any one of the below command. C:\perl>ppm in

Useful K shell commands and examples

Description Command Example How to get date in YYYYMMDDhhmmss format                          date +%Y%m%d%H%M%S                                 date +%Y%m%d%H%M%S 20150701164849        How to get hostname uname -n How to unzip and untar a file gunzip -c filename | tar -xvf - How to check if a file is non zero size if [ -s file ] How to check if a variable is empty  if [  -z file] How to check if a directory is present if [  -d file] How to check if a file is present if [  -f file] How to extract file name from path  echo filename | sed -e's/.*\///' # echo "/opt/app/tmp/pom.xml" | sed -e's/.*\///' pom.xml How to zip a file  cat $file |  gzip -c > $FILENAME How to retrieve return status from a shell $CTI/common/shells/SendToETL.sh TOPO $FILENAME RC=$? echo "Return status = $RC" How to run a command on a remote server ssh -l user hostname '. ./.profile;echo $JAVA_HOME

How to write MapReduce program using eclipse

Make sure that your Hadoop installtion is working fine on your machine. For this tutorial I have installed Hadoop on my MacBook Pro using the below guidelines. Hadoop Installation guidelines Install Eclipse IDE on the machine. I have installed Eclipse Version: Luna Service Release 1 (4.4.1). Create a new project using File->New->Project Set java Build Path by using Project->Properties->Java Build Path->Libraries->Add External JARs Assuming Hadoop is installed on /Users/jineshmathew/hadoop-2.5.1, select all JARs in below folders /Users/jineshmathew/hadoop-2.5/share/hadoop/common/lib/ /Users/jineshmathew/hadoop-2.5/share/hadoop/yarn/lib/ /Users/jineshmathew/hadoop-2.5/share/hadoop/mapreduce/lib /Users/jineshmathew/hadoop-2.5/share/hadoop/hdfs/lib/ Now we need to create input data, I have created a file emp.dat with the below employee data. emp.dat ------------------------------- Tom,Developer,IL,80000 Jose,Architect,OH,100000 Bill,Director,OH,1300

How to extract rows from Excel based on regular expressions

How to extract rows based on regular expressions There are two ways to extract or filter records from excel using regular expressions. 1.        Using Home->Sort & Filter ->Filter 2.        Using Data->filter->advanced We have the below excel document and we need to extract the rows based on name which contains ‘John’. Approach 1 Step 1: Click Home->Sort & Filter ->Filter Click on ‘Last Name’ drop down and click ‘Text Filters’ and then click ‘Contains’ Write the word that you want to filter with, in this example it is ‘John’. The result is as shown below. If you want to have an AND condition with another field that can be done by using repeating above for that field. Below example filter excel based on Country column as well. The result is as shown below. Approach 2 Step1: Create an entry as shown below at column I (or any empty column) with the column name which you are going to apply regular

DNS PROBE FINISHED NO INTERNET

Did you get an error saying "DNS PROBE FINISHED NO INTERNET" on the web browser and not able to connect to any websites. If so please try below steps to solve the issue. NOTE: This tutorial is specific to windows 7. Please expect some changes for other windows versions. STEP 1: Open command Prompt, Type 'cmd' and run as administrator as shown below. STEP 2: Run the following commands in order ipconfig /all  ipconfig /flushdns  ipconfig /renew  netsh int ip set dnsservers "wireless network connection" source=dhcp netsh winsock reset  NOTE: If you are facing problems with LAN connection ( Wired internet connection) then use below command instead of   netsh int ip set dnsservers "wireless network connection" source=dhcp netsh int ip set dnsservers "Local area connection" source=dhcp Please let me know if this works or if any issues.