Rails 3.2 Custom Logging
April 4th, 2012
In old rails apps I opened up various loggers, the venerable Ruby Logger, or the BufferedLogger of ActiveSupport, but with Rails 3.2 we can stuff all that code in the blender.
One of the reasons I had a customized logger was to add the pid (process ID) to the log.
Here have some pie!
WARNING THIS IS SLOW PIE! (See update below)
config.log_tags = [:subdomain, :uuid, :remote_ip, Proc.new { "PID-%.5d" % $$ }]
Now throw away all your old meta loggers!
more here
The Next Day Update (More Faster)!
There is a more complex way to do this. It could be added as a patch to rails to standardize the :pid logging, though.
Performance
Switching from rails 3.0.12 to rails 3.2.3, and upgrading from my monkey patched BufferedLogger, to the Proc.new version above) increased my login page load time from 5ms to 9ms (warm cache, config.cache_classes = true).
Setting up the PidMiddleware to set the formatted pid when the stack loads took me back down to 6ms, nearly back to rails 3.0 performance. There are probably some other things I have yet to configure for more gains, but this was a significant boost.
Create lib/action_dispatch_request.rb:
# Monkey Patch ActionDispatch::Request to add #pid method
module ActionDispatch
class Request < Rack::Request
# Process ID (pid), set by the PidMiddleware.
def pid
@pid ||= (@env["action_dispatch.pid"]).to_s
end
end
end
Create app/middlewares/my_app/pid_middleware.rb
require 'rack/utils'
module MyApp
class PidMiddleware
def initialize(app, formatted_string = "PID-%.5d")
@app = app
@formatted_pid = formatted_string % $$
end
#Adds a formatted pid to the env
def call(env)
env["action_dispatch.pid"] = @formatted_pid
@app.call(env)
end
end
end
Add to config/application.rb
# Haven't yet figured out how to avoid doing implicit requires in the application.rb
require Rails.root + 'app/middleware/my_app/pid_middleware'
# This autoload_paths doesn't seem to be doing what I want it to do (perhaps I am remiss in my wants?)
config.autoload_paths += %W( #{config.root}/app/middleware/my_app )
config.middleware.insert_before Rails::Rack::Logger, MyApp::PidMiddleware, "PID-%.5d"
config.log_tags = [:subdomain, :uuid, :remote_ip, :pid]
Peter Boling Resumé
March 8th, 2012
I am an experienced, full stack, Ruby on Rails Web Application programmer. I have been using rails as my main development platform since the summer of 2005. I am an experienced System Administrator on Linux, Mac, and Windows computers. I speak three languages, English, Spanish, and Portuguese, fluently.
I have built, deployed and managed several top 5000 websites, and led several PHP to Rails conversions of major websites. I have worked on websites in the finance, social networking, government, and commerce.
-My reusmé - outdated, new version under construction, as I now live and work in the NYC area.
See also my portfolio.
Portfolio
March 6th, 2012
I work on Neighborino.com, which is a neighborhood socialization, HOA management, and communication tool. My relationship with Neighborino is a profit sharing model, so the cost to them is minimal as they are in the launch phase. Check out the demo site to see a functioning HOA website.
As a software engineer for the State of Indiana Legislative Services Agency I worked on:As a partner at Sagebit.com I was a major part of developing the following sites:
- A Small World
- Timeperks
- Radio Bookmark
- Carta Buzz
- Monkey Stub
- Sagebit.com
- Yeti Mail (Currently Offline)
- Team Clip (Currently Offline)
I have worked on several other sites that I am unable to name publicly.
I am the author of many gems and plugins, the most popular of which are: I am the maintainer of the following projects: I am a committer on the following projects: I contribute to the following projects:Determinism versus Free Will in Mormonism
May 25th, 2011
At times I have spoken negatively of the church, however, I do have respect for some aspects of the church, and many of its past and present leaders. This note has nothing negative, it is exclusively about what I find inspirational in Mormonism. There are no links to any other sites. I have gathered from some of the best minds in Mormonism, quotes which I feel show an acute understanding of my current philosophy about life. These ideas stand the test of time, and even the switch to atheism. This is what I am grateful for in Mormonism, and I thought people would like to hear me say some positive things. I hope you find them to be so. In a sense you could say that my current belief is an amalgamation of the following quotes from Brigham Young, John Taylor, Parley P. Pratt, James E. Talmage, Stephen L. Richards, B. H. Roberts, John A. Widtsoe, Ezra Taft Benson, and Hugh B. Brown – all prophets, apostles, or general authorities of the church. One quote is even “scriptural” in nature coming straight from general conference. I am “quote mining” a little, but the quotes are generally complete thoughts in and of themselves, as you will see. There are far more quoted words in this note, than my own words. You may not get the same meaning out of these quotes as I do, and that is to be expected. We are all different. I am certainly interpreting them with a bias toward my current understanding of reality.
My Current Philosophy
Determinism is the concept that everything has a cause. This idea generally abolishes the idea of free will. Some determinists argue that the absence of free will negates the idea of personal responsibility. I do not agree with this, and find that responsibility is as valid as it would be if we did have true agency. Perhaps an example would be useful. If you have a computer which gets a virus, and the virus makes it so you can’t get work done on the computer, you would say the virus is the “cause” of the problem (determinism) but also that it is “responsible” for the problem. Though it didn’t choose to cause problems, as it only follows the routines that are programmed into it, and has no ability to do otherwise, the problems occurred regardless of choice. In this sense “cause” and “responsible” have the same meaning. The virus needs to be “punished” for what it did, and so you attempt to remove it from the computer. I do believe in personal responsibility.
I will make the case that determinism has a place in Mormon theology. What we call “free will” or “moral agency”, when properly understood is but an illusion of our mortal consciousness, which is but a complex chemical reaction occurring in our brain. I will first get a bunch of ideas down and then refine my thoughts later (as in a later date – this is somewhat unfinished – but I thought it worthwhile to share).
What do I believe about miracles?
The same thing Brigham Young did. There are no miracles, there are causes and there are results, or effects.
“Yet I will say with regard to miracles, there is no such thing save to the ignorant – that is, there never was a result wrought out by God or by any of His creatures without there being a cause for it. There may be results, the causes of which we do not see or understand, and what we call miracles are no more than this – they are the results or effects of causes hidden from our understandings.” [Brigham Young, Journal of Discourses, vol. 13, pg. 140 – p.141, 11 Jul 1869].
Miracles have scientific, and deterministic, causes that are just waiting to be discovered, rendering them all but miraculous to later generations who understand the causes. ‘Miracle’ is a fancy way of saying “I don’t know how”, and once when we understand how the universe works, “I don’t know how, yet, but I could figure it out.”
What do I believe about the mutability of the laws of nature?
Same as John Taylor.
“Science reveals the beauty and harmony of the world material; it unveils to us ten thousand mysteries in the kingdom of nature, and shows that all forms of life through fire and analogous decay are returned again to its bosom. It unfolds to us the mysteries of cloud and rains, dew and frost, growth and decay, and reveals the operation of those silent irresistible forces which give vitality to the world. It reveals to us the more wonderful operations of distant orbs and their relations to the forces of nature. It also reveals another grand principle, that the laws of nature are immutable and unchangeable as are all the works of God.” [John Taylor, Journal of Discourses, vol. 13, pg. 224, 6 May 1870].
There are no optional outcomes. One thing leads to another in a programmatic fashion with no potential for alternative paths. Evaporation directly results in rain, and it really is that simple.
Did the universe, and life in it, evolve from simpler patterns in ages past?
I agree with Brigham Young on this one:
“The origin of life whether human or inferior, must be lodged in some character whom I have not seen! Follow it back, no matter whether it be for six thousand years, six millions, six million millions, or billions of years, the figures and numbers are immaterial, I must have come from some source, my natural philosophy teaches me this. But, leaving the natural philosophy of the child free from false tradition, let us inquire. What does the philosophy of the Christian sects, or many of them, not all, teach? “God made the world in six days, out of nothing!” This is very wrong; no child should be taught any such dogma. God never did make a world out of nothing; He never will, He never can!” [Brigham Young, Journal of Discourses, vol. 13, pg. 248, 25 Sep 1870].
“He never can!” indicates that there are some things God cannot do. God cannot do anything other than follow the laws of the universe which are “immutable and unchangeable” (see John Talyor quote just above).
Does God have free will?
If God is bound by the natural laws in place, and cannot choose to not follow them, can he choose anything at all?
For the answer I turn again to Brigham Young:
“It is hard to get the people to believe that God is a scientific character, that He lives by science or strict law…” [Brigham Young, Journal of Discourses, vol. 13, pg. 302, 13 Nov 1870].
Can anything ever occur that is contrary to the laws of nature?
No, it cannot. For that would be miraculous, and miracles, as such, do not exist. So I agree with Parley P. Pratt here:
“Among the popular errors of modern times, an opinion prevails that miracles are events which transpire contrary to the laws of nature, that they are effects without a cause. If such is the fact, then, there never has been a miracle, and there never will be one. The laws of nature are the laws of truth. Truth is unchangeable, and independent in its own sphere. A law of nature never has been broken. And it is an absolute impossibility that such law ever should be broken.” [Parley P. Pratt, Key to the Science of Theology, 1891, pg. 102].
The miracles of 10, 50, or 150 years ago, may not be miracles today, due to increased understanding of how things work. A child who got sick with a 24 hour bug in 1830 may have gotten a blessing and been ‘healed’. It may have been called a miracle. But did anything happen other than what must have happened given the chemicals in his body and the environment of his surroundings? No. It cannot be otherwise, because God follows the unchangeable laws of the universe meaning there is only one potential outcome. If it is not so, then it would be impossible for him to know the end from the beginning.
“Miracles are commonly regarded as occurrences in opposition to the laws of nature. Such a conception is plainly erroneous, for the laws of nature are inviolable. However, as human understanding of these laws is at best but imperfect, events strictly in accordance with natural law may appear contrary thereto. The entire constitution of nature is founded on system and order.” [James E. Talmage, The Articles of Faith, Deseret Book, SLC, 1966, originally published 1899, pg. 220.]
If there is only one way things can happen in the future and only one way they happened in the past where does this leave us? First we must understand that looking to science for understanding of the genesis of humanity is appropriate, and worthwhile. Understanding how we came to be, physically, is important to understanding what we really are.
How do I feel about a literal interpretation of scripture?
I agree with Stephen L. Richards, that a literal interpretation is unfounded:
“The time of creation has ever been a subject of much comment and dispute. Yet I challenge anybody to produce from the Bible itself any finite limitation whatsoever of the periods of creation. By strained inferential references and interpretations men have sought to set the time in days or periods of a thousand years, but I feel sure that no justification of such limitations is warranted by the scriptures themselves. If the evolutionary hypothesis of the creation of life and matter in the universe is ultimately found to be correct, and I shall neither be disappointed nor displeased if it shall turn out so to be, in my humble opinion the Biblical account is sufficiently comprehensive to include the whole of the process.” [Stephen L. Richards, “An Open Letter to College Students,” Improvement Era, vol. 36 (June 1933), pg. 451-453, 484-485].
Why is it important to understand the evidence for evolution, and the history of life on earth?
There are many who are currently trying to promote ignorance of the subject, and many, even Mormons, who discount evolution, when it is proven, verifiable fact, and has been so for at least a hundred years. On this topic I have utmost respect for B.H. Roberts, one of the greatest (and smartest) general authority/scientists to ever live:
“On the other hand, to limit and insist upon the whole of life and death to this side of Adam’s advent to the earth, some six or eight thousand years ago, as proposed by some, is to fly in the face of the facts so indisputably brought to light by the researcher of science in modern times, and this as set forth by men of the highest type in the intellectual and moral world; not inferior men, or men of sensual and devilish temperament, but men who must be accounted as among the noblest and most self-sacrificing of the sons of men – of the type whence must come the noblest sons of God, since “the glory of God is intelligence” (D&C 93:36); and that too the glory of man. These researchers after truth are of that class. To pay attention to and give reasonable credence to their research and findings is to link the church of God with the highest increase of human thought and effort. On that side lies development, on the other lies contraction. It is on the former side that research work is going on and will continue to go on, future investigation and discoveries will continue on that side, nothing will retard them, and nothing will develop on the other side. One leads to narrow sectarianism, the other keeps the open spirit of a world movement with which our New Dispensation began. As between them which is to be our choice?” [B. H. Roberts, The Truth, the Way, the Life, originally written 1931, published by Smith Research Associates, Salt Lake City, UT, 1994, pg. 364].
There have been many at all levels of the church who were strong advocates of evolution. I especially appreciate the emphasis John A. Widtsoe puts on valuing truth above all else:
“Every person must decide for himself, on the basis of the evidence produced, which of these three opinions as to the age of the earth, before Adam, seems most reasonable to him, whether (1) six days, or (2) six thousand years, or (3) many millions of years. Clearly it does not matter to one’s daily welfare or ultimate salvation which view he adopts, except that every Latter-day saint must seek and cherish truth above all else.” [John A. Widtsoe, Evidences and Reconciliations, Bookcraft, 1960, pg. 149].
“The progress of science may yet shed much light on the origin of the earth.” [John A. Widtsoe, Evidences and Reconciliations, Bookcraft, Salt Lake City, 1960, pg. 150].
How do I feel about the convergence of religion and science?
I cannot argue with Ezra Taft Benson, speaking in General Conference, for he spoke the truth. True religion and true science can never conflict. Truth is always true.
“Religion and science have sometimes been in apparent conflict. Yet the conflict should only be apparent, not real for science should seek truth, and true religion is truth. There can never be conflict between revealed religion and scientific fact. That they have often occupied different fields of truth is a mere detail. The gospel accepts and embraces all truth; science is slowly expanding her arms and reaching into the invisible domain in search of truth. The two are meeting daily – science as a child, revealed religion as the mother. Truth is truth, whether labeled science or religion. There can be no conflict. Time is on the side of truth – for truth is eternal.” [Ezra Taft Benson, LDS Conference Report, Apr. 1966, pg. 129].
I know that religion has erred, and science has erred. Religion, in general is slow at making corrections when shown to be wrong. Science can also be slow to acommodate new evidence. There really is only one result of the search in either field, and that is truth. I have had to ecshew much of my religious belief, when I found things that I considered to be less in error. I have likewise eschewed some scientific beliefs once I learned about new evidence which proved my ideas wrong. In both cases I am trying to refine my views to be in line with reality.
How do I feel about scientific discovery?
I like what John Taylor has to say about it:
“True science is a discovery of the secret, immutable and eternal laws, by which the universe is governed; and when practically applied, sets in motion the mighty wheels of useful engines, with all the various machinery which genius has invented, or art contrived. It ameliorates the condition of man, by extending the means of intellectual, moral, social, and domestic happiness.” [John Taylor, Times and Seasons, vol. 4, pg. 46, 15 Dec 1842].
When we discover things through science and improve the human condition there is no magic involved.
How do I feel about academic research and exploring the unknown?
I agree with Hugh B Brown:
“We should all be interested in academic research. We must go out on the research front and continue to explore the vast unknown. We should be in the forefront of learning in all fields, for revelation does not come only through the prophet of God nor only directly from heaven in visions or dreams. Revelation may come in the laboratory, out of the test tube, out of the thinking mind and the inquiring soul, out of search and research and prayer and inspiration. We must be unafraid to contend for what we are thinking and to combat error with truth in this divided and imperiled world, and we must do it with the unfaltering faith that God is still in his heaven even though all is not well with the world.”
“We should be dauntless in our pursuit of truth and resist all demands for unthinking conformity. No one would have us become mere tape recorders of other people’s thoughts. We should be modest and teachable and seek to know the truth by study and faith. There have been times when progress was halted by thought control. Tolerance and truth demand that all be heard and that competing ideas be tested against each other so that the best, which might not always be our own, can prevail. Knowledge is the most complete and dependable when all points of view are heard. We are in a world of restlessness and skepticism, where old things are not only challenged but often disappear, but also a world of miraculous achievement, undreamed of accomplishment, and terrifying power. ...”
“While speak of independence and the right to think, to agree or disagree, to examine and question, I need to remind myself not to forget that fixed and unchanging laws govern all God’s creation, whether the vastness of the starry heavens or the minute revolving universe of the atom or human relationships. All is law. All is cause and effect, and God’s laws are universal. God has no favorites; no one is immune from either life’s temptations or the consequences of his or her deeds. God is not capricious.” [Hugh B. Brown, “A Final Testimony,” from Edwin B. Firmage, ed., The Memoirs of Hugh B. Brown: An Abundant Life, Signature Books, 1988].
Repeating part of the last quote because it is my final thought, and I am in complete agreement with it (given that I may disagree on the definition of God):
“While speak of independence and the right to think, to agree or disagree, to examine and question, I need to remind myself not to forget that fixed and unchanging laws govern all God’s creation, whether the vastness of the starry heavens or the minute revolving universe of the atom or human relationships. All is law. All is cause and effect, and God’s laws are universal.”
“All is cause and effect” is the essential definition of determinism, and it seems to also be an valid tenet of Mormonism. I hope this has helped people understand what kind of Mormon I am. Despite my atheism, I consider many of my views to be Mormon. They may not line up with your Mormon views, and there is nothing wrong with that. I was asked to resign from the church (in a very kind manner) for some of my views which are not in line with current church policy… but I think the ones outlined here are broadly within the scope of Mormonism.
git-svn fails to delete directories
April 26th, 2011
List all empty directories:
find . -wholename './.git' -prune -o -type d -empty -print
Find and delete all empty directories:
find . -wholename './.git' -prune -o -type d -empty -print -exec rm -rf \;
After deleting the directory it will complain that it cannot find the directory. I’m not sure why.
Execute those commands several times until no more empty directories are found. Nested empty directories have to be deleted in successive runs because they are not truly empty until their nested empties are deleted. :(
And fix the root of the problem:
--rmdir
Only used with the dcommit, set-tree and commit-diff commands.
Remove directories from the SVN tree if there are no files left behind. SVN can version empty directories, and they are not removed by default if there are no files left in them. git cannot version empty directories. Enabling this flag will make the commit to SVN act like git.
config key: svn.rmdir
Rails 2.3.8 & Mongrel 1.1.5 Bug
July 25th, 2010
The response body is: “You are being redirected”. The word “redirected” is a link to the page you wish it was going to. You never actually get redirected (at least not in FF or Safari).
I read about the problem here
One of the later comments had a gist that fixed it for me.
Copy this text
Paste into an initializer: mongrel_hack.rb
Commit, redeploy, done.
Then upgrade to Unicorn. :)
Rails Redo
March 8th, 2010
My environment for Ruby & Rails development began showing signs of wear and tear. I have been unable to get rvm to work for me at all. I dream about having the wonderful abilities it can provide, like independent sandboxes for rubies & gemsets, and configurations.
So when the latest gem upgrade (1.3.6) broke my older versions of rails (pre-2.3) things started to snowball uphill, and I decided to start over.
Read the rest of this entryRails, Money, Float, Decimal
November 17th, 2009
The problems of using floats to represent monetary values have been well discussed elsewhere. So it sufficeth me to say, “do not ever do it”. Now if you are confronted with this haunting bit of code (written by someone else, of course), and want to correct the elusive $35.000000000000000001 you are charging people then I have good news! It can be done, but the road is not paved. These are the four biggest bumps I’ve run into. They might apply to other styles of AR stores, but these tips are from my experiences with MySQL.
Read the rest of this entryUnpack your unruly gems!
November 13th, 2009
Unpacking Gems doesn’t always work in some projects for various annoying reasons.
So this is just my hammer for the nail.
Read the rest of this entryMy Cherub
November 4th, 2009
My little cherub of a daughter turned one year old just three weeks ago. She also has a congenital heart disease called tetralogy of fallot. Two days ago we were went down to Riley Children’s Hospital and had her heart tested. When we met with the doctor afterwards we learned the unsettling news that she would need another open heart surgery, and that it would need to be soon. She has been taking a beta blocker to calm her heart down, and we were hoping that it would slow the growth of the muscle, and lower the pressure at the pulmonary artery, because it was four times what is healthy. Instead it is now eight times what is healthy. That might explain why she turned blue-purlpe, for a few minutes, two weeks ago. It might also have been a factor in the seizure she appeared to have last week. So on Earl’s birthday she will be having her second open heart surgery. This has been a difficult trial for my wife and I. I know that God is in control, and I put my faith in him, and his will for us.
Contact
October 12th, 2009
My cell is the best way to get a hold of me.
- FaceBook: http://www.facebook.com/peter.boling
- GitHub: http://github.com/pboling/
- Twitter: http://twitter.com/galtzo
- cell: 765-760-2012
- email: peter.boling@peterboling.com
- AIM: djpeteplzdance
- jabber: peter.boling@gmail.com
- skype: peter.boling
- lang: English, Spanish, Portuguese