Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.3.0 #26

Merged
merged 25 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cce3843
Removed / deactivated pattern recognition and advanced analysis features
chrischtel Jan 29, 2025
a63e74a
Removed / deactivated pattern recognition and advanced analysis featu…
chrischtel Jan 29, 2025
6c4b68e
Improved Error Handling for network handler
chrischtel Jan 29, 2025
a9d3f1c
Improved Error Handling for network handler (#15)
chrischtel Jan 29, 2025
e458190
Added unit tests for error handling
chrischtel Jan 29, 2025
91bba34
Added unit tests for error handling (#16)
chrischtel Jan 29, 2025
c313547
Commented patter analysis tests / will be removed shortly
chrischtel Jan 29, 2025
38840dd
Commented patter analysis tests / will be removed shortly (#17)
chrischtel Jan 29, 2025
931441c
fixed various errors, segfault, error handling, clean up logic, and m…
chrischtel Jan 30, 2025
1365c4c
fixed various errors, segfault, error handling, clean up logic, and m…
chrischtel Jan 30, 2025
c598089
gitignore update
chrischtel Jan 30, 2025
52e95ca
gitignore update (#19)
chrischtel Jan 30, 2025
1854520
FORMAT module utility
chrischtel Jan 30, 2025
2b19f2a
WIP: fixed errors, conversion and shadowing errors
chrischtel Jan 30, 2025
458fd2f
WIP: implemented formatting into existing configuration
chrischtel Jan 30, 2025
072b565
FORMAT module utility (#21)
chrischtel Jan 30, 2025
d6495ab
fix: renamed '.Pointer' -> '.pointer' and '.One' to '.one'
chrischtel Feb 2, 2025
a507f18
fix: renamed MAX_PATH_BYTES to max_path_bytes
chrischtel Feb 2, 2025
0a74dad
feat: added non fallible methods for logging
chrischtel Feb 5, 2025
03a0b2b
fix: fixed API errors due to version bump (Zig v0.14.x)
chrischtel Feb 5, 2025
a7649ad
change: updated parts of 'basic_usage' example to use the new Infalli…
chrischtel Feb 5, 2025
373a711
fixed gitignore
chrischtel Feb 5, 2025
4a7dba5
deleted junk file
chrischtel Feb 5, 2025
ea334b5
version bump
chrischtel Feb 5, 2025
f33481c
version bump
chrischtel Feb 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
.zig-cache/
zig-out/
*.log
logs/
logs/
*test_*
test*
test_logs/*.json
13 changes: 3 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
### Fixed
- Fixed deadlock in file rotation when buffer limit is reached
- Fixed memory leaks in file path handling during log rotation
- Improved thread safety for file size tracking
- Added proper memory cleanup for file operations
- Enhanced error recovery during rotation failures

The file handler now properly manages system resources and handles concurrent
access more reliably. Users should see more stable behavior during high-volume
logging with file rotation enabled.
### Fixed v0.3.0 (February 5, 2025)
Added new non-failing log methods for each log level. These methods do not return an error.
fixed compilation errors to support zig 0.14-dev
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.2.0-alpha.1",
.version = "0.3.0",

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
Expand Down
12 changes: 6 additions & 6 deletions examples/basic_usage.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const OrderProcessor = struct {
const metadata = self.createMetadata();

// Log the start of order processing
try self.logger.log(.debug, "Starting order processing [dept={s}, order_id={d}]", .{ self.department, order_id }, metadata);
self.logger.debug("Starting order processing [dept={s}, order_id={d}]", .{ self.department, order_id }, metadata);

// Simulate processing steps with appropriate logging
try self.validateOrder(order_id);
Expand Down Expand Up @@ -99,14 +99,14 @@ pub fn main() !void {
};

// Log application startup
try logger.log(.info, "Application starting", .{}, base_metadata);
logger.info("Application starting", .{}, base_metadata);

// Simulate some logging activity
try logger.log(.debug, "Initializing subsystems", .{}, base_metadata);
try logger.log(.info, "Processing started", .{}, base_metadata);
try logger.log(.warn, "Resource usage high", .{}, base_metadata);
logger.debug("Initializing subsystems", .{}, base_metadata);
logger.info("Processing started", .{}, base_metadata);
logger.warn("Resource usage high", .{}, base_metadata);

// Ensure all logs are written before shutdown
try logger.flush();
try logger.log(.info, "Application shutdown complete", .{}, base_metadata);
logger.info("Application shutdown complete", .{}, base_metadata);
}
56 changes: 56 additions & 0 deletions examples/json_logging.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const std = @import("std");
const nexlog = @import("nexlog");
const JsonHandler = nexlog.output.json_handler.JsonHandler;

pub fn main() !void {
// Initialize allocator
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();

// Create a directory for testing logs if it doesn't exist
const log_dir = "test_logs";
try std.fs.cwd().makePath(log_dir);

// Get the current working directory
var cwd_buf: [std.fs.max_path_bytes]u8 = undefined;
const cwd = std.fs.cwd().realpath(".", &cwd_buf) catch unreachable;

// Construct the absolute path for the log file within the log_dir
const log_file_path = std.fs.path.join(allocator, &[_][]const u8{ cwd, log_dir, "app.json" }) catch unreachable;
defer allocator.free(log_file_path);

// Create a JSON handler
var json_handler = try JsonHandler.init(allocator, .{
.min_level = .debug,
.pretty_print = true, // Optional: Makes the JSON output more readable
.output_file = log_file_path,
});
defer json_handler.deinit();

// Create a logger
const logger = try nexlog.Logger.init(allocator, .{});
defer logger.deinit();

// Add the JSON handler to the logger
try logger.addHandler(json_handler.toLogHandler());

// Create some basic metadata
const metadata = nexlog.LogMetadata{
.timestamp = std.time.timestamp(),
.thread_id = 0, // Replace with actual thread ID in a real application
.file = @src().file,
.line = @src().line,
.function = @src().fn_name,
};

// Log some messages with different levels and optional fields
// Log some messages with different levels and optional fields
try logger.log(.info, "Application starting", .{}, metadata);
try logger.log(.debug, "This is a debug message", .{}, metadata);
try logger.log(.warn, "This is a warning message (code: {d})", .{123}, metadata);
try logger.log(.err, "An error occurred (code: {s})", .{"E_UNKNOWN"}, metadata);

// Ensure all logs are written before exiting
try logger.flush();
}
196 changes: 0 additions & 196 deletions examples/pattern_recognition.zig

This file was deleted.

1 change: 0 additions & 1 deletion src/analysis/correlator.zig

This file was deleted.

1 change: 0 additions & 1 deletion src/analysis/predictor.zig

This file was deleted.

File renamed without changes.
3 changes: 3 additions & 0 deletions src/core/config.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const LogLevel = @import("types.zig").LogLevel;
const format = @import("../utils/format.zig");

pub const LogConfig = struct {
min_level: LogLevel = .info,
Expand All @@ -12,4 +13,6 @@ pub const LogConfig = struct {
buffer_size: usize = 4096,
async_mode: bool = false,
enable_metadata: bool = true,

format_config: ?format.FormatConfig = null,
};
1 change: 1 addition & 0 deletions src/core/errors.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub const LogError = error{
FormattingError,
FilterError,
AlreadyInitialized,
NotInitialized,
};

pub const FileError = error{
Expand Down
6 changes: 5 additions & 1 deletion src/core/init.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const logger = @import("logger.zig");
const config = @import("config.zig");
const errors = @import("errors.zig");
const types = @import("types.zig");

const format = @import("../utils/format.zig");
/// Global logger state
pub const GlobalState = struct {
is_initialized: bool = false,
Expand Down Expand Up @@ -99,6 +99,10 @@ pub const LogBuilder = struct {
},
};
}
pub fn setFormatter(self: *LogBuilder, format_config: format.FormatConfig) *LogBuilder {
self.config.format_config = format_config;
return self;
}

pub fn setMinLevel(self: *LogBuilder, level: types.LogLevel) *LogBuilder {
self.config.min_level = level;
Expand Down
Loading
Loading