Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
library/generic/create_log.rb | 154 | 51 | 94.16%
|
82.35%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
2 =begin |
3 *Name : CreateLog |
4 *Description : class that defines custom logger methods |
5 *Author : Chandra sekaran |
6 *Creation Date : 23/08/2014 |
7 *Updation Date : |
8 =end |
9 |
10 module CUKES |
11 class CreateLog |
12 include FileLibrary # module that define methods all file related manipulations |
13 include DateTimeLibrary # module that define methods for all datetime related manipulations |
14 |
15 # Description : initializes the Logger class and creates a new log file |
16 # Author : Chandra sekaran |
17 # Arguments : |
18 # str_logfile_name: name of the log file to be created |
19 # |
20 def initialize(str_logfile_name = "log_") |
21 begin |
22 date_time_format = DATETIME_FORMAT || "%d_%m_%Y-%H_%M_%S" |
23 rescue Exception => ex |
24 date_time_format = "%d_%m_%Y-%H_%M_%S" # when DATETIME_FORMAT is not defined |
25 end |
26 |
27 begin |
28 level = LOGGER_LEVEL || "DEBUG" |
29 rescue Exception => ex |
30 level = "DEBUG" # when LOGGER_LEVEL is not defined |
31 end |
32 |
33 begin |
34 @str_logdir_name = $current_log_dir || "./test_result/test_report_#{Time.now.strftime(date_time_format)}" # this line is enough, ex handlng not need |
35 rescue Exception => ex |
36 @str_logdir_name = "./test_result/test_report_#{Time.now.strftime(date_time_format)}" |
37 end |
38 |
39 create_directory(@str_logdir_name) # creates a new directory |
40 @log_file = "#{@str_logdir_name}/#{str_logfile_name}.log" |
41 @log = Logger.new(@log_file) # creates a new log file |
42 set_level(level) # sets the Logger::Level |
43 @log.datetime_format = date_time_format # sets the datetime format |
44 @log.formatter = lambda do |severity, datetime, progname, message| |
45 "[#{Time.now.strftime(date_time_format)}] #{severity}: #{message}\n" # customize the log content |
46 end |
47 end |
48 |
49 # Description : logs a DEBUG message |
50 # Author : Chandra sekaran |
51 # Arguments : |
52 # message : string message to be logged |
53 # |
54 def debug(message) |
55 @log.debug(message) |
56 end |
57 |
58 # Description : logs an INFO message |
59 # Author : Chandra sekaran |
60 # Arguments : |
61 # message : string message to be logged |
62 # |
63 def info(message) |
64 @log.info(message) |
65 end |
66 |
67 # Description : logs a WARN message |
68 # Author : Chandra sekaran |
69 # Arguments : |
70 # message : string message to be logged |
71 # |
72 def warn(message) |
73 @log.warn(message) |
74 end |
75 |
76 # Description : logs an ERROR message |
77 # Author : Chandra sekaran |
78 # Arguments : |
79 # message : string message to be logged |
80 # |
81 def error(message) |
82 @log.error(message) |
83 #$world.puts(message) if !$world.nil? |
84 #exit #raise #"EXCEPTION RAISED"#Cucumber.wants_to_quit = true # exit(1) |
85 end |
86 |
87 # Description : logs a success message |
88 # Author : Chandra sekaran |
89 # Arguments : |
90 # message : string message to be logged |
91 # |
92 def success(message) |
93 info(message) |
94 $world.puts(message) if !$world.nil? |
95 end |
96 |
97 # Description : logs a FATAL message |
98 # Author : Chandra sekaran |
99 # Arguments : |
100 # message : string message to be logged |
101 # |
102 def fatal(message) |
103 @log.fatal(message) |
104 end |
105 |
106 # Description : sets the logger level |
107 # Author : Chandra sekaran |
108 # Arguments : |
109 # level : logger level string |
110 # |
111 def set_level(level) |
112 case level.upcase |
113 when "DEBUG" |
114 @log.level = Logger::DEBUG |
115 when "INFO" |
116 @log.level = Logger::INFO |
117 when "WARN" |
118 @log.level = Logger::WARN |
119 when "ERROR" |
120 @log.level = Logger::ERROR |
121 when "FATAL" |
122 @log.level = Logger::FATAL |
123 end |
124 end |
125 |
126 # Description : creates a new directory under the given path (newly added to override the method in file_library.rb) |
127 # Author : Chandra sekaran |
128 # Arguments : |
129 # str_directory_path : relative path of the directory to be created |
130 # |
131 def create_directory(str_directory_path) |
132 unless File.directory?(str_directory_path) |
133 FileUtils.mkdir_p(str_directory_path) |
134 puts "New directory created under : #{str_directory_path}" |
135 end |
136 end |
137 |
138 # Description : returns the relative path of currently created directory |
139 # Author : Chandra sekaran |
140 # |
141 def get_current_log_dir |
142 @str_logdir_name |
143 end |
144 |
145 # Description : returns the relative path of currently created file (logfile) |
146 # Author : Chandra sekaran |
147 # |
148 def get_current_log_file |
149 @log_file |
150 end |
151 |
152 private |
153 attr_reader :log |
154 end |
155 end |
Generated on 2015-05-08 10:40:30 +0530 with SimpleCov-RCov 0.2.3