flexi_config/
flexi_config_setters.rs

1/* Copyright 2016 Joshua Gentry
2 *
3 * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4 * http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5 * <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6 * option. This file may not be copied, modified, or distributed
7 * except according to those terms.
8 */
9
10use FlexiConfig;
11use config::{LogFormat, Priority, Target};
12
13//*************************************************************************************************
14// Defines the convenience setters for the FlexiConfig object.
15impl FlexiConfig
16{
17    //*********************************************************************************************
18    /// Convenience method to set the project.
19    pub fn project(
20        mut self,
21        project : &str
22        ) -> FlexiConfig
23    {
24        self.project = String::from(project);
25
26        self
27    }
28
29    //*********************************************************************************************
30    /// Convenience method to set the list of dependencies.
31    pub fn dependencies(
32        mut self,
33        name : &str,
34        priority : Option<Priority>
35        ) -> FlexiConfig
36    {
37        self.dependencies.insert(String::from(name), priority);
38
39        self
40    }
41
42    //*********************************************************************************************
43    /// Set the priority for all dependencies to the same value.
44    pub fn all_dependencies(
45        mut self,
46        priority : Option<Priority>
47        )
48    {
49        for (_, value) in self.dependencies.iter_mut()
50        {
51            *value = priority.clone();
52        }
53    }
54
55    //*********************************************************************************************
56    /// Convenience method to set the target.
57    pub fn target(
58        mut self,
59        target : Target
60        ) -> FlexiConfig
61    {
62        self.target = target;
63
64        self
65    }
66
67    //*********************************************************************************************
68    /// Convenience method to set the stderr log format.
69    pub fn stderr_format(
70        mut self,
71        format : LogFormat
72        ) -> FlexiConfig
73    {
74        self.stderr_format = format;
75
76        self
77    }
78
79    //*********************************************************************************************
80    /// Convenience method to set the disk log format.
81    pub fn disk_format(
82        mut self,
83        format : LogFormat
84        ) -> FlexiConfig
85    {
86        self.disk_format = format;
87
88        self
89    }
90
91    //*********************************************************************************************
92    /// Convenience method to set the log directory.
93    pub fn disk_dir(
94        mut self,
95        dir : &str
96        ) -> FlexiConfig
97    {
98        if dir.len() > 0
99        {
100            self.disk_dir = Some(String::from(dir));
101        }
102        else
103        {
104            self.disk_dir = None;
105        }
106
107        self
108    }
109
110    //*********************************************************************************************
111    /// Convenience method to set the duplicate error flag.
112    pub fn disk_dup_err(
113        mut self,
114        duplicate : bool
115        ) -> FlexiConfig
116    {
117        self.disk_dup_err = duplicate;
118
119        self
120    }
121
122    //*********************************************************************************************
123    /// Convenience method to set the duplicate info flag.
124    pub fn disk_dup_info(
125        mut self,
126        duplicate : bool
127        ) -> FlexiConfig
128    {
129        self.disk_dup_info = duplicate;
130
131        self
132    }
133
134    //*********************************************************************************************
135    /// Convenience method to set the extension for the log files.
136    pub fn disk_filename_ext(
137        mut self,
138        ext : &str
139        ) -> FlexiConfig
140    {
141        self.disk_filename_ext = String::from(ext);
142
143        self
144    }
145
146    //*********************************************************************************************
147    /// Convenience method to enable/disable a timestamp in the log file names.
148    pub fn disk_filename_time(
149        mut self,
150        enable : bool
151        ) -> FlexiConfig
152    {
153        self.disk_filename_time = enable;
154
155        self
156    }
157
158    //*********************************************************************************************
159    /// Convenience method to set a file size limit.  Setting a size of 0 will disable the file
160    /// size limit.
161    pub fn disk_file_size(
162        mut self,
163        size : u32
164        ) -> FlexiConfig
165    {
166        if size != 0
167        {
168            self.disk_file_size = Some(size);
169        }
170        else
171        {
172            self.disk_file_size = None;
173        }
174
175        self
176    }
177
178    //*********************************************************************************************
179    /// Convenience method to set the log file name suffix.
180    pub fn disk_filename_suffix(
181        mut self,
182        suffix : &str
183        ) -> FlexiConfig
184    {
185        if suffix.len() > 0
186        {
187            self.disk_filename_suffix = Some(String::from(suffix));
188        }
189        else
190        {
191            self.disk_filename_suffix = None;
192        }
193
194        self
195    }
196
197    //*********************************************************************************************
198    /// Convenience method to set the level for logging messages from the application.
199    pub fn app_priority(
200        mut self,
201        level : Priority
202        ) -> FlexiConfig
203    {
204        self.app_priority = level;
205
206        self
207    }
208}