lioooo_utils 0.3.5 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/lioooo_log.rb CHANGED
@@ -2,11 +2,12 @@
2
2
  require 'colored'
3
3
  require 'logging'
4
4
  require 'benchmark'
5
- LogRoot = File.expand_path("../../log", __FILE__)
5
+ require File.expand_path('../time_utils', __FILE__)
6
+ LogRoot = File.expand_path('../../log', __FILE__)
6
7
  class LiooooUtilsLogger
7
8
  attr_accessor :logger, :log_dir
8
9
 
9
- def initialize type, log_dir=nil
10
+ def initialize(type, log_dir=nil)
10
11
  @log_dir = log_dir.nil? ? LogRoot : log_dir
11
12
  init_log_dir
12
13
  path = File.expand_path("#{log_dir}/#{type}_log.log", __FILE__)
@@ -18,7 +19,7 @@ class LiooooUtilsLogger
18
19
  logger.level = :debug
19
20
  end
20
21
 
21
- def prefix fix
22
+ def prefix(fix)
22
23
  path = File.expand_path("#{LogRoot}/#{fix}_log.log", __FILE__)
23
24
  @logger.add_appenders(
24
25
  Logging.appenders.stdout,
@@ -33,28 +34,33 @@ class LiooooUtilsLogger
33
34
  end
34
35
 
35
36
  # puts log with error prefix
36
- def error msg
37
- msg = "#{msg}"
37
+ def error(msg)
38
+ msg = "[#{now}] #{msg}"
38
39
  @logger.error msg.red
39
40
  end
40
41
 
42
+ def now
43
+ LiooooUtils::TimeUtils.now_y_m_d_s_m_s
44
+ end
45
+
41
46
  # puts log with info prefix
42
- def info msg
47
+ def info(msg)
48
+ msg = "[#{now}] #{msg}"
43
49
  @logger.info msg
44
50
  end
45
51
 
46
- def warn msg
47
- msg = "#{msg} "
52
+ def warn(msg)
53
+ msg = "[#{now}] #{msg}"
48
54
  @logger.warn msg.magenta
49
55
  end
50
56
 
51
57
  def debug msg
52
- msg = "#{msg}"
58
+ msg = "[#{now}] #{msg}"
53
59
  @logger.debug msg.yellow
54
60
  end
55
61
 
56
- def shell msg
57
- msg = "\n #{msg}"
62
+ def shell(msg)
63
+ msg = "\n [#{now}] #{msg}"
58
64
  @logger.debug msg.white_on_black
59
65
  end
60
66
 
@@ -65,13 +71,13 @@ class LiooooUtilsLogger
65
71
  end
66
72
 
67
73
  #---------------------for call shell command----------------
68
- def shell_exec! cmd
74
+ def shell_exec!(cmd)
69
75
  shell cmd
70
76
  system "source ~/.bash_profile && #{cmd}"
71
77
  end
72
78
 
73
79
  # print block exec time
74
- def real_time &block
80
+ def real_time(&block)
75
81
  if block_given?
76
82
  elapsed = Benchmark.realtime do
77
83
  yield
@@ -85,7 +91,7 @@ end
85
91
 
86
92
  # need init when use it
87
93
  #LiooooLogger = LiooooUtilsLogger.new :lioooo, "/tmp"
88
- #LiooooLogger.ba do |ele|
94
+ #LiooooLogger.real_time do |ele|
89
95
  # sleep 3
90
96
  #end
91
97
 
data/lib/lioooo_utils.rb CHANGED
@@ -3,3 +3,4 @@ Root=File.expand_path('../../', __FILE__)
3
3
  require "#{Root}/lib/lioooo_log"
4
4
  require "#{Root}/lib/utils"
5
5
  require "#{Root}/lib/sigcheck"
6
+ require "#{Root}/lib/time_utils"
data/lib/time_utils.rb ADDED
@@ -0,0 +1,14 @@
1
+ #encoding: utf-8
2
+ class LiooooUtils
3
+ module TimeUtils
4
+ class << self
5
+
6
+ #print strftime 2014-04-28 13:24:46
7
+ def now_y_m_d_s_m_s
8
+ Time.now.strftime('%Y-%m-%d %H:%M:%S')
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ #puts LiooooUtils::TimeUtils.now_y_m_d_s_m_s
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lioooo_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-24 00:00:00.000000000 Z
12
+ date: 2014-04-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colored
@@ -151,6 +151,7 @@ files:
151
151
  - lib/lioooo_log.rb
152
152
  - lib/lioooo_utils.rb
153
153
  - lib/sigcheck.rb
154
+ - lib/time_utils.rb
154
155
  - lib/utils.rb
155
156
  - lib/version.rb
156
157
  - LICENSE.txt
@@ -172,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
172
173
  version: '0'
173
174
  segments:
174
175
  - 0
175
- hash: -1136961478188097229
176
+ hash: 2940203827639941500
176
177
  required_rubygems_version: !ruby/object:Gem::Requirement
177
178
  none: false
178
179
  requirements: