From 0523b4265bb19bfff15c6a435dd52ffd6a5683f8 Mon Sep 17 00:00:00 2001
From: randx <dmitriy.zaporozhets@gmail.com>
Date: Tue, 11 Sep 2012 23:24:53 +0300
Subject: [PATCH] Application logger

---
 app/assets/javascripts/admin.js.coffee   |  4 +++
 app/assets/javascripts/application.js    |  2 +-
 app/assets/stylesheets/sections/nav.scss |  1 -
 app/observers/project_observer.rb        | 12 ++++++++
 app/observers/user_observer.rb           | 12 ++++++++
 app/views/admin/logs/show.html.haml      | 35 ++++++++++++++++++------
 lib/gitlab/app_logger.rb                 | 11 ++++++++
 lib/gitlab/backend/gitolite_config.rb    | 10 +++++--
 lib/gitlab/git_logger.rb                 | 11 ++++++++
 lib/gitlab/logger.rb                     |  8 ++----
 10 files changed, 86 insertions(+), 20 deletions(-)
 create mode 100644 lib/gitlab/app_logger.rb
 create mode 100644 lib/gitlab/git_logger.rb

diff --git a/app/assets/javascripts/admin.js.coffee b/app/assets/javascripts/admin.js.coffee
index 269a7a767ed..76454c29269 100644
--- a/app/assets/javascripts/admin.js.coffee
+++ b/app/assets/javascripts/admin.js.coffee
@@ -6,3 +6,7 @@ $ ->
       elems.val('').attr 'disabled', true
     else
       elems.removeAttr 'disabled'
+
+  $('.log-tabs a').click (e) ->
+    e.preventDefault()
+    $(this).tab('show')
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 4c487ec1d38..f9fdb0f7dc2 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -11,7 +11,7 @@
 //= require jquery.endless-scroll
 //= require jquery.highlight
 //= require jquery.waitforimages
-//= require bootstrap-modal
+//= require bootstrap
 //= require modernizr
 //= require chosen-jquery
 //= require raphael
diff --git a/app/assets/stylesheets/sections/nav.scss b/app/assets/stylesheets/sections/nav.scss
index 6f6a0e8e29f..2d9029183a6 100644
--- a/app/assets/stylesheets/sections/nav.scss
+++ b/app/assets/stylesheets/sections/nav.scss
@@ -55,7 +55,6 @@ ul.main_menu {
 
     &.current {
       background-color:#D5D5D5;
-      border-bottom: 1px solid #AAA;
       border-right: 1px solid #BBB;
       border-left: 1px solid #BBB;
       border-radius: 0 0 1px 1px;
diff --git a/app/observers/project_observer.rb b/app/observers/project_observer.rb
index 135959ab738..03a61709829 100644
--- a/app/observers/project_observer.rb
+++ b/app/observers/project_observer.rb
@@ -4,6 +4,18 @@ class ProjectObserver < ActiveRecord::Observer
   end
 
   def after_destroy(project)
+    log_info("Project \"#{project.name}\" was removed")
+
     project.destroy_repository
   end
+
+  def after_create project
+    log_info("#{project.owner.name} created a new project \"#{project.name}\"")
+  end
+
+  protected
+
+  def log_info message
+    Gitlab::AppLogger.info message
+  end
 end
diff --git a/app/observers/user_observer.rb b/app/observers/user_observer.rb
index d12bcc99c83..654621f7e1c 100644
--- a/app/observers/user_observer.rb
+++ b/app/observers/user_observer.rb
@@ -1,5 +1,17 @@
 class UserObserver < ActiveRecord::Observer
   def after_create(user)
+    log_info("User \"#{user.name}\" (#{user.email}) was created")
+
     Notify.new_user_email(user.id, user.password).deliver
   end
+
+  def after_destroy user
+    log_info("User \"#{user.name}\" (#{user.email})  was removed")
+  end
+
+  protected
+
+  def log_info message
+    Gitlab::AppLogger.info message
+  end
 end
diff --git a/app/views/admin/logs/show.html.haml b/app/views/admin/logs/show.html.haml
index 800d3bb288f..0efe6db7483 100644
--- a/app/views/admin/logs/show.html.haml
+++ b/app/views/admin/logs/show.html.haml
@@ -1,9 +1,26 @@
-.file_holder#README
-  .file_title
-    %i.icon-file
-    githost.log
-  .file_content.logs
-    %ol
-      - Gitlab::Logger.read_latest.each do |line|
-        %li
-          %p= line
+%ul.nav.nav-tabs.log-tabs
+  %li.active
+    = link_to "githost.log", "#githost", 'data-toggle' => 'tab'
+  %li
+    = link_to "application.log", "#application", 'data-toggle' => 'tab'
+.tab-content
+  .tab-pane.active#githost
+    .file_holder#README
+      .file_title
+        %i.icon-file
+        githost.log
+      .file_content.logs
+        %ol
+          - Gitlab::GitLogger.read_latest.each do |line|
+            %li
+              %p= line
+  .tab-pane#application
+    .file_holder#README
+      .file_title
+        %i.icon-file
+        application.log
+      .file_content.logs
+        %ol
+          - Gitlab::AppLogger.read_latest.each do |line|
+            %li
+              %p= line
diff --git a/lib/gitlab/app_logger.rb b/lib/gitlab/app_logger.rb
new file mode 100644
index 00000000000..8e4717b46e6
--- /dev/null
+++ b/lib/gitlab/app_logger.rb
@@ -0,0 +1,11 @@
+module Gitlab
+  class AppLogger < Gitlab::Logger
+    def self.file_name
+      'application.log'
+    end
+
+    def format_message(severity, timestamp, progname, msg)
+      "#{timestamp.to_s(:long)}: #{msg}\n"
+    end
+  end
+end
diff --git a/lib/gitlab/backend/gitolite_config.rb b/lib/gitlab/backend/gitolite_config.rb
index 0d636d2d789..f51e8efc370 100644
--- a/lib/gitlab/backend/gitolite_config.rb
+++ b/lib/gitlab/backend/gitolite_config.rb
@@ -58,18 +58,22 @@ module Gitlab
         end
       end
     rescue PullError => ex
-      Gitlab::Logger.error("Pull error ->  " + ex.message)
+      log("Pull error ->  " + ex.message)
       raise Gitolite::AccessDenied, ex.message
 
     rescue PushError => ex
-      Gitlab::Logger.error("Push error ->  " + " " + ex.message)
+      log("Push error ->  " + " " + ex.message)
       raise Gitolite::AccessDenied, ex.message
 
     rescue Exception => ex
-      Gitlab::Logger.error(ex.class.name + " " + ex.message)
+      log(ex.class.name + " " + ex.message)
       raise Gitolite::AccessDenied.new("gitolite timeout")
     end
 
+    def log message
+      Gitlab::GitLogger.error(message)
+    end
+
     def destroy_project(project)
       FileUtils.rm_rf(project.path_to_repo)
       conf.rm_repo(project.path)
diff --git a/lib/gitlab/git_logger.rb b/lib/gitlab/git_logger.rb
new file mode 100644
index 00000000000..fbfed205a0f
--- /dev/null
+++ b/lib/gitlab/git_logger.rb
@@ -0,0 +1,11 @@
+module Gitlab
+  class GitLogger < Gitlab::Logger
+    def self.file_name
+      'githost.log'
+    end
+
+    def format_message(severity, timestamp, progname, msg)
+      "#{timestamp.to_s(:long)} -> #{severity} -> #{msg}\n"
+    end
+  end
+end
diff --git a/lib/gitlab/logger.rb b/lib/gitlab/logger.rb
index c3a19e71c10..9405163dced 100644
--- a/lib/gitlab/logger.rb
+++ b/lib/gitlab/logger.rb
@@ -9,17 +9,13 @@ module Gitlab
     end
 
     def self.read_latest
-      path = Rails.root.join("log/githost.log")
+      path = Rails.root.join("log", file_name)
       self.build unless File.exist?(path)
       logs = File.read(path).split("\n")
     end
 
     def self.build
-      new(File.join(Rails.root, "log/githost.log"))
+      new(File.join(Rails.root, "log", file_name))
     end
-
-    def format_message(severity, timestamp, progname, msg)
-      "#{timestamp.to_s(:long)} -> #{severity} -> #{msg}\n" 
-    end 
   end
 end
-- 
GitLab