~nerosnm/oslog

f0e0a1169d79e24e4e38008387fbb6bb3dfd7374 — Søren Mortensen 3 years ago 0e3d740
Rename to oslog and cleaner structure

Signed-off-by: Søren Mortensen <soren@sorenmortensen.com>
16 files changed, 101 insertions(+), 50 deletions(-)

R os_log/.gitignore => .gitignore
A Cargo.toml
M README.md
R os_log_wrapper/.gitignore => liboslog/.gitignore
R os_log_wrapper/Makefile => liboslog/Makefile
R os_log_wrapper/include/os_log_wrapper.h => liboslog/include/oslog.h
R os_log_wrapper/src/os_log_wrapper.c => liboslog/src/oslog.c
A oslog-sys/.gitignore
R os_log/Cargo.toml => oslog-sys/Cargo.toml
R os_log/build.rs => oslog-sys/build.rs
R os_log/include/os_log.h => oslog-sys/include/oslog-sys.h
A oslog-sys/src/lib.rs
R os_log/src/os_log.rs => oslog-sys/src/os_log.rs
A oslog/.gitignore
A oslog/Cargo.toml
R os_log/src/lib.rs => oslog/src/lib.rs
R os_log/.gitignore => .gitignore +0 -0
A Cargo.toml => Cargo.toml +6 -0
@@ 0,0 1,6 @@
[workspace]

members = [
    "oslog-sys",
    "oslog"
]

M README.md => README.md +4 -4
@@ 1,4 1,4 @@
# os_log
# oslog

A Rust [`log`](https://github.com/rust-lang-nursery/log)
implementation that logs messages using Apple's new [unified logging


@@ 10,13 10,13 @@ Add this to your `Cargo.toml`:

```toml
[dependencies]
os_log = { git = "https://github.com/econobox/os_log" }
oslog = { git = "https://github.com/econobox/oslog" }
```

and this to your crate root:

```rust
extern crate os_log;
extern crate oslog;
```

...and then don't do anything, because the library is a work in


@@ 24,5 24,5 @@ progress and doesn't work yet :)

## License

`os_log` is licensed under the [MIT
`oslog` is licensed under the [MIT
License](https://opensource.org/licenses/MIT).

R os_log_wrapper/.gitignore => liboslog/.gitignore +0 -0
R os_log_wrapper/Makefile => liboslog/Makefile +5 -5
@@ 3,17 3,17 @@ CFLAGS=-I$(IDIR)

IDIR=include

_DEPS = os_log_wrapper.h
_DEPS = oslog.h
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))

ODIR=obj

_OBJ = os_log_wrapper.o
_OBJ = oslog.o
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))

SDIR=src

_SRC = os_log_wrapper.c
_SRC = oslog.c
SRC = $(patsubst %,$(SDIR)/%,$(_SRC))

OUTDIR=out


@@ 22,7 22,7 @@ $(ODIR)/%.o: $(SDIR)/%.c $(DEPS)
	@echo "[Compile]" $<
	@$(CC) -c -o $@ $< $(CFLAGS)

$(OUTDIR)/liboslogwrapper.a: $(OBJ)
$(OUTDIR)/liboslog.a: $(OBJ)
	@echo "[Link (Static)]" $<
	@mkdir -p $(OUTDIR)
	@ar rcs $@ $^


@@ 33,4 33,4 @@ clean:
	rm -f $(ODIR)/*.o *~ $(INCDIR)/*~
	rm -rf out

all: liboslogwrapper.a
all: liboslog.a

R os_log_wrapper/include/os_log_wrapper.h => liboslog/include/oslog.h +5 -5
@@ 1,13 1,13 @@
//
//  os_log_wrapper.h
//  os_log_wrapper
//  oslog.h
//  liboslog
//
//  Created by Søren Mortensen on 29/07/2018.
//  Copyright © 2018 Søren Mortensen. All rights reserved.
//

#ifndef oslogwrapper_h
#define oslogwrapper_h
#ifndef oslog_h
#define oslog_h

#include <os/log.h>



@@ 17,4 17,4 @@ void _os_log_debug(const char *str);
void _os_log_error(const char *str);
void _os_log_fault(const char *str);

#endif /* oslogwrapper_h */
#endif /* oslog_h */

R os_log_wrapper/src/os_log_wrapper.c => liboslog/src/oslog.c +3 -3
@@ 1,12 1,12 @@
//
//  os_log_wrapper.c
//  os_log_wrapper
//  oslog.c
//  oslog
//
//  Created by Søren Mortensen on 29/07/2018.
//  Copyright © 2018 Søren Mortensen. All rights reserved.
//

#include "os_log_wrapper.h"
#include "oslog.h"

void _os_log(const char *str) {
    os_log(OS_LOG_DEFAULT, "%{public}s", str);

A oslog-sys/.gitignore => oslog-sys/.gitignore +17 -0
@@ 0,0 1,17 @@

# Created by https://www.gitignore.io/api/rust

### Rust ###
# Generated by Cargo
# will have compiled files and executables
/target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk


# End of https://www.gitignore.io/api/rust

R os_log/Cargo.toml => oslog-sys/Cargo.toml +1 -2
@@ 1,11 1,10 @@
[package]
name = "os_log"
name = "oslog-sys"
version = "0.1.0"
authors = ["Søren Mortensen <soren@sorenmortensen.com>"]
build = "build.rs"

[dependencies]
log = { version = "0.4", features = ["std"] }

[build-dependencies]
bindgen = "0.37"

R os_log/build.rs => oslog-sys/build.rs +9 -8
@@ 13,19 13,20 @@ use std::path::PathBuf;
use std::process::Command;

fn main() {
    let wrapper_dir = concat!(env!("CARGO_MANIFEST_DIR"), "/../os_log_wrapper");
    let liboslog_dir = concat!(env!("CARGO_MANIFEST_DIR"), "/../liboslog");

    Command::new("make")
        .current_dir(PathBuf::from(wrapper_dir))
        .status().unwrap();
    
    println!("cargo:rustc-link-search=native=../os_log_wrapper/out/");
    println!("cargo:rustc-link-lib=static=oslogwrapper");
    
        .current_dir(PathBuf::from(liboslog_dir))
        .status()
        .unwrap();

    println!("cargo:rustc-link-search=native={}/out/", liboslog_dir);
    println!("cargo:rustc-link-lib=static=oslog");

    let bindings = bindgen::Builder::default()
        // The input header we would like to generate
        // bindings for.
        .header("include/os_log.h")
        .header("include/oslog-sys.h")
        // Finish the builder and generate the bindings.
        .generate()
        // Unwrap the Result and panic on failure.

R os_log/include/os_log.h => oslog-sys/include/oslog-sys.h +3 -3
@@ 1,9 1,9 @@
//
//  os_log.h
//  os_log
//  oslog-sys.h
//  oslog-sys
//
//  Created by Søren Mortensen on 28/07/2018.
//  Copyright © 2018 Søren Mortensen. All rights reserved.
//

#include "../../os_log_wrapper/include/os_log_wrapper.h"
#include "../../liboslog/include/oslog.h"

A oslog-sys/src/lib.rs => oslog-sys/src/lib.rs +11 -0
@@ 0,0 1,11 @@
//
//  lib.rs
//  oslog-sys
//
//  Created by Søren Mortensen on 28/07/2018.
//  Copyright © 2018 Søren Mortensen. All rights reserved.
//

mod os_log;

pub use os_log::*;

R os_log/src/os_log.rs => oslog-sys/src/os_log.rs +1 -1
@@ 1,6 1,6 @@
//
//  os_log.rs
//  os_log
//  oslog-sys
//
//  Created by Søren Mortensen on 28/07/2018.
//  Copyright © 2018 Søren Mortensen. All rights reserved.

A oslog/.gitignore => oslog/.gitignore +17 -0
@@ 0,0 1,17 @@

# Created by https://www.gitignore.io/api/rust

### Rust ###
# Generated by Cargo
# will have compiled files and executables
/target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk


# End of https://www.gitignore.io/api/rust

A oslog/Cargo.toml => oslog/Cargo.toml +8 -0
@@ 0,0 1,8 @@
[package]
name = "oslog"
version = "0.1.0"
authors = ["Søren Mortensen <soren@sorenmortensen.com>"]

[dependencies]
log = { version = "0.4", features = ["std"] }
oslog-sys = { path = "../oslog-sys" }

R os_log/src/lib.rs => oslog/src/lib.rs +11 -19
@@ 1,21 1,23 @@
//
//  lib.rs
//  os_log
//  oslog
//
//  Created by Søren Mortensen on 28/07/2018.
//  Created by Søren Mortensen on 29/07/2018.
//  Copyright © 2018 Søren Mortensen. All rights reserved.
//

extern crate log;
extern crate oslog_sys;

pub mod os_log;
use log::{Level, Log, Metadata, Record, SetLoggerError};

use log::{Record, Level, Log, Metadata, SetLoggerError};
use oslog_sys::_os_log_fault;
use oslog_sys::{
    OS_LOG_TYPE_DEBUG, OS_LOG_TYPE_DEFAULT, OS_LOG_TYPE_ERROR, OS_LOG_TYPE_FAULT, OS_LOG_TYPE_INFO,
};

use std::ffi::CString;

use os_log::*;

struct OsLog {
    level: Level,
}


@@ 38,7 40,9 @@ impl Log for OsLog {
        if self.enabled(record.metadata()) {
            let string = format!("{}", record.args());
            let c_string = CString::new(string).unwrap();
            unsafe { _os_log_fault(c_string.as_ptr()); }
            unsafe {
                _os_log_fault(c_string.as_ptr());
            }
        }
    }



@@ 49,15 53,3 @@ pub fn init_with_level(level: Level) -> Result<(), SetLoggerError> {
    log::set_boxed_logger(Box::new(OsLog { level }))
        .map(|()| log::set_max_level(level.to_level_filter()))
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_thing() {
        let string = format!("{}", "This is a test log from os_log");
        let c_string = CString::new(string).unwrap();
        unsafe { _os_log_fault(c_string.as_ptr()); }
    }
}