@@ -7,6 +7,7 @@ extern crate exitcode;
77extern crate image;
88#[ macro_use]
99extern crate log;
10+ extern crate num_cpus;
1011extern crate palette;
1112extern crate rand;
1213extern crate rayon;
@@ -20,14 +21,13 @@ mod errors;
2021mod models;
2122mod operations;
2223
23- use flexi_logger:: { Logger , opt_format } ;
24+ use flexi_logger:: { opt_format , Cleanup , Criterion , Logger , Naming } ;
2425use indicatif:: { MultiProgress , ProgressBar , ProgressStyle } ;
2526use std:: {
2627 ffi:: OsStr ,
2728 io,
2829 path:: { Path , PathBuf } ,
2930 process:: { Command , Stdio } ,
30- thread,
3131} ;
3232use walkdir:: { DirEntry , WalkDir } ;
3333
@@ -52,12 +52,17 @@ use walkdir::{DirEntry, WalkDir};
5252fn main ( ) {
5353 let args = args:: application_args ( ) ;
5454
55- Logger :: with_str ( "vcsr=debug,info,warn" )
56- . log_to_file ( )
57- . duplicate_to_stderr ( flexi_logger:: Duplicate :: Info )
58- . directory ( dirs:: home_dir ( ) . unwrap ( ) . join ( ".vcsr" ) . join ( "logs" ) )
59- . format ( opt_format) . start ( )
60- . unwrap ( ) ;
55+ let log_level = match & args. verbose {
56+ true => String :: from ( "debug,info,warn,error" ) ,
57+ false => String :: from ( "info,warn,error" ) ,
58+ } ;
59+ Logger :: with_str ( log_level)
60+ . log_to_file ( )
61+ . directory ( dirs:: home_dir ( ) . unwrap ( ) . join ( ".vcsr" ) . join ( "logs" ) )
62+ . rotate ( Criterion :: Size ( 20000 ) , Naming :: Numbers , Cleanup :: Never )
63+ . format ( opt_format)
64+ . start ( )
65+ . unwrap ( ) ;
6166
6267 let multi = MultiProgress :: new ( ) ;
6368 let bar_style = ProgressStyle :: default_bar ( )
@@ -70,14 +75,17 @@ fn main() {
7075 . stderr ( Stdio :: null ( ) )
7176 . output ( )
7277 {
73- Ok ( _) => debug ! ( "ffmpeg installed. Continuing." ) ,
78+ Ok ( _) => info ! ( "ffmpeg installed. Continuing." ) ,
7479 Err ( _) => {
7580 error ! ( "ffmpeg not installed. Exiting." ) ;
7681 std:: process:: exit ( exitcode:: SOFTWARE )
7782 }
7883 } ;
7984 let mut walker: WalkDir ;
80-
85+ let pool = rayon:: ThreadPoolBuilder :: new ( )
86+ . num_threads ( num_cpus:: get ( ) * 2 )
87+ . build ( )
88+ . unwrap ( ) ;
8189 for path in & args. filenames {
8290 if !Path :: new ( path) . exists ( ) {
8391 error ! ( "File does not exist, trying next: {}" , path) ;
@@ -107,18 +115,22 @@ fn main() {
107115 bar. set_style ( bar_style. clone ( ) ) ;
108116 let mut current_args = args. clone ( ) ;
109117 let entry_copy = entry. clone ( ) ;
110- let _ = thread :: spawn ( move || match process_file ( entry, & mut current_args, & bar) {
118+ let _ = pool . spawn ( move || match process_file ( entry, & mut current_args, & bar) {
111119 Ok ( file_name) => {
112120 let m = format ! (
113121 "succesfully created {}" ,
114- file_name. file_name( ) . unwrap( ) . to_string_lossy( ) ) ;
122+ file_name. file_name( ) . unwrap( ) . to_string_lossy( )
123+ ) ;
115124
116- debug ! ( "{}" , & m) ;
125+ info ! ( "{}" , & m) ;
117126 bar. finish_with_message ( & m) ;
118127 }
119128 Err ( err) => {
120- error ! ( "Skipped {}: {}" , entry_copy. file_name( ) . to_string_lossy( ) . to_owned( ) , err. to_string( ) ) ;
121- // std::process::exit(-1);
129+ error ! (
130+ "Skipped {}: {}" ,
131+ entry_copy. file_name( ) . to_string_lossy( ) . to_owned( ) ,
132+ err. to_string( )
133+ ) ;
122134 }
123135 } ) ;
124136 }
@@ -140,7 +152,7 @@ fn process_file(
140152
141153 if !dir_entry. path ( ) . exists ( ) {
142154 if args. ignore_errors {
143- debug ! ( "File does not exist, skipping {}: " , file_name_str) ;
155+ info ! ( "File does not exist, skipping {}: " , file_name_str) ;
144156 return Ok ( dir_entry. path ( ) . to_path_buf ( ) ) ;
145157 } else {
146158 return Err ( errors:: CustomError :: Io ( io:: Error :: new (
@@ -171,7 +183,7 @@ fn process_file(
171183
172184 if args. no_overwrite {
173185 if Path :: new ( & output_path) . exists ( ) {
174- debug ! (
186+ info ! (
175187 "contact sheet already exists, skipping {}" ,
176188 & output_path. to_string_lossy( ) . to_owned( ) . to_owned( )
177189 ) ;
@@ -337,7 +349,7 @@ fn process_file(
337349 if !Path :: new ( thumbnail_output_path) . exists ( ) {
338350 std:: fs:: create_dir_all ( thumbnail_output_path) ?;
339351 }
340- debug ! ( "Copying thumbnails to {}" , thumbnail_output_path) ;
352+ info ! ( "Copying thumbnails to {}" , thumbnail_output_path) ;
341353 for ( i, frame) in selected_frames. iter ( ) . enumerate ( ) {
342354 let thumbnail_file_extension = Path :: new ( & frame. filename ) . extension ( ) . unwrap ( ) ;
343355 let thumbnail_filename = format ! (
0 commit comments