All Projects → ryapric → loggit

ryapric / loggit

Licence: other
Modern Logging for the R Ecosystem

Programming Languages

r
7636 projects
Makefile
30231 projects

Projects that are alternatives of or similar to loggit

raise if
one liner `raise Exception if condition` for Python
Stars: ✭ 15 (-55.88%)
Mutual labels:  exception-handler
ANE-Exceptions
Exception tracking Adobe AIR Native Extension for Android and iOS
Stars: ✭ 16 (-52.94%)
Mutual labels:  exception-handler
backtrace-unity
First-class error reporting for the Unity game engine.
Stars: ✭ 99 (+191.18%)
Mutual labels:  exception-handler
error
Makes handling and debugging PHP errors suck less
Stars: ✭ 17 (-50%)
Mutual labels:  exception-handler
crash
Proper error handling, exceptions and try/catch for ZSH
Stars: ✭ 51 (+50%)
Mutual labels:  exception-handler
mwe-cpp-exception
Minimum working example of proper C++11 exception handling
Stars: ✭ 20 (-41.18%)
Mutual labels:  exception-handler
ErrorHeroModule
💎 A Hero for your Zend Framework/Laminas, and Expressive/Mezzio application to log ( DB and Mail ) and handle php errors & exceptions during Mvc process/between request and response
Stars: ✭ 47 (+38.24%)
Mutual labels:  exception-handler
ErrorControlSystem
ErrorControlSystem is a .NET library created to automate handling .NET Windows-Base application exceptions and raise that to a sql server. This exception handler have some features as screen capturing, fetch server date time in exception occurrence time and etc.
Stars: ✭ 30 (-11.76%)
Mutual labels:  exception-handler
ExceptionCatcher
Catch Objective-C exceptions in Swift
Stars: ✭ 97 (+185.29%)
Mutual labels:  exception-handler

Modern Logging for the R Ecosystem

Ryan Price [email protected]

CRAN_Status_Badge R-CMD-check Monthly downloads Support me on Ko-Fi


loggit is an ndJSON logging library for R software. It is blazingly fast when writing logs, and has zero external dependencies. loggit can be as simple and unobstrusive as you’d like, or as involved as your application needs it to be.

Please see below for some quick examples, and read the vignettes for the Getting Started guide, as well as some other use case examples.

Why use loggit?

There are indeed several logging packages available for R. loggit, however, takes a more modern approach approach to logging in R:

  • Opting to use the JSON format, which is parsable by most modern software
  • Designed with log streams in mind
  • Unobtrusive, yet highly flexible
  • Convenient ability to log data, then analyze that log data on the same host.

Additionally, the boilerplate to get going with loggit is minimal at worst, only requiring you to point to the log file. If deploying your R code in a container ecosystem, you don’t even need to do that, since loggit will echo its formatted logs to stdout. No need to write custom formatters, handlers, levels, etc. – just f&ck#n’ loggit!

Quick Examples

The quickest way to get up & running with loggit is to… do nothing special. loggit’s simplest functionality does its best to stay out of your way. You’ll probably want to point it to a log file, though; otherwise, logs will print to the console, but land in a tempfile.

library(loggit)
#> 
#> Attaching package: 'loggit'
#> The following objects are masked from 'package:base':
#> 
#>     message, stop, warning
# set_logfile("./loggit.log")

message("This is a message")
#> {"timestamp": "2022-04-12T10:55:02-0500", "log_lvl": "INFO", "log_msg": "This is a message"}
#> This is a message
warning("This is a warning")
#> {"timestamp": "2022-04-12T10:55:02-0500", "log_lvl": "WARN", "log_msg": "This is a warning"}
#> Warning in warning("This is a warning"): This is a warning
# stop("This actually throws a critical error, so I'm not actually going to run it here :)"))
#> {"timestamp": "2020-05-31T20:59:33-0500", "log_lvl": "ERROR", "log_msg": "This actually throws a critical error, so I'm not actually going to run it here :)"}

You can suppress each part of the console output separately (both the loggit ndJSON and the regular R output) but the default is to post both. Only the ndJSON is written to the log file.

You can also use the loggit() function directly to compose much more custom logs, including entirely custom fields (and prevent throwing actual status codes until you wish to handle them). loggit doesn’t require that you set custom logger objects or anything like that: just throw whatever you want at it, and it’ll become a structured log.

loggit("ERROR", "This will log an error - but not actually throw one yet", rows = nrow(iris), anything_else = "you want to include")
#> {"timestamp": "2022-04-12T10:55:02-0500", "log_lvl": "ERROR", "log_msg": "This will log an error - but not actually throw one yet", "rows": "150", "anything_else": "you want to include"}

# Read log file into data frame to implement logic based on entries
logdata <- read_logs()
print(logdata)
#>                  timestamp log_lvl
#> 1 2022-04-12T10:55:02-0500    INFO
#> 2 2022-04-12T10:55:02-0500    WARN
#> 3 2022-04-12T10:55:02-0500   ERROR
#>                                                   log_msg rows
#> 1                                       This is a message     
#> 2                                       This is a warning     
#> 3 This will log an error - but not actually throw one yet  150
#>         anything_else
#> 1                    
#> 2                    
#> 3 you want to include
if (any(logdata$log_lvl == "ERROR")) {
  print("Errors detected somewhere in your code!") # but you can throw a stop() here, too, for example
}
#> [1] "Errors detected somewhere in your code!"

Again, check out the vignettes for more details!

Installation

You can install the latest CRAN release of loggit via install.packages("loggit").

Or, to get the latest development version from GitHub –

Via devtools:

devtools::install_github("ryapric/loggit")

Or, clone & build from source:

cd /path/to/your/repos
git clone https://github.com/ryapric/loggit.git loggit
make install

To use the most recent development version of loggit in your own package, you can include it in your Remotes: field in your DESCRIPTION file:

Remotes: github::ryapric/loggit

Note that packages being submitted to CRAN cannot have a Remotes field. Refer here for more info.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].