-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bda5777
Showing
13 changed files
with
649 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.v] | ||
indent_style = tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
* text=auto eol=lf | ||
*.bat eol=crlf | ||
|
||
**/*.v linguist-language=V | ||
**/*.vv linguist-language=V | ||
**/*.vsh linguist-language=V | ||
**/v.mod linguist-language=V |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Binaries for programs and plugins | ||
main | ||
*.exe | ||
*.exe~ | ||
*.so | ||
*.dylib | ||
*.dll | ||
|
||
logs/ | ||
*.log | ||
|
||
# Ignore binary output folders | ||
bin/ | ||
|
||
# Ignore common editor/system specific metadata | ||
.DS_Store | ||
.idea/ | ||
.vscode/ | ||
*.iml | ||
|
||
# ENV | ||
.env | ||
|
||
# vweb and database | ||
*.db | ||
*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2023 github.com/dnkdev/logx | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
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 OR COPYRIGHT HOLDERS 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module main | ||
|
||
import log | ||
import time | ||
//import logx.prebuilt.filesize.filelog | ||
import logx.prebuilt.daily.filelog | ||
|
||
|
||
fn start_vlog(repeats int) string{ | ||
mut vlog := log.Log{} | ||
vlog.set_level(.debug) | ||
vlog.set_full_logpath('./debug_vlog.log') | ||
bench := time.ticks() | ||
for i in 0..repeats { | ||
vlog.debug('Some text ${i}') | ||
vlog.info('Some text ${i}') | ||
vlog.warn('Some text ${i}') | ||
vlog.error('Some text ${i}') | ||
} | ||
return 'vLog Time: ${time.ticks() - bench}ms' | ||
} | ||
|
||
fn start_logx(repeats int)! string { | ||
mut logger := filelog.new()! | ||
logger.set_level(.trace) | ||
dump(logger) | ||
bench := time.ticks() | ||
for i in 0..repeats { | ||
logger.trace('Some text ${i}') | ||
logger.debug('Some text ${i}') | ||
logger.info('Some text ${i}') | ||
logger.note('Some text ${i}') | ||
} | ||
return 'logX Time: ${time.ticks() - bench}ms' | ||
} | ||
|
||
fn main(){ | ||
mut repeats := 10000 | ||
txt_logx := start_logx(repeats)! | ||
txt_vlog := start_vlog(repeats) | ||
|
||
|
||
C.atexit( | ||
fn[txt_logx, txt_vlog](){ | ||
println(txt_vlog) | ||
println(txt_logx) | ||
} | ||
) | ||
//time.sleep(2000*time.millisecond) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
module filelog | ||
|
||
import logx | ||
|
||
[rotation: 'daily'] | ||
pub struct PrebuiltFileLog { | ||
pub mut: | ||
trace_ logx.LevelInfo [cap: 10000; file: 'logs/trace/trace.log'] | ||
debug_ logx.LevelInfo [cap: 9000; file: 'logs/debug/debug.log'] | ||
info_ logx.LevelInfo [cap: 8000; file: 'logs/info/info.log'] | ||
note_ logx.LevelInfo [cap: 7000; file: 'logs/note/note.log'] | ||
warn_ logx.LevelInfo [cap: 1000; file: 'logs/warn/warn.log'] | ||
alert_ logx.LevelInfo [cap: 1000; file: 'logs/alert/alert.log'] | ||
error_ logx.LevelInfo [cap: 1000; file: 'logs/error/error.log'] | ||
fatal_ logx.LevelInfo [cap: 1; file: 'logs/fatal/fatal.log'] | ||
log_level int | ||
log_day int // should be if [rotation: 'daily'] set | ||
} | ||
|
||
pub enum LogLevel { | ||
trace | ||
debug | ||
info | ||
note | ||
warn | ||
alert | ||
error | ||
fatal | ||
} | ||
|
||
pub fn (mut l PrebuiltFileLog) wait() { | ||
logx.wait(mut l) | ||
} | ||
|
||
pub fn (mut l PrebuiltFileLog) set_level(level LogLevel) { | ||
l.log_level = int(level) | ||
} | ||
|
||
pub fn (mut l PrebuiltFileLog) trace(s string) { | ||
if l.log_level > int(LogLevel.trace) { | ||
return | ||
} | ||
logx.check_daily_rotation(mut l) | ||
l.trace_.ch <- l.trace_.formatter(s, 'TRACE') | ||
} | ||
|
||
pub fn (mut l PrebuiltFileLog) debug(s string) { | ||
if l.log_level > int(LogLevel.debug) { | ||
return | ||
} | ||
logx.check_daily_rotation(mut l) | ||
l.debug_.ch <- l.debug_.formatter(s, 'DEBUG') | ||
} | ||
|
||
pub fn (mut l PrebuiltFileLog) info(s string) { | ||
if l.log_level > int(LogLevel.info) { | ||
return | ||
} | ||
logx.check_daily_rotation(mut l) | ||
l.info_.ch <- l.info_.formatter(s, 'INFO ') | ||
} | ||
|
||
pub fn (mut l PrebuiltFileLog) note(s string) { | ||
if l.log_level > int(LogLevel.note) { | ||
return | ||
} | ||
logx.check_daily_rotation(mut l) | ||
l.note_.ch <- l.note_.formatter(s, 'NOTE ') | ||
} | ||
|
||
pub fn (mut l PrebuiltFileLog) warn(s string) { | ||
if l.log_level > int(LogLevel.warn) { | ||
return | ||
} | ||
logx.check_daily_rotation(mut l) | ||
l.warn_.ch <- l.warn_.formatter(s, 'WARN ') | ||
} | ||
|
||
pub fn (mut l PrebuiltFileLog) alert(s string) { | ||
if l.log_level > int(LogLevel.alert) { | ||
return | ||
} | ||
logx.check_daily_rotation(mut l) | ||
l.alert_.ch <- l.alert_.formatter(s, 'ALERT') | ||
} | ||
|
||
pub fn (mut l PrebuiltFileLog) error(s string) { | ||
if l.log_level > int(LogLevel.error) { | ||
return | ||
} | ||
logx.check_daily_rotation(mut l) | ||
l.error_.ch <- l.error_.formatter(s, 'ERROR') | ||
} | ||
|
||
pub fn (mut l PrebuiltFileLog) fatal(s string) { | ||
if l.log_level > int(LogLevel.fatal) { | ||
return | ||
} | ||
logx.check_daily_rotation(mut l) | ||
l.fatal_.ch <- l.fatal_.formatter(s, 'FATAL') | ||
logx.wait(mut l) | ||
panic(s) | ||
} | ||
|
||
pub fn new() !&PrebuiltFileLog { | ||
return logx.from_new(PrebuiltFileLog{})! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
module filelog | ||
|
||
import logx | ||
|
||
[rotation: 'filesize'] | ||
pub struct PrebuiltFileLog { | ||
pub mut: | ||
trace_ logx.LevelInfo [max_size: '1MB'; cap: 10000; file: 'logs/trace/trace.log'] | ||
debug_ logx.LevelInfo [max_size: '1MB'; cap: 9000; file: 'logs/debug/debug.log'] | ||
info_ logx.LevelInfo [max_size: '1MB'; cap: 8000; file: 'logs/info/info.log'] | ||
note_ logx.LevelInfo [max_size: '1MB'; cap: 7000; file: 'logs/note/note.log'] | ||
warn_ logx.LevelInfo [max_size: '1MB'; cap: 1000; file: 'logs/warn/warn.log'] | ||
alert_ logx.LevelInfo [max_size: '1MB'; cap: 1000; file: 'logs/alert/alert.log'] | ||
error_ logx.LevelInfo [max_size: '1MB'; cap: 1000; file: 'logs/error/error.log'] | ||
fatal_ logx.LevelInfo [max_size: '1MB'; cap: 1; file: 'logs/fatal/fatal.log'] | ||
log_level int | ||
} | ||
|
||
pub enum LogLevel { | ||
trace | ||
debug | ||
info | ||
note | ||
warn | ||
alert | ||
error | ||
fatal | ||
} | ||
|
||
pub fn (mut l PrebuiltFileLog) wait() { | ||
logx.wait(mut l) | ||
} | ||
|
||
pub fn (mut l PrebuiltFileLog) set_level(level LogLevel) { | ||
l.log_level = int(level) | ||
} | ||
|
||
pub fn (mut l PrebuiltFileLog) trace(s string) { | ||
if l.log_level > int(LogLevel.trace) { | ||
return | ||
} | ||
logx.check_level_size_rotation(mut l.trace_) | ||
l.trace_.ch <- l.trace_.formatter(s, 'TRACE') | ||
} | ||
|
||
pub fn (mut l PrebuiltFileLog) debug(s string) { | ||
if l.log_level > int(LogLevel.debug) { | ||
return | ||
} | ||
logx.check_level_size_rotation(mut l.debug_) | ||
l.debug_.ch <- l.debug_.formatter(s, 'DEBUG') | ||
} | ||
|
||
pub fn (mut l PrebuiltFileLog) info(s string) { | ||
if l.log_level > int(LogLevel.info) { | ||
return | ||
} | ||
logx.check_level_size_rotation(mut l.info_) | ||
l.info_.ch <- l.info_.formatter(s, 'INFO ') | ||
} | ||
|
||
pub fn (mut l PrebuiltFileLog) note(s string) { | ||
if l.log_level > int(LogLevel.note) { | ||
return | ||
} | ||
logx.check_level_size_rotation(mut l.note_) | ||
l.note_.ch <- l.note_.formatter(s, 'NOTE ') | ||
} | ||
|
||
pub fn (mut l PrebuiltFileLog) warn(s string) { | ||
if l.log_level > int(LogLevel.warn) { | ||
return | ||
} | ||
logx.check_level_size_rotation(mut l.warn_) | ||
l.warn_.ch <- l.warn_.formatter(s, 'WARN ') | ||
} | ||
|
||
pub fn (mut l PrebuiltFileLog) alert(s string) { | ||
if l.log_level > int(LogLevel.alert) { | ||
return | ||
} | ||
logx.check_level_size_rotation(mut l.alert_) | ||
l.alert_.ch <- l.alert_.formatter(s, 'ALERT') | ||
} | ||
|
||
pub fn (mut l PrebuiltFileLog) error(s string) { | ||
if l.log_level > int(LogLevel.error) { | ||
return | ||
} | ||
logx.check_level_size_rotation(mut l.error_) | ||
l.error_.ch <- l.error_.formatter(s, 'ERROR') | ||
} | ||
|
||
pub fn (mut l PrebuiltFileLog) fatal(s string) { | ||
if l.log_level > int(LogLevel.fatal) { | ||
return | ||
} | ||
logx.check_level_size_rotation(mut l.fatal_) | ||
l.fatal_.ch <- l.fatal_.formatter(s, 'FATAL') | ||
logx.wait(mut l) | ||
panic(s) | ||
} | ||
|
||
pub fn new() !&PrebuiltFileLog { | ||
return logx.from_new(PrebuiltFileLog{})! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# 📕 logx | ||
|
||
My small library for easier custom logging implementation. File logging.<br> | ||
- [x] One or multiple files / directories | ||
- [x] daily rotation | ||
- [x] filesize rotation | ||
|
||
Example implementation (daily rotation, filesize rotation): look at code: | ||
<a href="https://github.com/dnkdev/logx/tree/master/prebuilt">filelog</a><br> | ||
Daily : `import logx.prebuilt.daily.filelog` <br> | ||
Filesize: `import logx.prebuilt.filesize.filelog`<br> | ||
|
||
```v | ||
import logx.prebuilt.size.filelog | ||
//... | ||
mut logger := filelog.new()! | ||
logger.set_level(.trace) | ||
logger.trace('Some text') | ||
logger.debug('Some text') | ||
logger.info('Some text') | ||
logger.note('Some text') | ||
logger.warn('Some text') | ||
logger.alert('Some text') | ||
logger.error('Some text') | ||
logger.fatal('Some text') // panic | ||
logger.wait() // call wait if the program can exit before all writes are done | ||
``` | ||
|
||
## | ||
|
||
(log)X == eXperimental | ||
|
||
## |
Oops, something went wrong.