Creating directories

J

Joe Van Dyk

There seem to have been a bunch of filesystem-related releases
recently. So I'm not sure if one of them would address my problem
better than something that's in the standard library.

I'm starting a bunch of applications and need to write their stdout
and stderr to logs. Log files are stored at /<some_base_path>/<user
name>/<application name>.log.

What's the simplest way of creating all those directories (assuming
that none of them exist)?
 
A

Ara.T.Howard

There seem to have been a bunch of filesystem-related releases
recently. So I'm not sure if one of them would address my problem
better than something that's in the standard library.

I'm starting a bunch of applications and need to write their stdout
and stderr to logs. Log files are stored at /<some_base_path>/<user
name>/<application name>.log.

What's the simplest way of creating all those directories (assuming
that none of them exist)?

require 'fileutils'
FileUtils::mkdir_p 'dir'

you don't need to care if it exsts and all subdirs are created on the fly.

cheers.

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze. --Nagarjuna
===============================================================================
 
A

Ara.T.Howard

Thanks!

And a related question: Every time I start an application, I want to write
to a new log file. But I want to keep the old log files around (i.e. rotate
them). Can I do that with Logger? I see options for rotating when a log
file gets to a certain size or on a daily, weekly, monthly basis, but not
when I'm creating a new one.

require 'logger'

logger = Logger:new 'log', log_age

# or

logger = Logger:new 'log', log_age, log_size


# log_age can be daily|weekly|monthly|number_of_days

whammo. log rolling.

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze. --Nagarjuna
===============================================================================
 
J

Joe Van Dyk

require 'logger'

logger =3D Logger:new 'log', log_age

# or

logger =3D Logger:new 'log', log_age, log_size


# log_age can be daily|weekly|monthly|number_of_days

whammo. log rolling.

:) You might want to re-read my question.

Every time I start the application, I want to create a new log file
and rotate the old ones (say, keep the last 10). I did see the
options for rotating on size and by date. But I didn't see an option
for rolling the log for every new application launch.

So, if I start the application 5 times, there should be five log files.
 
A

Ara.T.Howard

:) You might want to re-read my question.
oops.

Every time I start the application, I want to create a new log file and
rotate the old ones (say, keep the last 10). I did see the options for
rotating on size and by date. But I didn't see an option for rolling the
log for every new application launch.

So, if I start the application 5 times, there should be five log files.

perhaps:


jib:~/tmp > ruby -e' print ARGF.read ' a.rb
require 'logger'

force_roll = Logger::new 'log', 7, 0
force_roll << ''
force_roll.close

logger = Logger::new 'log', 7

logger.info{ Process::pid }


jib:~/tmp > ruby -e' p Dir[ "log*" ] '
[]


jib:~/tmp > ruby -e' 10.times{ load "a.rb" } '


jib:~/tmp > ruby -e' p Dir[ "log*" ] '
["log", "log.0", "log.1", "log.2", "log.3", "log.4", "log.5"]

but kinda hackish...

hth.

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze. --Nagarjuna
===============================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top