-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc.go
More file actions
147 lines (147 loc) · 3.84 KB
/
doc.go
File metadata and controls
147 lines (147 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Package genlog provides high-performance fake log generation for testing and benchmarking.
//
// # Overview
//
// genlog generates realistic log data using customizable templates and pre-generated random values.
// It achieves millions of logs per second throughput through:
// - Pre-compiled templates
// - Value pools for fast lookups
// - Producer-consumer pipeline architecture
// - Parallel generation and batched writes
//
// # Quick Start
//
// The simplest way to use genlog is with a configuration file:
//
// gen, err := genlog.NewFromFile("config.yaml")
// if err != nil {
// log.Fatal(err)
// }
//
// gen.Start()
// gen.Wait()
// gen.Stop()
//
// # Programmatic Configuration
//
// You can also create configurations programmatically:
//
// cfg := &genlog.Config{
// Templates: []genlog.Template{
// {
// Template: "{{timestamp}} [{{level}}] {{message}}",
// Weight: 10,
// },
// },
// CustomTypes: map[string][]string{
// "level": {"INFO", "WARN", "ERROR"},
// "message": {"User logged in", "Request processed"},
// },
// Outputs: []genlog.OutputConfig{
// {
// Type: "file",
// Config: map[string]interface{}{
// "path": "output.log",
// },
// },
// },
// Limits: genlog.Limits{
// MaxCount: 1000000, // Generate 1M logs
// },
// }
//
// gen, err := genlog.New(cfg)
// if err != nil {
// log.Fatal(err)
// }
//
// gen.Start()
// gen.Wait()
// gen.Stop()
//
// # Custom Functions
//
// Register custom Go functions that can be called from templates:
//
// cfg := &genlog.Config{
// Templates: []genlog.Template{
// {
// Template: "{{Uppercase {{level}}}} - {{Reverse \"hello\"}}",
// Weight: 1,
// },
// },
// CustomFunctions: map[string]genlog.TemplateFunc{
// "Uppercase": func(args ...string) string {
// if len(args) == 0 {
// return ""
// }
// return strings.ToUpper(args[0])
// },
// "Reverse": func(args ...string) string {
// if len(args) == 0 {
// return ""
// }
// runes := []rune(args[0])
// for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
// runes[i], runes[j] = runes[j], runes[i]
// }
// return string(runes)
// },
// },
// // ... rest of config
// }
//
// Custom functions:
// - Accept variable arguments as strings
// - Can override built-in functions (e.g., FormattedDate, Number)
// - Work alongside regular placeholders in templates
// - Are evaluated with their literal string arguments
// - Only available when using genlog as a library (not from YAML config)
//
// # Template Syntax
//
// Templates use {{placeholder}} syntax for dynamic values:
//
// - Built-in placeholders: {{ipv4}}, {{username}}, {{email}}, {{timestamp}}
// - Custom types: Define in CustomTypes map and reference by name
// - Functions: {{FormattedDate "2006-01-02"}}, {{Number 1 100}}
//
// # Performance Tuning
//
// Control generation performance through the Performance configuration:
//
// cfg.Performance = genlog.Performance{
// ProducerWorkers: 8, // CPU-bound generation workers
// ConsumerWorkers: 2, // I/O-bound write workers
// ChannelBuffer: 100000, // Pipeline buffer size
// WriteBatchSize: 1000, // Logs per write batch
// ValuePoolSize: 10000, // Pre-generated values per type
// }
//
// # Generation Limits
//
// Control when generation stops:
//
// cfg.Limits = genlog.Limits{
// MaxCount: 1000000, // Stop after 1M logs
// MaxDuration: time.Hour, // Or after 1 hour
// MaxSize: 1 << 30, // Or after 1GB
// }
//
// # Statistics
//
// Monitor generation in real-time:
//
// stats := gen.Stats().Snapshot()
// fmt.Printf("Generated: %d logs at %.0f logs/sec\n",
// stats.Generated, stats.LogsPerSecond)
//
// # Output Types
//
// Built-in output types:
//
// - file: Write to local files
// - udp: Send via UDP socket
//
// Additional output types can be added by implementing the output.Output interface.
package genlog