<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WPStorm &#187; Log</title>
	<atom:link href="http://wpstorm.net/tag/log/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpstorm.net</link>
	<description>Coding, Wordpress and Plugin Development</description>
	<lastBuildDate>Wed, 28 Mar 2012 22:52:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Amazon CloudFront Edges in AWStats</title>
		<link>http://wpstorm.net/2011/01/amazon-cloudfront-edges-awstats/</link>
		<comments>http://wpstorm.net/2011/01/amazon-cloudfront-edges-awstats/#comments</comments>
		<pubDate>Fri, 07 Jan 2011 02:02:00 +0000</pubDate>
		<dc:creator>Johan Steen</dc:creator>
				<category><![CDATA[Cloud Services]]></category>
		<category><![CDATA[Amazon]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[AWStats]]></category>
		<category><![CDATA[CloudFront]]></category>
		<category><![CDATA[Log]]></category>

		<guid isPermaLink="false">http://wpstorm.net/?p=363</guid>
		<description><![CDATA[Here&#8217;s a quick breakdown of how to get the usage of your different Amazon CloudFront Edge locations within AWStats. I confess that I get some crazy pleasure from collecting statistics, still though, bandwidth usage is of interest in this case, as well as hits and that it can be interesting to see which regions most ...]]></description>
			<content:encoded><![CDATA[<div id="attachment_364" class="wp-caption alignright" style="width: 310px"><a href="http://wpstorm.net/files/2011/01/cloudfront-awstats-cluster.jpg"><img src="http://wpstorm.net/files/2011/01/cloudfront-awstats-cluster-300x144.jpg" alt="" title="CloudFront Edges in AWStats" width="300" height="144" class="size-medium wp-image-364" /></a><p class="wp-caption-text">Click to enlarge</p></div>
<p>Here&#8217;s a quick breakdown of how to get the usage of your different Amazon CloudFront Edge locations within AWStats. I confess that I get some crazy pleasure from collecting statistics, still though, bandwidth usage is of interest in this case, as well as hits and that it can be interesting to see which regions most of the visitors come from.</p>
<p>I use the cluster functionality in AWStats to display the CloudFront Edges, as can be seen in the screenshot to the right.</p>
<p>I&#8217;m running AWStats on an Ubuntu server and this guide assumes that you are already collecting your CloudFront logs to a server and processes them with AWStats. If not, check out my other article dealing with that.</p>
<p>Let&#8217;s work with our hypothetical CloudFront distribution named cdn.example.com.</p>
<p>In Ubuntu AWStats stores the configurations files in /etc/awstats/ so I will assume there is a file located there named<br />
<code>/etc/awstats/awstats.cdn.example.com.conf</code><br />
which processes the CloudFront log already. </p>
<p>If you have configured the above .conf file properly for CloudFront, %cluster is collected in the LogFormat which contains all information needed to be able to display the edges. So now we only need to tell AWStats to start using that information.</p>
<p>First in the awstats.cdn.example.com.conf, enable cluster statistics by finding ShowClusterStats=0 and change it to:<br />
<code>ShowClusterStats=PHB</code><br />
And then continue down to the plugin section and uncomment<br />
<code>LoadPlugin="clusterinfo"</code></p>
<p>Now we only need to tell AWStats the name of the edges, so they make sense when checking the statistics later on. In AWStats DirData directory, create a file named clusterinfo.[your awstats config name].txt</p>
<p>Which in our example would be<br />
<code>/var/lib/awstats/clusterinfo.cdn.example.com.txt</code></p>
<p>This file shall contain a tab separated list of cluster numbers and then a text to display for each cluster. At the time of writing this article this is the complete list to paste into that file for all available CloudFront Edges. If Amazon adds more edges in the future they will have to be added at that time.</p>
<pre class="brush: plain; title: ; notranslate">
DFW3    USA: Dallas/Fort Worth, TX
EWR2    USA: Newark, NJ
IAD2    USA: Ashburn, VA
JAX1    USA: Jacksonville, FL
JFK1    USA: New York, NY
LAX1    USA: Los Angeles, CA
MIA3    USA: Miami, FL
SEA4    USA: Seattle, WA
SFO4    USA: Palo Alto, CA
STL2    USA: St. Louis, MO
AMS1    Europe: Amsterdam
DUB2    Europe: Dublin
FRA2    Europe: Frankfurt
LHR3    Europe: London
HKG1    Asia: Hong Kong
NRT4    Asia: Tokyo
SIN2    Asia: Singapore
</pre>
<p>Okay, that&#8217;s it, the next time AWStats updates the statistics output you should start getting Edge usage outputted in the Cluster section, like in the screenshot above.</p>
]]></content:encoded>
			<wfw:commentRss>http://wpstorm.net/2011/01/amazon-cloudfront-edges-awstats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Download AWS S3 Logs with Python &amp; boto</title>
		<link>http://wpstorm.net/2010/11/aws-s3-logs-boto-python/</link>
		<comments>http://wpstorm.net/2010/11/aws-s3-logs-boto-python/#comments</comments>
		<pubDate>Mon, 29 Nov 2010 00:21:19 +0000</pubDate>
		<dc:creator>Johan Steen</dc:creator>
				<category><![CDATA[Cloud Services]]></category>
		<category><![CDATA[Amazon]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[boto]]></category>
		<category><![CDATA[Log]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://wpstorm.net/?p=362</guid>
		<description><![CDATA[I&#8217;ve started to move my static content for some of my web sites to Amazon Web Services using S3 and CloudFront for delivery. I&#8217;ve enabled logging for my CloudFront distributions as well as my public S3 buckets, and wanted to be able to automatically download the logs using cron to my server for processing with ...]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve started to move my static content for some of my web sites to Amazon Web Services using S3 and CloudFront for delivery. I&#8217;ve enabled logging for my CloudFront distributions as well as my public S3 buckets, and wanted to be able to automatically download the logs using cron to my server for processing with AWStats.</p>
<p>To make this happen I&#8217;ve written a script in <a href="http://aws.amazon.com/python/">Python</a> with the <a href="http://boto.cloudhackers.com/">boto module</a> that downloads all generated log files to a local folder and then deletes them from the Amazon S3 Bucket when done. The log files downloaded to the local folder can then be further processed with logresolvemerge and AWStats.</p>
<p>You need to have the boto module installed for this to work. Personally I&#8217;m working with Ubuntu 10.04, where boto can be easily installed by executing:</p>
<pre class="brush: bash; title: ; notranslate">
sudo apt-get install python-boto
</pre>
<p>The script takes some command line arguments that are listed in the doc header. All of these can have a default value set in the head of the get_logs class. If you set default values in the script, the command line arguments are useful if you need to override a default value on some occasions.</p>
<h3>get-aws-logs.py</h3>
<pre class="brush: python; title: ; notranslate">
#! /usr/bin/env python
&quot;&quot;&quot;Download and delete log files for AWS S3 / CloudFront

Usage: python get-aws-logs.py [options]

Options:
  -b ..., --bucket=...    AWS Bucket
  -p ..., --prefix=...    AWS Key Prefix
  -a ..., --access=...    AWS Access Key ID
  -s ..., --secret=...    AWS Secret Access Key
  -l ..., --local=...     Local Download Path
  -h, --help              Show this help
  -d                      Show debugging information while parsing

Examples:
  get-aws-logs.py -b eqxlogs
  get-aws-logs.py --bucket=eqxlogs
  get-aws-logs.py -p logs/cdn.example.com/
  get-aws-logs.py --prefix=logs/cdn.example.com/

This program requires the boto module for Python to be installed.
&quot;&quot;&quot;

__author__ = &quot;Johan Steen (http://www.artstorm.net/)&quot;
__version__ = &quot;0.5.0&quot;
__date__ = &quot;28 Nov 2010&quot;

import boto
import getopt
import sys, os

_debug = 0

class get_logs:
	&quot;&quot;&quot;Download log files from the specified bucket and path and then delete them from the bucket.
	Uses: http://boto.s3.amazonaws.com/index.html
	&quot;&quot;&quot;
	# Set default values
	AWS_BUCKET_NAME = '{bucket}'
	AWS_KEY_PREFIX = '{prefix}'
	AWS_ACCESS_KEY_ID = '{access key}'
	AWS_SECRET_ACCESS_KEY = '{secret key}'
	LOCAL_PATH = '{local path}'
	# Don't change below here
	s3_conn = None
	bucket_list = None

	def __init__(self):
		s3_conn = None
		bucket_list = None

	def start(self):
		&quot;&quot;&quot;Connect, get file list, copy and delete the logs&quot;&quot;&quot;
		self.s3Connect()
		self.getList()
		self.copyFiles()

	def s3Connect(self):
		&quot;&quot;&quot;Creates a S3 Connection Object&quot;&quot;&quot;
		self.s3_conn = boto.connect_s3(self.AWS_ACCESS_KEY_ID, self.AWS_SECRET_ACCESS_KEY)

	def getList(self):
		&quot;&quot;&quot;Connects to the bucket and then gets a list of all keys available with the chosen prefix&quot;&quot;&quot;
		bucket = self.s3_conn.get_bucket(self.AWS_BUCKET_NAME)
		self.bucket_list = bucket.list(self.AWS_KEY_PREFIX)

	def copyFiles(self):
		&quot;&quot;&quot;Creates a local folder if not already exists and then download all keys and deletes them from the bucket&quot;&quot;&quot;
		# Using makedirs as it's recursive
		if not os.path.exists(self.LOCAL_PATH):
			os.makedirs(self.LOCAL_PATH)
		for key_list in self.bucket_list:
			key = str(key_list.key)
			# Get the log filename (L[-1] can be used to access the last item in a list).
			filename = key.split('/')[-1]
			# check if file exists locally, if not: download it
			if not os.path.exists(self.LOCAL_PATH+filename):
				key_list.get_contents_to_filename(self.LOCAL_PATH+filename)
				if _debug:
					print &quot;Downloaded from bucket: &quot;+filename
			# check so file is downloaded, if so: delete from bucket
			if os.path.exists(self.LOCAL_PATH+filename):
				key_list.delete()
				if _debug:
					print &quot;Deleted from bucket:    &quot;+filename

def usage():
	print __doc__

def main(argv):
	try:
		opts, args = getopt.getopt(argv, &quot;hb:p:l:a:s:d&quot;, [&quot;help&quot;, &quot;bucket=&quot;, &quot;prefix=&quot;, &quot;local=&quot;, &quot;access=&quot;, &quot;secret=&quot;])
	except getopt.GetoptError:
		usage()
		sys.exit(2)
	logs = get_logs()
	for opt, arg in opts:
		if opt in (&quot;-h&quot;, &quot;--help&quot;):
			usage()
			sys.exit()
		elif opt == '-d':
			global _debug
			_debug = 1
		elif opt in (&quot;-b&quot;, &quot;--bucket&quot;):
			logs.AWS_BUCKET_NAME = arg
		elif opt in (&quot;-p&quot;, &quot;--prefix&quot;):
			logs.AWS_KEY_PREFIX = arg
		elif opt in (&quot;-a&quot;, &quot;--access&quot;):
			logs.AWS_ACCESS_KEY_ID = arg
		elif opt in (&quot;-s&quot;, &quot;--secret&quot;):
			logs.AWS_SECRET_ACCESS_KEY = arg
		elif opt in (&quot;-l&quot;, &quot;--local&quot;):
			logs.LOCAL_PATH = arg
	logs.start()

if __name__ == &quot;__main__&quot;:
	main(sys.argv[1:])
</pre>
<p>Have in mind that I&#8217;m pretty new to Linux and to Python, so I bet things can be solved better, easier or in a more beautiful way than what I&#8217;ve done, as well as making it more fail safe.</p>
<p>Feel free to suggest improvements that can be made to the code.</p>
]]></content:encoded>
			<wfw:commentRss>http://wpstorm.net/2010/11/aws-s3-logs-boto-python/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Email log messages library in CodeIgniter</title>
		<link>http://wpstorm.net/2009/05/email-log-messages-library-codeigniter/</link>
		<comments>http://wpstorm.net/2009/05/email-log-messages-library-codeigniter/#comments</comments>
		<pubDate>Sun, 31 May 2009 15:53:08 +0000</pubDate>
		<dc:creator>Johan Steen</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[Library]]></category>
		<category><![CDATA[Log]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://wpstorm.net/?p=231</guid>
		<description><![CDATA[When working with CodeIgniter, I&#8217;ve found the log message functionality built into the framework very helpful. The other day I noticed in my log of one of my CodeIgniter based sites that I&#8217;ve had some 404 errors going on for some time. As I don&#8217;t have the time to check my logs daily, I hadn&#8217;t ...]]></description>
			<content:encoded><![CDATA[<p>When working with CodeIgniter, I&#8217;ve found the log message functionality built into the framework very helpful. The other day I noticed in my log of one of my CodeIgniter based sites that I&#8217;ve had some 404 errors going on for some time. As I don&#8217;t have the time to check my logs daily, I hadn&#8217;t noticed this problem until now.</p>
<p>This led me to think that it would be real handy to get the log messages sent out by email as well, so you don&#8217;t risk to have a problem going on at the site unnoticed for days or even weeks.</p>
<p>So I wrote an extension to the native Log class in CodeIgniter which adds this functionality. Below is the code for MY_Log.php which extends the CI_Log class. MY_Log calls the native Log functions so the log file still gets generated, and if a log message was executed it also gets sent out by email afterward.</p>
<p>Change the email address in the code to the one you want to receive the log messages to, and then save the file in your application/libraries/ folder as MY_Log.php. This assumes that your Class Extension Prefix is set to MY_ in your config file.</p>
<p>I hope some of you find this class extension useful, and feel free to improve upon it. Cheers!</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/**
 * MY_Log Class
 *
 * This library extends the native Log library.
 * It adds the function to have the log messages being emailed when they have been outputted to the log file.
 *
 * @package		CodeIgniter
 * @subpackage		Libraries
 * @category		Logging
 * @author		Johan Steen
 * @link		http://wpstorm.net/
 */
class MY_Log extends CI_Log {
	/**
	 * Constructor
	 *
	 * @access	public
	 */
	function MY_Log()
	{
		parent::CI_Log();
	}

	/**
	 * Write Log File
	 *
	 * Calls the native write_log() method and then sends an email if a log message was generated.
	 *
	 * @access	public
	 * @param	string	the error level
	 * @param	string	the error message
	 * @param	bool	whether the error is a native PHP error
	 * @return	bool
	 */
	function write_log($level = 'error', $msg, $php_error = FALSE)
	{
		$result = parent::write_log($level, $msg, $php_error);

		if ($result == TRUE &amp;&amp; strtoupper($level) == 'ERROR') {
			$message = &quot;An error occurred: \n\n&quot;;
			$message .= $level.' - '.date($this-&gt;_date_fmt). ' --&gt; '.$msg.&quot;\n&quot;;

			$to = 'someone@example.com';
			$subject = 'An error has occured';
			$headers = 'From: Example Name &lt;no-reply@example.com&gt;' . &quot;\r\n&quot;;
			$headers .= 'Content-type: text/plain; charset=utf-8\r\n';

			mail($to, $subject, $message, $headers);
		}
		return $result;
	}
}
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://wpstorm.net/2009/05/email-log-messages-library-codeigniter/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

