Git Product home page Git Product logo

ezlog's Introduction

EZLog

中文介绍

🦀️Rust 移动端开发体验

EZLog is a high efficiency Cross-platform logging library.

it is inspired by Xlog and Loagan, rewrite in Rust.

Feature

  • iOS, Android, MacOS support.
  • map file into memory by mmap.
  • zlib compression.
  • AEAD encryption.
  • fetch log by callback.
  • trim out of date files.
  • CLI paser support.

Quick Start

iOS

By CocoaPods

Add EZLog to Podfile

pod 'EZLog', '~> 0.1'

then

pod update

Open Xcode, add sample code

import EZLog

init() {
    pthread_setname_np("main")
    #if DEBUG
    ezlogInitWithTrace()
    #else
    ezlogInit()
    #endif
    
    let dirPath = URL.documents.appendingPathComponent("ezlog").relativePath
    let config = EZLogConfig(level: Level.trace,
                                dirPath: dirPath,
                                name: "demo",
                                keepDays: 7,
                                maxSize: 150*1024,
                                compress: CompressKind.ZLIB,
                                compressLevel: CompressLevel.DEFAULT,
                                cipher: Cipher.AES128GCM,
                                cipherKey: [UInt8]("a secret key!!!!".utf8),
                                cipherNonce: [UInt8]("unique nonce".utf8))
    let logger = EZLogger(config: config)

    ezlogRegisterCallback(success: {name, date, logs in
        if !logs.isEmpty {
            for log in logs {
                print("name:" + name + " date:" + date + " log:" + log);
            }
        } else {
            print("no log found at that time")
        }
        
    }, fail: {name, date, err in
        print("name:" + name + " date:" + date + " err:" + err);
    })
    
    logger.debug("first blood")
}
  1. click run and see console ouput.

Android

Add ezlog to dependencies

open top-level build.gradle, add mavenCentral to repositories.

buildscript {
    repositories {
        ...
        mavenCentral()
        ...
    }
}

allprojects {
    repositories {
        ...
        mavenCentral()
        ...
    }
}

open app level build.gradle, add ezlog

dependencies {
    implementation "wtf.s1.ezlog:ezlog:0.1.4"
}

sync gradle

Setup in application. For example

override fun onCreate() {
    super.onCreate()

    val path = File(filesDir, "ezlog").absolutePath
    val config = EZLogConfig.Builder("demo", path)
        .compress(EZLog.CompressZlib)
        .compressLevel(EZLog.CompressFast)
        .cipher(EZLog.Aes128Gcm)
        .cipherKey("a secret key!!!!".toByteArray())
        .cipherNonce("unique nonce".toByteArray())
        .enableTrace(BuildConfig.DEBUG)
        .build()
    EZLog.initWith(config)

    EZLog.v("ezlog", "first blood")

    EZLog._registerCallback(object : Callback {
        override fun onLogsFetchSuccess(
            logName: String?,
            date: String?,
            logs: Array<out String>?
        ) {
            Log.i("ezlog", "$logName $date ${logs.contentToString()}")
            logs?.let {
                logs.getOrNull(0)?.let { log ->
                    Log.i("ezlog", "check file exists ${File(log).exists()}")
                }
            }
        }

        override fun onLogsFetchFail(logName: String?, date: String?, err: String?) {
            Log.i("ezlog", "$logName $date $err")
        }
    })
}
Build from source code

install and config rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env

use rust nightly rustup 1.64.0-nightly-2022-07-15 has a bug, cant compile crate time

rustup default nightly-2022-07-12

we use build-std feature, so add nightly src component

rustup component add rust-src --toolchain nightly-x86_64-apple-darwin

add target: iOS, android, etc...

rustup target add aarch64-linux-android armv7-linux-androideabi aarch64-apple-ios aarch64-apple-ios-sim x86_64-apple-ios

clone repository and open in command line tool. then run

cargo check

wait crates download...

cargo build -p ezlog

For android build

we use cargo-ndk to build dylib

cargo install cargo-ndk

cd android

sh b_android.sh

then open current workspace in AndroidStudio

For iOS build

install cbindgen

cargo install --force cbindgen

cd ios dir

sh b_ios.sh

open the ios/EZlog.xcworkspace in Xcode

License

See LICENSE-MIT, LICENSE-APACHE,

ezlog's People

Contributors

dependabot[bot] avatar s1rius avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.