Method: SemanticLogger::Appender::File#reopen
- Defined in:
- lib/semantic_logger/appender/file.rb
#reopen ⇒ Object
After forking an active process call #reopen to re-open open the file handles etc to resources.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/semantic_logger/appender/file.rb', line 148 def reopen begin @file&.close rescue StandardError nil end self.current_file_name = apply_format_directives(file_name) if ::File.directory?(file_name) raise(ArgumentError, "The supplied log file_name: #{current_file_name} is already a directory.") end self.log_count = 0 if append && reopen_size && ::File.exist?(current_file_name) self.log_size = ::File.size(current_file_name) self.log_size = 0 if log_size >= reopen_size else self.log_size = 0 end self.reopen_at = reopen_period ? next_reopen_period(reopen_period) : nil = ::File::WRONLY | ::File::CREAT |= ::File::APPEND if append @file = ::File.open(current_file_name, ) # Force all log entries to write immediately without buffering # Allows multiple processes to write to the same log file simultaneously @file.sync = true @file.set_encoding(encoding) if @file.respond_to?(:set_encoding) @file.flock(::File::LOCK_EX) if exclusive_lock @file end |