Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a folder (if not present) with Logger.new?

I'm trying to register a new log

@@my_logger ||= Logger.new("#{Rails.root}/log/my.log") 

but when I try to generate new folders , to put it inside

@@my_logger ||= Logger.new("#{Rails.root}/log/today.to_s/my.log") 

it returns Errno::ENOENT: No such file or directory

May it be a permission problem? How to create a folder (if not present) with Logger.new?

like image 839
Mauro Dias Avatar asked Feb 26 '13 18:02

Mauro Dias


People also ask

How to create a new folder in uipath?

Use create Directory activity to create the folder. Create “Master Folder” using create Directory activity give the path as above. Again use create Directory to create sub folder . Hello Friends, Here some tips how to create folder locally in System by Uipath the may help some of your friends , Here we go!

How do you create a directory in ruby?

Using Ruby's Mkdir Method To Create A New Directory If you want to create a new folder with Ruby you can use the Dir. mkdir method. If given a relative path, this directory is created under the current path ( Dir. pwd ).


2 Answers

Try something like this.

  dir = File.dirname("#{Rails.root}/log/#{today}/my.log")    FileUtils.mkdir_p(dir) unless File.directory?(dir)    @@my_logger ||= Logger.new("#{Rails.root}/log/#{today}/my.log") 
like image 171
Mikhail Nikalyukin Avatar answered Sep 21 '22 19:09

Mikhail Nikalyukin


You can also do this way

directory_name = "name" Dir.mkdir(directory_name) unless File.exists?(directory_name) 
like image 40
user2622247 Avatar answered Sep 21 '22 19:09

user2622247