-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: tison <[email protected]>
- Loading branch information
1 parent
4be7d02
commit 4fd68a2
Showing
10 changed files
with
116 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2024 tison <[email protected]> | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::fmt::{Arguments, Debug, Formatter}; | ||
|
||
use crate::layout::Layout; | ||
|
||
pub struct CustomLayout { | ||
#[allow(clippy::type_complexity)] | ||
f: Box< | ||
dyn Fn(&log::Record, &dyn Fn(Arguments) -> anyhow::Result<()>) -> anyhow::Result<()> | ||
+ Send | ||
+ Sync | ||
+ 'static, | ||
>, | ||
} | ||
|
||
impl Debug for CustomLayout { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "CustomLayout {{ ... }}") | ||
} | ||
} | ||
|
||
impl CustomLayout { | ||
pub fn new( | ||
layout: impl Fn(&log::Record, &dyn Fn(Arguments) -> anyhow::Result<()>) -> anyhow::Result<()> | ||
+ Send | ||
+ Sync | ||
+ 'static, | ||
) -> Self { | ||
CustomLayout { | ||
f: Box::new(layout), | ||
} | ||
} | ||
|
||
pub fn format<F>(&self, record: &log::Record, f: &F) -> anyhow::Result<()> | ||
where | ||
F: Fn(Arguments) -> anyhow::Result<()>, | ||
{ | ||
(self.f)(record, f) | ||
} | ||
} | ||
|
||
impl From<CustomLayout> for Layout { | ||
fn from(layout: CustomLayout) -> Self { | ||
Layout::Custom(layout) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
use crate::layout::Layout; | ||
use crate::layout::LayoutImpl; | ||
use std::fmt::Arguments; | ||
|
||
#[derive(Debug, Default, Clone, Copy)] | ||
pub struct Identical; | ||
|
||
impl Layout for Identical { | ||
fn format<F>(&self, record: &log::Record, f: F) -> anyhow::Result<()> | ||
impl Identical { | ||
pub fn format<F>(&self, record: &log::Record, f: &F) -> anyhow::Result<()> | ||
where | ||
F: Fn(&log::Record) -> anyhow::Result<()>, | ||
F: Fn(Arguments) -> anyhow::Result<()>, | ||
{ | ||
f(record) | ||
f(*record.args()) | ||
} | ||
} | ||
|
||
impl From<Identical> for LayoutImpl { | ||
impl From<Identical> for Layout { | ||
fn from(layout: Identical) -> Self { | ||
LayoutImpl::Identical(layout) | ||
Layout::Identical(layout) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.