Skip to content

Commit ee9f742

Browse files
authored
chore(logging): increase log verbosity (#1244)
* chore(logging): increase log verbosity in git-cliff/src/lib.rs * chore(logging): increase log verbosity in git-cliff/src/lib.rs and git-cliff/src/profile.rs * chore(logging): increase log verbosity in git-cliff-core/src/changelog.rs * chore(logging): increase log verbosity in git-cliff-core/src/commit.rs * chore(logging): increase log verbosity in git-cliff-core/src/config.rs * chore(logging): increase log verbosity in git-cliff-core/src/lib.rs * chore(logging): increase log verbosity in git-cliff-core/src/repo.rs * chore(logging): increase log verbosity in git-cliff-core/src/remote/mod.rs * chore(logging): increase log verbosity in git-cliff-core/src/statistics.rs * chore(logging): increase log verbosity in git-cliff-core/src/template.rs * ci: trigger actions Signed-off-by: Shingo OKAWA <[email protected]> * fix: address review feedback Signed-off-by: Shingo OKAWA <[email protected]> * fix: address review feedback Signed-off-by: Shingo OKAWA <[email protected]> * ci: trigger GitHub Actions workflow Signed-off-by: Shingo OKAWA <[email protected]> * fix: address review feedback Signed-off-by: Shingo OKAWA <[email protected]> --------- Signed-off-by: Shingo OKAWA <[email protected]>
1 parent 3da8f26 commit ee9f742

File tree

11 files changed

+80
-95
lines changed

11 files changed

+80
-95
lines changed

git-cliff-core/src/changelog.rs

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,16 @@ impl<'a> Changelog<'a> {
8888
match commit.process(git_config) {
8989
Ok(commit) => Some(commit),
9090
Err(e) => {
91-
trace!(
92-
"{} - {} ({})",
93-
commit.id.chars().take(7).collect::<String>(),
94-
e,
95-
commit.message.lines().next().unwrap_or_default().trim()
96-
);
91+
let short_id = commit.id.chars().take(7).collect::<String>();
92+
let summary = commit.message.lines().next().unwrap_or_default().trim();
93+
match &e {
94+
Error::ParseError(_) | Error::FieldError(_) => {
95+
log::warn!("{short_id} - {e} ({summary})");
96+
}
97+
_ => {
98+
log::trace!("{short_id} - {e} ({summary})");
99+
}
100+
}
97101
None
98102
}
99103
}
@@ -102,12 +106,11 @@ impl<'a> Changelog<'a> {
102106
/// Checks the commits and returns an error if any unconventional commits
103107
/// are found.
104108
fn check_conventional_commits(commits: &Vec<Commit<'a>>) -> Result<()> {
105-
debug!("Verifying that all commits are conventional.");
109+
log::debug!("Verifying that all commits are conventional");
106110
let mut unconventional_count = 0;
107-
108111
commits.iter().for_each(|commit| {
109112
if commit.conv.is_none() {
110-
error!(
113+
log::error!(
111114
"Commit {id} is not conventional:\n{message}",
112115
id = &commit.id[..7],
113116
message = commit
@@ -164,7 +167,7 @@ impl<'a> Changelog<'a> {
164167
/// Processes the commits and omits the ones that doesn't match the
165168
/// criteria set by configuration file.
166169
fn process_commits(&mut self) -> Result<()> {
167-
debug!("Processing the commits...");
170+
log::debug!("Processing the commits");
168171
for release in self.releases.iter_mut() {
169172
Self::process_commit_list(&mut release.commits, &self.config.git)?;
170173
for submodule_commits in release.submodule_commits.values_mut() {
@@ -176,7 +179,7 @@ impl<'a> Changelog<'a> {
176179

177180
/// Processes the releases and filters them out based on the configuration.
178181
fn process_releases(&mut self) {
179-
debug!("Processing {} release(s)...", self.releases.len());
182+
log::debug!("Processing {} release(s)", self.releases.len());
180183
let skip_regex = self.config.git.skip_tags.as_ref();
181184
let mut skipped_tags = Vec::new();
182185
self.releases = self
@@ -188,13 +191,13 @@ impl<'a> Changelog<'a> {
188191
if let Some(version) = &release.version {
189192
if skip_regex.is_some_and(|r| r.is_match(version)) {
190193
skipped_tags.push(version.clone());
191-
trace!("Skipping release: {}", version);
194+
log::debug!("Skipping release: {}", version);
192195
return false;
193196
}
194197
}
195198
if release.commits.is_empty() {
196199
if let Some(version) = release.version.clone() {
197-
trace!("Release doesn't have any commits: {}", version);
200+
log::debug!("Release doesn't have any commits: {}", version);
198201
}
199202
match &release.previous {
200203
Some(prev_release) if prev_release.commits.is_empty() => {
@@ -250,11 +253,8 @@ impl<'a> Changelog<'a> {
250253
.map(|v| v.contains_variable(github::TEMPLATE_VARIABLES))
251254
.unwrap_or(false)
252255
{
253-
debug!(
254-
"You are using an experimental feature! Please report bugs at <https://git-cliff.org/issues>"
255-
);
256256
let github_client = GitHubClient::try_from(self.config.remote.github.clone())?;
257-
info!(
257+
log::info!(
258258
"{} ({})",
259259
github::START_FETCHING_MSG,
260260
self.config.remote.github
@@ -267,11 +267,11 @@ impl<'a> Changelog<'a> {
267267
github_client.get_commits(ref_name),
268268
github_client.get_pull_requests(ref_name),
269269
)?;
270-
debug!("Number of GitHub commits: {}", commits.len());
271-
debug!("Number of GitHub pull requests: {}", pull_requests.len());
270+
log::debug!("Number of GitHub commits: {}", commits.len());
271+
log::debug!("Number of GitHub pull requests: {}", pull_requests.len());
272272
Ok((commits, pull_requests))
273273
});
274-
info!("{}", github::FINISHED_FETCHING_MSG);
274+
log::info!("{}", github::FINISHED_FETCHING_MSG);
275275
data
276276
} else {
277277
Ok((vec![], vec![]))
@@ -304,11 +304,8 @@ impl<'a> Changelog<'a> {
304304
.map(|v| v.contains_variable(gitlab::TEMPLATE_VARIABLES))
305305
.unwrap_or(false)
306306
{
307-
debug!(
308-
"You are using an experimental feature! Please report bugs at <https://git-cliff.org/issues>"
309-
);
310307
let gitlab_client = GitLabClient::try_from(self.config.remote.gitlab.clone())?;
311-
info!(
308+
log::info!(
312309
"{} ({})",
313310
gitlab::START_FETCHING_MSG,
314311
self.config.remote.gitlab
@@ -321,7 +318,7 @@ impl<'a> Changelog<'a> {
321318
let project_id = match tokio::join!(gitlab_client.get_project(ref_name)) {
322319
(Ok(project),) => project.id,
323320
(Err(err),) => {
324-
error!("Failed to lookup project! {}", err);
321+
log::error!("Failed to lookup project! {}", err);
325322
return Err(err);
326323
}
327324
};
@@ -330,11 +327,11 @@ impl<'a> Changelog<'a> {
330327
gitlab_client.get_commits(project_id, ref_name),
331328
gitlab_client.get_merge_requests(project_id, ref_name),
332329
)?;
333-
debug!("Number of GitLab commits: {}", commits.len());
334-
debug!("Number of GitLab merge requests: {}", merge_requests.len());
330+
log::debug!("Number of GitLab commits: {}", commits.len());
331+
log::debug!("Number of GitLab merge requests: {}", merge_requests.len());
335332
Ok((commits, merge_requests))
336333
});
337-
info!("{}", gitlab::FINISHED_FETCHING_MSG);
334+
log::info!("{}", gitlab::FINISHED_FETCHING_MSG);
338335
data
339336
} else {
340337
Ok((vec![], vec![]))
@@ -365,11 +362,8 @@ impl<'a> Changelog<'a> {
365362
.map(|v| v.contains_variable(gitea::TEMPLATE_VARIABLES))
366363
.unwrap_or(false)
367364
{
368-
debug!(
369-
"You are using an experimental feature! Please report bugs at <https://git-cliff.org/issues>"
370-
);
371365
let gitea_client = GiteaClient::try_from(self.config.remote.gitea.clone())?;
372-
info!(
366+
log::info!(
373367
"{} ({})",
374368
gitea::START_FETCHING_MSG,
375369
self.config.remote.gitea
@@ -382,11 +376,11 @@ impl<'a> Changelog<'a> {
382376
gitea_client.get_commits(ref_name),
383377
gitea_client.get_pull_requests(ref_name),
384378
)?;
385-
debug!("Number of Gitea commits: {}", commits.len());
386-
debug!("Number of Gitea pull requests: {}", pull_requests.len());
379+
log::debug!("Number of Gitea commits: {}", commits.len());
380+
log::debug!("Number of Gitea pull requests: {}", pull_requests.len());
387381
Ok((commits, pull_requests))
388382
});
389-
info!("{}", gitea::FINISHED_FETCHING_MSG);
383+
log::info!("{}", gitea::FINISHED_FETCHING_MSG);
390384
data
391385
} else {
392386
Ok((vec![], vec![]))
@@ -422,11 +416,8 @@ impl<'a> Changelog<'a> {
422416
.map(|v| v.contains_variable(bitbucket::TEMPLATE_VARIABLES))
423417
.unwrap_or(false)
424418
{
425-
debug!(
426-
"You are using an experimental feature! Please report bugs at <https://git-cliff.org/issues>"
427-
);
428419
let bitbucket_client = BitbucketClient::try_from(self.config.remote.bitbucket.clone())?;
429-
info!(
420+
log::info!(
430421
"{} ({})",
431422
bitbucket::START_FETCHING_MSG,
432423
self.config.remote.bitbucket
@@ -439,11 +430,11 @@ impl<'a> Changelog<'a> {
439430
bitbucket_client.get_commits(ref_name),
440431
bitbucket_client.get_pull_requests(ref_name)
441432
)?;
442-
debug!("Number of Bitbucket commits: {}", commits.len());
443-
debug!("Number of Bitbucket pull requests: {}", pull_requests.len());
433+
log::debug!("Number of Bitbucket commits: {}", commits.len());
434+
log::debug!("Number of Bitbucket pull requests: {}", pull_requests.len());
444435
Ok((commits, pull_requests))
445436
});
446-
info!("{}", bitbucket::FINISHED_FETCHING_MSG);
437+
log::info!("{}", bitbucket::FINISHED_FETCHING_MSG);
447438
data
448439
} else {
449440
Ok((vec![], vec![]))
@@ -462,7 +453,7 @@ impl<'a> Changelog<'a> {
462453
/// Adds remote data (e.g. GitHub commits) to the releases.
463454
#[allow(unused_variables)]
464455
pub fn add_remote_data(&mut self, range: Option<&str>) -> Result<()> {
465-
debug!("Adding remote data...");
456+
log::debug!("Adding remote data");
466457
self.add_remote_context()?;
467458

468459
// Determine the ref at which to fetch remote commits, based on the commit
@@ -524,7 +515,7 @@ impl<'a> Changelog<'a> {
524515
if last_release.version.is_none() {
525516
let next_version =
526517
last_release.calculate_next_version_with_config(&self.config.bump)?;
527-
debug!("Bumping the version to {next_version}");
518+
log::debug!("Bumping the version to {next_version}");
528519
last_release.version = Some(next_version.to_string());
529520
last_release.timestamp = Some(
530521
SystemTime::now()
@@ -540,7 +531,7 @@ impl<'a> Changelog<'a> {
540531

541532
/// Generates the changelog and writes it to the given output.
542533
pub fn generate<W: Write + ?Sized>(&self, out: &mut W) -> Result<()> {
543-
debug!("Generating changelog...");
534+
log::debug!("Generating changelog");
544535
let postprocessors = self.config.changelog.postprocessors.clone();
545536

546537
if let Some(header_template) = &self.header_template {
@@ -603,7 +594,7 @@ impl<'a> Changelog<'a> {
603594

604595
/// Generates a changelog and prepends it to the given changelog.
605596
pub fn prepend<W: Write + ?Sized>(&self, mut changelog: String, out: &mut W) -> Result<()> {
606-
debug!("Generating changelog and prepending...");
597+
log::debug!("Generating changelog and prepending");
607598
if let Some(header) = &self.config.changelog.header {
608599
changelog = changelog.replacen(header, "", 1);
609600
}
@@ -632,7 +623,7 @@ fn get_body_template(config: &Config, trim: bool) -> Result<Template> {
632623
"commit.bitbucket",
633624
];
634625
if template.contains_variable(&deprecated_vars) {
635-
warn!(
626+
log::warn!(
636627
"Variables {deprecated_vars:?} are deprecated and will be removed in the future. Use \
637628
`commit.remote` instead."
638629
);

git-cliff-core/src/commit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ impl Commit<'_> {
327327
match values {
328328
Some(values) => {
329329
if values.is_empty() {
330-
trace!("field '{field_name}' is present but empty");
330+
log::trace!("Field '{field_name}' is present but empty");
331331
} else {
332332
for value in values {
333333
regex_checks.push((pattern_regex, value));

git-cliff-core/src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,10 @@ impl Bump {
354354
/// This function also logs the returned value.
355355
pub fn get_initial_tag(&self) -> String {
356356
if let Some(tag) = self.initial_tag.clone() {
357-
warn!("No releases found, using initial tag '{tag}' as the next version.");
357+
log::warn!("No releases found, using initial tag '{tag}' as the next version");
358358
tag
359359
} else {
360-
warn!("No releases found, using {DEFAULT_INITIAL_TAG} as the next version.");
360+
log::warn!("No releases found, using {DEFAULT_INITIAL_TAG} as the next version");
361361
DEFAULT_INITIAL_TAG.into()
362362
}
363363
}
@@ -499,7 +499,7 @@ impl Config {
499499
.filter_map(|v| v.as_ref())
500500
{
501501
if supported_path.exists() {
502-
debug!("Using configuration file from: {:?}", supported_path);
502+
log::debug!("Using configuration file from: {:?}", supported_path);
503503
return Some(supported_path.to_path_buf());
504504
}
505505
}

git-cliff-core/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub enum Error {
3333
LoggerError(String),
3434
/// When commit's not follow the conventional commit structure we throw this
3535
/// error.
36-
#[error("Cannot parse the commit: `{0}`")]
36+
#[error("Commit did not match conventional format: `{0}`")]
3737
ParseError(#[from] git_conventional::Error),
3838
/// Error that may occur while grouping commits.
3939
#[error("Grouping error: `{0}`")]

git-cliff-core/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ pub mod tag;
4242
/// Template engine.
4343
pub mod template;
4444

45-
#[macro_use]
46-
extern crate log;
47-
4845
/// Default configuration file.
4946
pub const DEFAULT_CONFIG: &str = "cliff.toml";
5047
/// Default output file.

git-cliff-core/src/remote/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,15 @@ pub trait RemoteClient {
190190
page: i32,
191191
) -> Result<T> {
192192
let url = T::url(project_id, &self.api_url(), &self.remote(), ref_name, page);
193-
debug!("Sending request to: {url}");
193+
log::debug!("Sending request to: {url}");
194194
let response = self.client().get(&url).send().await?;
195195
let response_text = if response.status().is_success() {
196196
let text = response.text().await?;
197-
trace!("Response: {:?}", text);
197+
log::trace!("Response: {:?}", text);
198198
text
199199
} else {
200200
let text = response.text().await?;
201-
error!("Request error: {}", text);
201+
log::error!("Request error: {}", text);
202202
text
203203
};
204204
Ok(serde_json::from_str::<T>(&response_text)?)
@@ -212,15 +212,15 @@ pub trait RemoteClient {
212212
page: i32,
213213
) -> Result<Vec<T>> {
214214
let url = T::url(project_id, &self.api_url(), &self.remote(), ref_name, page);
215-
debug!("Sending request to: {url}");
215+
log::debug!("Sending request to: {url}");
216216
let response = self.client().get(&url).send().await?;
217217
let response_text = if response.status().is_success() {
218218
let text = response.text().await?;
219-
trace!("Response: {:?}", text);
219+
log::trace!("Response: {:?}", text);
220220
text
221221
} else {
222222
let text = response.text().await?;
223-
error!("Request error: {}", text);
223+
log::error!("Request error: {}", text);
224224
text
225225
};
226226
let response = serde_json::from_str::<Vec<T>>(&response_text)?;
@@ -244,7 +244,7 @@ pub trait RemoteClient {
244244
.buffered(T::buffer_size())
245245
.take_while(|page| {
246246
if let Err(e) = page {
247-
debug!("Error while fetching page: {:?}", e);
247+
log::debug!("Error while fetching page: {:?}", e);
248248
}
249249
future::ready(page.is_ok())
250250
})
@@ -275,7 +275,7 @@ pub trait RemoteClient {
275275
let status = match page {
276276
Ok(v) => !self.early_exit(v),
277277
Err(e) => {
278-
debug!("Error while fetching page: {:?}", e);
278+
log::debug!("Error while fetching page: {:?}", e);
279279
true
280280
}
281281
};

git-cliff-core/src/repo.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl Repository {
189189
// submodule updated
190190
Some(format!("{}..{}", old_file_id, new_file_id))
191191
};
192-
trace!("Release commit range for submodules: {:?}", range);
192+
log::trace!("Release commit range for submodules: {:?}", range);
193193
delta.new_file().path().and_then(Path::to_str).zip(range)
194194
});
195195
// iterate through all path diffs and find corresponding submodule if
@@ -305,11 +305,11 @@ impl Repository {
305305
cache_key,
306306
v,
307307
) {
308-
error!("Failed to set cache for repo {:?}: {e}", self.path);
308+
log::error!("Failed to set cache for repo {:?}: {e}", self.path);
309309
}
310310
}
311311
Err(e) => {
312-
error!("Failed to serialize cache for repo {:?}: {e}", self.path);
312+
log::error!("Failed to serialize cache for repo {:?}: {e}", self.path);
313313
}
314314
}
315315

@@ -500,7 +500,7 @@ impl Repository {
500500
.url()
501501
.ok_or_else(|| Error::RepoError(String::from("failed to get the remote URL")))?
502502
.to_string();
503-
trace!("Upstream URL: {url}");
503+
log::trace!("Upstream URL: {url}");
504504
return find_remote(&url);
505505
}
506506
}

git-cliff-core/src/statistics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ impl From<&Release<'_>> for Statistics {
5252
fn from(release: &Release) -> Self {
5353
let commit_count = release.commits.len();
5454
let commits_timespan = if release.commits.len() < 2 {
55-
trace!(
56-
"commits_timespan: insufficient commits to calculate duration (found {})",
55+
log::trace!(
56+
"Insufficient commits to calculate duration (found {})",
5757
release.commits.len()
5858
);
5959
None
@@ -105,7 +105,7 @@ impl From<&Release<'_>> for Statistics {
105105
)
106106
.map(|(curr, prev)| (curr.date_naive() - prev.date_naive()).num_days()),
107107
None => {
108-
trace!("days_passed_since_last_release: previous release not found");
108+
log::trace!("Previous release not found");
109109
None
110110
}
111111
};

0 commit comments

Comments
 (0)