Coder Social home page Coder Social logo

cschlosser / glog-rs Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 73 KB

Port of the C++ glog logging functionality as backend into the standard Rust logging frontend

Home Page: https://crates.io/crates/glog

License: BSD 3-Clause "New" or "Revised" License

Rust 100.00%
glog logging log crate rust

glog-rs's Introduction

glog for Rust

CI

This is a port of the C++ logging framework glog as backend for Rusts standard logging frontend.

โš ๏ธ Stability Warning: Currently there are no tests for this framework. This will be added in the next release. Currently the framework is tested only manually to verify the current featureset.

Introduction

glog-rs tries to stay as close to glog as possible to maintain compatibility, which can be useful in mixed environments using C++ and Rust code at the same time.

This includes default values for flags, flag names and behavior.

Additional options or configurations can be enabled before initializing the framework to use more of what the Rust standard logging frontend has to offer or to solve different use cases.

Examples

The most basic example is this:

use log::*;
use glog::Flags;

glog::new().init(Flags::default()).unwrap();

info!("It works!");

which will write I0401 12:34:56.987654 123 readme.rs:6] It works! to the INFO log file.

If you want to have colored output on stderr as well consider initializing by using some of the flags:

glog::new().init(Flags {
        colorlogtostderr: true,
        alsologtostderr: true, // use logtostderr to only write to stderr and not to files
        ..Default::default()
    }).unwrap();

A non standard extension would the year in addition to month and day in the timestamp. This is possible by calling the with_year method prior to init like this:

glog::new()
    .with_year(true) // Add the year to the timestamp in the logfile
    .init(Flags {
        logtostderr: true, // don't write to log files
        ..Default::default()
    }).unwrap();

info!("With the year");

will print I20210401 12:34:56.987654 123 readme.rs:11] With the year.

Inspirations

This project was inspired by the great C++ logging framework glog and stderrlog-rs as a kickstarter for a Rust logging backend.

glog-rs's People

Contributors

cschlosser avatar wathiede avatar

Watchers

 avatar

Forkers

wathiede

glog-rs's Issues

Generate convenient symlinks to latest log files.

The C++ library has a helper SetLogSymlink and the Go version automatically creates symlinks for each log file.

So, for example, on my system I see files like this from a Go program using glog:

$ ls -l /tmp/nomadnet.INFO         
lrwxrwxrwx 1 wathiede users 59 Dec 26 21:16 /tmp/nomadnet.INFO -> nomadnet.nixos-07.wathiede.log.INFO.20221226-211600.4192921

That points to the logs of the most recent invocations of my glog enabled programs.

Would you be receptive of a pull request that mimicked the Go behavior? If not, how about a helper to create it manually like the C++ version?

The automatic behavior is really nice because the symlinks don't get created until a program has logged at that level, for example, the .ERROR symlink won't even exist if the program hasn't yet logged at the error level.

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.