mirror of
https://github.com/gechandesu/syslog.git
synced 2026-01-23 23:34:12 +03:00
init
This commit is contained in:
8
.editorconfig
Normal file
8
.editorconfig
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.v]
|
||||||
|
indent_style = tab
|
||||||
8
.gitattributes
vendored
Normal file
8
.gitattributes
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
* text=auto eol=lf
|
||||||
|
*.bat eol=crlf
|
||||||
|
|
||||||
|
*.v linguist-language=V
|
||||||
|
*.vv linguist-language=V
|
||||||
|
*.vsh linguist-language=V
|
||||||
|
v.mod linguist-language=V
|
||||||
|
.vdocignore linguist-language=ignore
|
||||||
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Binaries for programs and plugins
|
||||||
|
main
|
||||||
|
syslog
|
||||||
|
*.exe
|
||||||
|
*.exe~
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
*.dll
|
||||||
|
|
||||||
|
# Ignore binary output folders
|
||||||
|
bin/
|
||||||
|
|
||||||
|
# Ignore common editor/system specific metadata
|
||||||
|
.DS_Store
|
||||||
|
.idea/
|
||||||
|
.vscode/
|
||||||
|
*.iml
|
||||||
|
|
||||||
|
# ENV
|
||||||
|
.env
|
||||||
|
|
||||||
|
# vweb and database
|
||||||
|
*.db
|
||||||
|
*.js
|
||||||
18
README.md
Normal file
18
README.md
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Write Messages into System Journal
|
||||||
|
|
||||||
|
`syslog` module is a thin wrapper around syslog C API. Read the
|
||||||
|
[syslog(3)](https://www.man7.org/linux/man-pages/man3/syslog.3.html)
|
||||||
|
manual page for details.
|
||||||
|
|
||||||
|
Basic usage:
|
||||||
|
|
||||||
|
```v
|
||||||
|
import syslog
|
||||||
|
|
||||||
|
mut log := syslog.open()
|
||||||
|
defer {
|
||||||
|
log.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
log.send(.info, 'Hello, World!')
|
||||||
|
```
|
||||||
22
UNLICENSE
Normal file
22
UNLICENSE
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
This is free and unencumbered software released into the public domain.
|
||||||
|
|
||||||
|
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
||||||
|
software, either in source code form or as a compiled binary, for any purpose,
|
||||||
|
commercial or non-commercial, and by any means.
|
||||||
|
|
||||||
|
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||||
|
software dedicate any and all copyright interest in the software to the public
|
||||||
|
domain. We make this dedication for the benefit of the public at large and to
|
||||||
|
the detriment of our heirs and
|
||||||
|
successors. We intend this dedication to be an overt act of relinquishment in
|
||||||
|
perpetuity of all present and future rights to this software under copyright
|
||||||
|
law.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE
|
||||||
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||||
|
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
For more information, please refer to <http://unlicense.org/>
|
||||||
12
examples/log.v
Normal file
12
examples/log.v
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import syslog
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
mut log := syslog.open(ident: 'helloworld')
|
||||||
|
defer {
|
||||||
|
log.close()
|
||||||
|
}
|
||||||
|
log.send(.info, 'hello from V!')
|
||||||
|
log.send(.err, 'error message from V!')
|
||||||
|
|
||||||
|
eprintln('On Linux run `journalctl -t helloworld` to see the result.')
|
||||||
|
}
|
||||||
94
syslog.c.v
Normal file
94
syslog.c.v
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
module syslog
|
||||||
|
|
||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
|
fn C.openlog(&char, i32, i32)
|
||||||
|
fn C.syslog(i32, &char, ...voidptr)
|
||||||
|
fn C.closelog()
|
||||||
|
|
||||||
|
/*
|
||||||
|
Values for option
|
||||||
|
*/
|
||||||
|
|
||||||
|
pub const log_cons = C.LOG_CONS
|
||||||
|
pub const log_ndelay = C.LOG_NDELAY
|
||||||
|
pub const log_nowait = C.LOG_NOWAIT
|
||||||
|
pub const log_odelay = C.LOG_ODELAY
|
||||||
|
pub const log_perror = C.LOG_PERROR
|
||||||
|
pub const log_pid = C.LOG_PID
|
||||||
|
|
||||||
|
/*
|
||||||
|
Values for facility
|
||||||
|
*/
|
||||||
|
|
||||||
|
pub const log_auth = C.LOG_AUTH
|
||||||
|
pub const log_authpriv = C.LOG_AUTHPRIV
|
||||||
|
pub const log_cron = C.LOG_CRON
|
||||||
|
pub const log_daemon = C.LOG_DAEMON
|
||||||
|
pub const log_ftp = C.LOG_FTP
|
||||||
|
pub const log_kern = C.LOG_KERN
|
||||||
|
pub const log_local0 = C.LOG_LOCAL0
|
||||||
|
pub const log_local1 = C.LOG_LOCAL1
|
||||||
|
pub const log_local2 = C.LOG_LOCAL2
|
||||||
|
pub const log_local3 = C.LOG_LOCAL3
|
||||||
|
pub const log_local4 = C.LOG_LOCAL4
|
||||||
|
pub const log_local5 = C.LOG_LOCAL5
|
||||||
|
pub const log_local6 = C.LOG_LOCAL6
|
||||||
|
pub const log_local7 = C.LOG_LOCAL7
|
||||||
|
pub const log_lpr = C.LOG_LPR
|
||||||
|
pub const log_mail = C.LOG_MAIL
|
||||||
|
pub const log_news = C.LOG_NEWS
|
||||||
|
pub const log_syslog = C.LOG_SYSLOG
|
||||||
|
pub const log_user = C.LOG_USER
|
||||||
|
pub const log_uucp = C.LOG_UUCP
|
||||||
|
|
||||||
|
/*
|
||||||
|
Values for level
|
||||||
|
*/
|
||||||
|
|
||||||
|
pub enum Level {
|
||||||
|
emerg = C.LOG_EMERG
|
||||||
|
alert = C.LOG_ALERT
|
||||||
|
crit = C.LOG_CRIT
|
||||||
|
err = C.LOG_ERR
|
||||||
|
warn = C.LOG_WARNING
|
||||||
|
notice = C.LOG_NOTICE
|
||||||
|
info = C.LOG_INFO
|
||||||
|
debug = C.LOG_DEBUG
|
||||||
|
}
|
||||||
|
|
||||||
|
@[params]
|
||||||
|
pub struct OpenParams {
|
||||||
|
pub:
|
||||||
|
ident string
|
||||||
|
option int
|
||||||
|
facility int = log_user
|
||||||
|
}
|
||||||
|
|
||||||
|
// open opens a system log for program. See also openlog(3).
|
||||||
|
pub fn open(p OpenParams) Syslog {
|
||||||
|
C.openlog(&char(p.ident.str), i32(p.option), i32(p.facility))
|
||||||
|
return Syslog{
|
||||||
|
OpenParams: p
|
||||||
|
is_opened: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Syslog {
|
||||||
|
OpenParams
|
||||||
|
pub mut:
|
||||||
|
is_opened bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// send sends a message of level `lvl` to system journal. See also syslog(3).
|
||||||
|
pub fn (s Syslog) send(lvl Level, msg string) {
|
||||||
|
C.syslog(i32(lvl), c'%s', &char(msg.str))
|
||||||
|
}
|
||||||
|
|
||||||
|
// close closes the system journal. See also closelog(3).
|
||||||
|
pub fn (mut s Syslog) close() {
|
||||||
|
if s.is_opened {
|
||||||
|
C.closelog()
|
||||||
|
s.is_opened = false
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user